1

I am trying to use condas to install an environment that uses python 2.7 and numpy version 1.10

I try to create such an environment

 conda create -n test2 python=2.7 numpy=1.10

It contends it is going to install the software I specified

The following NEW packages will be INSTALLED:

mkl:        11.3.3-0     
numpy:      1.10.4-py27_2
openssl:    1.0.2l-0     
pip:        9.0.1-py27_1 
python:     2.7.13-0     
readline:   6.2-2        
setuptools: 27.2.0-py27_0
sqlite:     3.13.0-0     
tk:         8.5.18-0     
wheel:      0.29.0-py27_0
zlib:       1.2.8-3

and then activate it and run python

 source activate test2
 python

it informs me I am using python version 2.7.13 and then I try check the numpy version number

 import numpy
 numpy.version.version

It tells me I have version

'1.13.0'

which is not the version I specified. On the other hand, If I skip specifying the python version, it installs python 3, but the correct version of numpy (1.10.4)

Any ideas about what is going on here? Furthermore, how do I fix this? Thanks!

Edit: as per Uvar's comment

 conda create -n test4 python=2.7 numpy=1.10 --no-deps

Tells me

The following NEW packages will be INSTALLED:

numpy:  1.10.4-py27_2
python: 2.7.13-0

but then if I source activate test4 and check the numpy version number, it tells me I am running 1.13.0 again.

Edit 2 (Again in response to a query by Uvar):

 conda list -n test2

returns

# packages in environment at /home/ohnoplus/anaconda3/envs/test2:

#

 mkl                       11.3.3                        0   
 numpy                     1.10.4                   py27_2   
 openssl                   1.0.2l                        0 
 pip                       9.0.1                    py27_1   
 python                    2.7.13                        0   
 readline                  6.2                           2   
 setuptools                27.2.0                   py27_0   
 sqlite                    3.13.0                        0   
 tk                        8.5.18                        0   
 wheel                     0.29.0                   py27_0   
 zlib                      1.2.8                         3

Edit 3: If I source activate test2 and then inside of python import numpy and numpy.__file__ I get the following

'/home/ohnoplus/.local/lib/python2.7/site-packages/numpy/__init__.pyc'

meanwhile if outside of python, but inside of test2, I echo $PATH

I get

/home/ohnoplus/anaconda3/envs/test2/bin:/home/ohnoplus/anaconda3/bin:/home/ohnoplus/bin:/home/ohnoplus/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Edit 4: @Uvar and @MSeifert point out that I should get my path variables pointing in the right place. I'll experiment with getting this right but I have a couple of questions:

I notice that the python sys.path in test2 appears to be looking in the right place for numpy if I look at sys.paths

 import sys
 print (sys.path)

['', '/home/ohnoplus/anaconda3/envs/test2/lib/python27.zip', '/home/ohnoplus/anaconda3/envs/test2/lib/python2.7', '/home/ohnoplus/anaconda3/envs/test2/lib/python2.7/plat-linux2', '/home/ohnoplus/anaconda3/envs/test2/lib/python2.7/lib-tk', '/home/ohnoplus/anaconda3/envs/test2/lib/python2.7/lib-old', '/home/ohnoplus/anaconda3/envs/test2/lib/python2.7/lib-dynload', '/home/ohnoplus/.local/lib/python2.7/site-packages', '/home/ohnoplus/anaconda3/envs/test2/lib/python2.7/site-packages', '/home/ohnoplus/anaconda3/envs/test2/lib/python2.7/site-packages/setuptools-27.2.0-py2.7.egg']

Should I be updating $PATH in as referenced in the command line, this sys.path variable, or something else?

ohnoplus
  • 1,205
  • 1
  • 17
  • 29
  • Are you running `source activate` or `source activate test2`? If you are running the former, you're switching to the `root` env and not the one you just created. – JoshAdel Aug 09 '17 at 17:40
  • Sorry. That was a mis-type on stackoverflow. I ran `source activate test2` on my system to get the behavior described. – ohnoplus Aug 09 '17 at 17:45
  • So, if I follow the exact same steps, there is no problem for me. Then again, I have a windows install. From the packages being installed, I can see that you probably have OSX? There is a possibility that your root python install is interfering. Could you try the same with `--no-deps` flag? – Uvar Aug 09 '17 at 18:34
  • I am running Ubuntu 16.04. Tried with the --no-deps flag and got exactly the same result, with the exception that the only packages that it said it was going to install were numpy and python. – ohnoplus Aug 09 '17 at 18:40
  • hmm..and output from `conda list -n test2` ? – Uvar Aug 09 '17 at 19:12
  • Please see the newest edit. Also, thanks for bearing with me on this. – ohnoplus Aug 09 '17 at 19:22
  • 1
    Could you check `numpy.__file__` and compare it to the path for your `test?` environment. – MSeifert Aug 09 '17 at 19:33
  • @MSeifert: I've added the output of `numpy.__file__`. I'm not quite sure about the correct way to get the path for test2. I included the output of `echo $PATH`, but maybe you are looking for something else. Let me know if I should run something else too. – ohnoplus Aug 09 '17 at 19:44
  • 1
    Any `conda` environment (except the root one) has an `envs` folder somewhere in the filepath. From what I see you don't use the Python/NumPy from your conda installation. The good news is: The solution is simple. The bad news is: You have to restructure your PATH. :) – MSeifert Aug 09 '17 at 19:49
  • 1
    So, the package is installed correctly, but seems to me that once you go into the interpreter, you get hooked up with your root install instead of the environment. I am unfortunately no expert on this. You will need to change your PATH or do something which you are better off not doing: unbinding the link between `python` and `python2` .. it IS working in a python 3 install, since then `python` in your activated environment silently points to `python3` .. Srry to be of little help :( – Uvar Aug 09 '17 at 19:51
  • Thanks everyone. It does indeed seem like python is looking in the wrong place for numpy. I'm now figuring out the best way of correcting this. I'm trying to figure outh whether to edit $PATH or sys.path within python, or maybe some other path (please see my edit 4). Any advice? – ohnoplus Aug 09 '17 at 20:08
  • On second thought, it looks like home/ohnoplus/.local/lib/python2.7/site-packages is before /home/ohnoplus/anaconda3/envs/test2/lib/python2.7/site-packages". I think I just need to figure out how to change the order of these. – ohnoplus Aug 09 '17 at 20:23
  • can you try something like `export PATH=${PATH%/home/ohnoplus/.local/lib/python2.7/site-packages}` before calling `python` ? I'll admit it is a long shot, but can't hurt to try – Uvar Aug 09 '17 at 20:39
  • I ended up solving the problem before I tried running this fix. Thanks for the suggestion though! – ohnoplus Aug 09 '17 at 20:49

1 Answers1

0

Ok. Got it! When I run sys.path it looks in ".local/lib/python2.7/site-packages" before it looks in "anaconda3/envs/test2/lib/python2.7/site-packages"

I don't think I was ever using the python version in .local, and so I just moved the python2.7 directory out of ~/.local/lib. This seemed to remedy the problem. Now when I import numpy, the version is as expected.

Reference: The discussion linked below, along with the comments of Uvar and MSeifert, pointed me in the direction to solve this problem.

https://github.com/conda/conda/issues/448

ohnoplus
  • 1,205
  • 1
  • 17
  • 29