title: scipy.stats is lost when I import my module
body: <p>The problem appears only when I run the code via the Linux command line, i.e. the Windows Subsystem for Linux. It does not occur when run via a conda environment on Windows. In both cases, <code>scipy</code> is properly installed.</p>
  <p>I have created a function to perform linear regressions of values in rows from across two dataframes <code>df_1</code> and <code>df_2</code>. Their column names are the same as the keys as the dictionary <code>data_dict</code>.</p>
  <pre class="lang-py prettyprint-override"><code>from scipy.stats import linregress
  import numpy as np
  
  def foo(df_1, df_2, data_dict):
      for index, row in df_2.iterrows():
          x = []
          for d in data_dict:
              x.append(row[d])
          x = np.array(x)
      for index, row in df_1.iterrows():
          y = []
          for d in data_dict:
              y.append(row[d])
          y = np.array(y)
          s, i, r, p, se = linregress(x, y)
  </code></pre>
  <p>This works fine as long as I run it from within the script it is written in, however as soon as I import it into a different script, 'bar' and try to run it I get the error <code>AttributeError: module 'scipy' has no attribute 'stats'</code>, and the traceback refers to the line in which <code>linregress</code> is actually used, not the import line.</p>
  <p>I have tried importing in other ways, i.e.</p>
  <pre class="lang-py prettyprint-override"><code>from scipy import stats
  </code></pre>
  <p>As well as importing directly before the linregress operation, i.e.</p>
  <pre class="lang-py prettyprint-override"><code>from scipy.stats import linregress
  s, i, r, p, se = linregress(x, y)
  </code></pre>
  <p>And finally I've tried seeing if any of the other modules imported to 'bar' are interfering with  <code>scipy.stats</code>, and this is not the case.</p>
  <p>Any idea why python is 'forgetting' <code>scipy.stats</code>?</p>
  <p>I also tried checking that <code>scipy.stats</code> was imported by writing a list of all modules imported in 'bar' before calling foo;</p>
  <pre class="lang-py prettyprint-override"><code>with open('modules_on_import.txt', 'a') as f:
      for s in sys.modules:
          f.write(f&quot;{s}\n&quot;)
  f.close()
  </code></pre>
  <p>and scipy.stats can be found in modules_on_import.txt</p>
  <p>Some more details:</p>
  <ol>
  <li>I'm not running in virtual environment, <code>echo $VIRTUAL_ENV</code> returns nothing.</li>
  <li>Everything is run via the command line, i.e. directly in Bash. In this case I simply type <code>python3 bar.py</code>.</li>
  <li>All modules installed using pip, via command line - i.e. <code>pip install scipy</code></li>
  <li>Unsure if it matters, but I'm editing in <code>vim</code>.</li>
  </ol>
  <p>A (simplified) example of <code>bar.py</code>.</p>
  <pre class="lang-py prettyprint-override"><code>from psd_processing import process_psd # function to make df_2 and data_dict
  from uptake_processing import process_uptake # function to make df_1
  from foo_test import foo
  
  project = '0020'
  loading_df = process_uptake(project, 'co2', 298) # this works
  param_df, data_dict = process_psd(project, 'n2', 'V') # this works
  correlation_df = foo(loading_df, param_df, data_dict) # this breaks on linregress in foo.py
  </code></pre>
  <p>It's not the installation method of <code>scipy</code>. I uninstalled and reinstalled with <code>pip3</code> to be sure.</p>
  <p>However, when I run the code via the Spyder IDE, it works!
  Some pertinent information;</p>
  <ol>
  <li>I was originally running the code via Ubuntu 20.04.3 LTS on Windows 10 x86_64. My Python installation is in <code>/usr</code> on Ubuntu.</li>
  <li>When running in Spyder, the code is run directly on Windows. The python installation is in <code>C:\Users\&lt;user&gt;\Anaconda3</code>.</li>
  </ol>
  <p>How do I get this code to run properly via the command line?</p>