Conda list shows a package but cannot import it

Question:

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 😀

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'
>>> 
Asked By: Damien F

||

Answers:

Seems to be deps related issue see here github , So maybe You should ensure that Anaconda is up-to-date so that you are working with all the latest package releases. To do this, you should first update the conda utility run : conda update conda , When prompted to do so, type y to proceed with the update. After that update anaconda also run : conda update anaconda Again when prompted to do so, type y to proceed , after updates finished open new terminal and verify : conda --version
and : python --version

  • now try reinstalling visdom :conda install -n universe visdom --force-reinstall or just update all packages : conda install -n universe --update-all .

Answered By: WaLid LamRaoui

It might be an issue with file system permissions. This could happen if you have installed the package while under root. Try to run

sudo chmod -R a+rX /home/deeplearning/anaconda3/envs/

Drop the sudo if you are root in your VM terminal.

Answered By: igrinis

A couple possibilities occur to me:

1. A Potential Path Problem

Your python command might refer to a different python than the python which is in your active conda environment folder. Check this by running in terminal which conda and which python. If you get something like the below, you’re good here.

/anaconda3/bin/conda
/anaconda3/envs/<yourEnvName>/bin/python

If you are getting different paths, it is possible your path is messed up. open up your .bashrc file and double check lines associated with python and conda.

Alternatively, reinstall conda.

2. A Very Vexing Version Variation

You might have a version/dependency incompatibility issue. This seems unlikely to me as visdom is compatible with python 2.7 onward (I think) and you clearly are using python 3.5.2. Nonetheless, this might happen if you are using multiple package managers. Nowadays it is less common, but it does happen occasionally. Try checking this by running pip show visdom and/or conda search --reverse-dependency visdom or the equivalent for your package manager.

If this is indeed a problem, then I suggest first updating your packages and if that does not work then uninstalling visdom with the original package manager and trying to install with a different package manager.


If all of the above fails, start exploring your problem from a new environment. Can you replicate it in the new environment? (I can’t). Can you replicate it on another machine? etc…

Keep the internets updated with your problem as we might be able to help some others out!

Answered By: Joe B

Check the files installed for the package as per List installed files of a package? and compare the list with your sys.path.

For visdom specifically, looking at the contents of the available Linux tarball, I see that it contains paths like lib/python3.6/site-packages — i.e. it’s for Python 3.6 while your Python is 3.5.

Answered By: ivan_pozdeev

I unfortunately don’t have a “Do exactly this to fix your problem” solution but I would suggest the following steps. Many seem obvious but I find when sorting these sorts of problems out you have to be certain of each step before moving on.

  1. Does the host system, in this case your Ubuntu VM, have multiple versions of python installed? Are you sure you are using the version you think you’re using? Did you check your path variable? You need to be sure you’re using your conda installation.
  2. Does the host system have different versions of conda installed?
  3. It looks like in the activated environment you checked the package is listed in conda. But is it in the package directory for your virtual environment? One way to check this is to use the find command and specify the base path for your virtual environment.
  4. Try forcing the reinstallation of the package.
  5. Try using pip instead of conda. If your environment is setup properly pip should install packages to the conda path.

more desperate steps

  1. Make a new virtual environment. Add packages one by one. Examine what each package is changing.
  2. Reinstall conda.
  3. Create a new instance of your vm.
  4. Make a vm instance from a different image.
  5. Make your own image.

This is just one way to troubleshoot the problem. When possible try to avoid steps 6-10 because they’re rather involved. That said sometimes it’s a problem with the vm and not with you.

Answered By: VanBantam

Realize this is a very old question but the same thing just happened to me after doing a conda update conda on my base environment on OSX and the package was numpy. Showed in conda list but could not be imported. What I did, which fixed it:

conda activate base
conda remove numpy
conda install numpy

This fixed things.

Answered By: Eric Bridger

I meet the same problem, and tried all the given solutions to solve this problem, they didn’t work for me.
Finally I just add the package installed directory to sys.path:

import sys  
sys.path.append('/Users/eng/anaconda3/envs/paddle/lib/python2.7/site-packages')

it workded.

Answered By: zhangshuang

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.

Answered By: Huanfa Chen
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.