Search code examples
pythonanacondavirtualenv

Conda list shows a package but cannot import it


Here an issue i'm having on a conda Virtual env. I'm using ubuntu 64b guest on windows 7 host with Virtual Box.

So when i'm doing :

source activate MyVirtEnv
conda list |grep visdom
visdom                    0.1.05                        0    conda-forge

Seems to be installed right ? Next step :

python
Python 3.5.3 |Anaconda custom (64-bit)| (default, Mar  6 2017, 11:58:13) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import visdom
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'visdom'
>>> 

Ok, here i'm lost. Why does python does not recognize this package (and it's not the only one). I'm still in my env activated when executing python.

I'm quite new to python so perhaps i'm missing a huge mistake, please be kind :D

Thanks for your help on this one !

Update 1 :

deeplearning@deep-learning-virtual-machine:~$ source activate universe
(universe) deeplearning@deep-learning-virtual-machine:~$ python
Python 3.5.3 |Anaconda custom (64-bit)| (default, Mar  6 2017, 11:58:13) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/deeplearning/anaconda3/envs/universe/lib/python35.zip', '/home/deeplearning/anaconda3/envs/universe/lib/python3.5', '/home/deeplearning/anaconda3/envs/universe/lib/python3.5/plat-linux', '/home/deeplearning/anaconda3/envs/universe/lib/python3.5/lib-dynload', '/home/deeplearning/anaconda3/envs/universe/lib/python3.5/site-packages', '/home/deeplearning/anaconda3/envs/universe/lib/python3.5/site-packages/Sphinx-1.5.6-py3.5.egg', '/home/deeplearning/gym', '/home/deeplearning/anaconda3/envs/universe/lib/python3.5/site-packages/torchvision-0.1.9-py3.5.egg']
>>> sys.executable
'/home/deeplearning/anaconda3/envs/universe/bin/python'
>>> 

Solution

  • I have answered this question in another post:

    https://stackoverflow.com/a/65584502/4667568


    I encountered this issue in my conda environment. The reason is that packages have been installed into two different folders, only one of which is recognised by the Python executable.

    ~/anaconda2/envs/[my_env]/site-packages ~/anaconda2/envs/[my_env]/lib/python2.7/site-packages

    A proved solution is to add both folders to python path, using the following steps in command line (Please replace [my_env] with your own environment):

    conda activate [my_env]. conda-develop ~/anaconda2/envs/[my_env]/site-packages conda-develop ~/anaconda2/envs/[my_env]/lib/python2.7/site-packages (conda-develop is to add a .pth file to the folder so that the Python executable knows of this folder when searching for packages.) To ensure this works, try to activate Python in this environment, and import the package that was not found.