0

I used How do I check which version of NumPy I'm using? to learn how to get the version of numpy. However, when I run conda list | grep numpy, I get:

numpy                     1.15.2           py36ha559c80_0
numpy-base                1.15.2           py36h8128ebf_0
numpydoc                  0.8.0                    py36_0

However, when I run version from IPython shell, I get:

import numpy as np
np.__version__
Out: '1.13.3'
np.version.version
Out: '1.13.3'
np.version.full_version
Out: '1.13.3'

Why are the two versions different? Which one should I trust? Thanks for any help.


Please note that I am not using venv (i.e. virtual environment). I am directly accessing Anaconda's packages. So, there is no issue about versioning.


Here's what PyCharm is showing me: enter image description here


As per Conda's version information on package doesn't correspond to __version__, here's __file__ and sys.path. Please note that I have hidden my name for privacy issues. enter image description here

watchtower
  • 4,140
  • 14
  • 50
  • 92

2 Answers2

1

It seems that you have besides your python 3 environment in anaconda, another python with IPython and numpy installed.

It looks like that PyCharm and Anaconda see (correctly) the same numpy versions, while IPython which, I assume you didn't start from within your anaconda environment, sees another python installation with the older numpy. In fact, your output shows, that there is another python3.6 in C:\Users\... which doesn't belong to anaconda.

To make numpy 1.15 available in IPython you can either start IPython from within your anaconda environment by typing in the terminal (easier solution)

C:\>activate <your_anaconda_environment_name>
(<your_anaconda_environment_name>) C:\>ipython

or you make your local IPython load the modules from the anaconda environment by having a look at this answer. This will be not a recommended option in this case, given the resulting cross linkings of two python installations.

gehbiszumeis
  • 3,525
  • 4
  • 24
  • 41
0

The issue is that PyCharm reads older python version from location App-data\roaming... What I did is that in start-up script, I added the following code.

print("Correcting sys paths now...")
paths = [
'C:\\Anaconda3\\python36.zip',
 'C:\\Anaconda3\\DLLs',
 'C:\\Anaconda3\\lib',
 'C:\\Anaconda3',
 'C:\\Anaconda3\\lib\\site-packages',
 'C:\\Anaconda3\\lib\\site-packages\\win32',
 'C:\\Anaconda3\\lib\\site-packages\\win32\\lib',
 'C:\\Anaconda3\\lib\\site-packages\\Pythonwin',
 'C:\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
]
import sys
for path in reversed(paths):
    sys.path.insert(0,path)
print("Completed correcting sys paths now...")
del path
del paths

Above code will force Python to read latest files from Anaconda. However, if you are using virtual environment, you would need to point to that environment.

If you want to know where is Python installed, you can run:

import os
import sys
os.path.dirname(sys.executable)

Above answer is inspired from conda python isn't using the numpy version I try install if I also specify that it should use python 2. It doesn't provide the solution. I have posted a solution above.

watchtower
  • 4,140
  • 14
  • 50
  • 92