Conda list shows a package but cannot import it
Solution 1
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.
Solution 2
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!
Solution 3
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.apend('/Users/eng/anaconda3/envs/paddle/lib/python2.7/site-packages')
it workded.
Solution 4
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
.
Solution 5
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.
- 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.
- Does the host system have different versions of conda installed?
- 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. - Try forcing the reinstallation of the package.
- Try using
pip
instead of conda. If your environment is setup properlypip
should install packages to the conda path.
more desperate steps
- Make a new virtual environment. Add packages one by one. Examine what each package is changing.
- Reinstall conda.
- Create a new instance of your vm.
- Make a vm instance from a different image.
- 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.
Related videos on Youtube
Damien F
Updated on July 09, 2022Comments
-
Damien F almost 2 years
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' >>>
-
darthbith over 6 yearsIs Python installed in the
MyVirtEnv
environment? What is the output ofsys.path
andsys.executable
from the Python that you're running? -
Damien F over 6 yearsYes, of course python is installed i updated the post with text entry you asked for
-
darthbith over 6 yearsWhat is the name of your environment? In your example at the top you use
MyVirtEnv
, but in the output below, the environment name seems to beuniverse
-
Damien F over 6 yearsMy environment name is universe (MyVirtEnv was a generic name)
-
darthbith over 6 yearsThen can you please show the output of the actual commands that you run to list the packages? For instance, can you
conda list -n universe | grep visdom
? -
Damien F over 6 years
conda list -n universe | grep visdom
:visdom 0.1.05 0 conda-forge
-
dia almost 6 yearsis this figured?
-
ivan_pozdeev about 5 yearsPossible duplicate of stackoverflow.com/questions/47138241/…
-
Manuel Alves over 2 yearsconda update --all fixed the issue for me.
-
-
Jacob Stern about 3 years#1 was indeed my issue. This post shows how to solve it. TL;DR:
conda deactivate && conda activate foo_env
stackoverflow.com/questions/36733179/…