简体   繁体   中英

Conda says package is already installed but doesn't list it and won't install it again. Python code can't import the library

Conda says the package is already installed and will not install it again, but when I list the packages in the environment, there are no packages installed.

When I try to import the package in a notebook file, it fails. 在此处输入图像描述

Running a terminal shell launched from JupyterLab:

  1. Use pip to uninstall bashplotlib - that works
  2. Use Conda to activate an environment -- That works
  3. Use Conda to install bashplotlib -- It fails because it's already supposedly installed
  4. Use Conda to print the packages installed in the Conda environment -- There are none listed
PS C:\Users\nicomp> pip uninstall bashplotlib Uninstalling bashplotlib-0.6.5: Would remove: c:\users\nicomp\anaconda3\lib\site-packages\bashplotlib-0.6.5-py2.7.egg-info c:\users\nicomp\anaconda3\lib\site-packages\bashplotlib\* c:\users\nicomp\anaconda3\scripts\hist-script.py c:\users\nicomp\anaconda3\scripts\scatter-script.py c:\users\nicomp\anaconda3\scripts\scatter.exe Proceed (Y/n)? y Successfully uninstalled bashplotlib-0.6.5 PS C:\Users\nicomp> conda activate fooEnvironment PS C:\Users\nicomp> conda info --envs # conda environments: # base * C:\Users\nicomp\anaconda3 bashplotlibEnvironment C:\Users\nicomp\anaconda3\envs\bashplotlibEnvironment condaTestEnvironment C:\Users\nicomp\anaconda3\envs\condaTestEnvironment fooEnvironment C:\Users\nicomp\anaconda3\envs\fooEnvironment jupyterlab-debugger C:\Users\nicomp\anaconda3\envs\jupyterlab-debugger microservices C:\Users\nicomp\anaconda3\envs\microservices ml C:\Users\nicomp\anaconda3\envs\ml someEnvironment C:\Users\nicomp\anaconda3\envs\someEnvironment zzz C:\Users\nicomp\anaconda3\envs\zzz PS C:\Users\nicomp> conda install -c conda-forge bashplotlib Collecting package metadata (current_repodata.json): done Solving environment: done # All requested packages already installed. PS C:\Users\nicomp> conda list -n fooEnvironment # packages in environment at C:\Users\nicomp\anaconda3\envs\fooEnvironment: # # Name Version Build Channel PS C:\Users\nicomp>

Activation Failing

From the conda info --envs output, it indicates that the conda activate command is not working, since the output shows that base is still activated (that's what " * " indicates). That is, despite the efforts, the package is getting installed in base .

Specifying Target Environment

I can't answer why the environment activation is broken (this can be specific to PowerShell or the Jupyter terminal - try searching), but I can at least recommend a more robust installation command. Rather than relying on environment activation, most Conda commands support specification of the target environment using the --name,-n or --prefix,-p flags. In this case,

conda install -n fooEnvironment -c conda-forge bashplotlib

would work no matter what environment happens to be activated.

I'd encourage this as a good habit to adopt because it makes the command less context-sensitive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM