3

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)
>>>
3
  • Have you installed psutils in your virtualenv as stated by conda? Commented Oct 27, 2016 at 22:04
  • @P.Camilleri can you please point me to that? I don't see anything about psutils in the docs I've been following. However, perhaps I should try conda create -n p3 python=3 anaconda. Would that insure that the right version of numpy is linked? Commented Oct 27, 2016 at 22:14
  • 1
    Weel there was a line in the code you included which said No psutil available. To proceed, please conda install psutil. But it looks like you fixed your issue! Commented Oct 28, 2016 at 7:47

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! I did unset PYTHONPATH and numpy imported properly inside the env. Question: if I remove that environment variable from my .bashrc altogether, what will happen if I run python outside of a specified environment. For instance, just log in and type python?
You will get whichever python comes first on your $PATH. If you let miniconda modify your path, then it will be the "root" environment from miniconda. To check, see what you get if you run which python.
Got it. I put the CONDA_BIN miniconda created before my path, and started my path with export PATH="$CONDA_BIN:/usr/bin....". Works as hoped for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.