Search code examples
python-2.7python-3.xnumpycondaminiconda

Conda env not loading correct version of numpy


I'm running miniconda2 (python2.7 install). Rather than try to use miniconda3 side by side, I tried just creating a python3.5 environment. However, when I try to import numpy I get an error because python tries to load numpy for python2.7. I'm assuming this is because of the environment variables set in my .bashrc which point to the miniconda2 installation.

What is the best way to fix this? Is there a way I can use conda python2 and python3 side by side?

My .bashrc has:

export PYTHONLIB="/home/exacloud/lustre1/CompBio/miniconda2/lib"
export PYTHONPATH="/home/exacloud/lustre1/CompBio/miniconda2/lib/python2.7/site-packages"
export PYTHONUSERBASE="/home/exacloud/lustre1/CompBio/miniconda2"
export CONDA_BIN="/home/exacloud/lustre1/CompBio/miniconda2/bin"

Session:

balter@s-3-5:~$ conda create -n p3 python=3 pandas numpy
Fetching package metadata .............
Solving package specifications: ..........

Package plan for installation in environment /<path>/miniconda2/envs/p3:

The following NEW packages will be INSTALLED:

    blas:            1.1-openblas                  conda-forge
    ca-certificates: 2016.8.31-0                   conda-forge
    certifi:         2016.8.31-py35_0              conda-forge
    libgfortran:     3.0.0-1
    ncurses:         5.9-9                         conda-forge
    numpy:           1.11.2-py35_blas_openblas_200 conda-forge [blas_openblas]
    openblas:        0.2.18-5                      conda-forge
    openssl:         1.0.2h-2                      conda-forge
    pandas:          0.19.0-np111py35_0            conda-forge
    pip:             8.1.2-py35_0                  conda-forge
    python:          3.5.2-2                       conda-forge
    python-dateutil: 2.5.3-py35_0                  conda-forge
    pytz:            2016.7-py35_0                 conda-forge
    readline:        6.2-0                         conda-forge
    setuptools:      26.1.1-py35_0                 conda-forge
    six:             1.10.0-py35_1                 conda-forge
    sqlite:          3.13.0-1                      conda-forge
    tk:              8.5.19-0                      conda-forge
    wheel:           0.29.0-py35_0                 conda-forge
    xz:              5.2.2-0                       conda-forge
    zlib:            1.2.8-3                       conda-forge

Proceed ([y]/n)? y

Linking packages ...
[                    ]|                                                                            [ca-certificates     ]|                                                                            [libgfortran         ]|####                                                                        [ncurses             ]|########                                                                    [sqlite              ]|#############                                                               [tk                  ]|#################                                                           [openblas            ]|#######################                                              |  33%
Screen session on s (system load: 1.12 1.05 0.91)               Thu 27.10.2016 14:43
    wheel:           0.29.0-py35_0                 conda-forge
    xz:              5.2.2-0                       conda-forge
    zlib:            1.2.8-3                       conda-forge

Proceed ([y]/n)? y

Linking packages ...
[                    ]|                                                                           [ca-certificates     ]|                                                                           [libgfortran         ]|####                                                                       [ncurses             ]|########                                                                   [sqlite              ]|#############                                                              [tk                  ]|#################                                                          [openb[      COMPLETE      ]|######################################################################| 100%
No psutil available.
To proceed, please conda install psutil#
# To activate this environment, use:
# $ source activate p3
#
# To deactivate this environment, use:
# $ source deactivate
#
balter@s-3-5:~$
balter@s-3-5:~$ source activate p3
(p3) balter@s-3-5:~$ python
Python 3.5.2 | packaged by conda-forge | (default, Jul 26 2016, 01:32:08)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/<path>/miniconda2/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/<path>/miniconda2/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/<path>/miniconda2/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/<path>/miniconda2/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/<path>/miniconda2/lib/python2.7/site-packages/numpy/core/__init__.py", line 14, in <module>
    from . import multiarray
ImportError: dynamic module does not define module export function (PyInit_multiarray)
>>>

Solution

  • You should not set the PYTHONPATH environment variable in your .bashrc:

    http://conda.pydata.org/docs/troubleshooting.html#resolution-for-python-packages-make-sure-you-have-not-set-the-pythonpath-or-pythonhome-variable

    Activating the conda environment should take care of ensuring that all of your paths work with the packages in the environment.