简体   繁体   中英

Conda install vs pip install(issues in importing seaborn package)

I am facing an issue in importing module in jupyter notebook. The issue is that I access the jupyter notebook through anaconda software and when i tired installing seaborn, I used the command "pip install seaborn" in cmd and the package was installed(verifed through "pip list") but when i tried importing the seborn package in notebook it gave the error ModuleNotFoundError: No module named 'seaborn' I even restarted the kernel,notebook and anacond but still the issue persisted. But when i did "conda list" in the notebook the package was not there but then after "conda install seaborn" the package got installed and the package got imported. I wanted to know why this error occured as i didnt face this situation while importing numpy or pandas(for numpy or pandas only pip install was enough)

python version:3.10.5

conda version:4.14.0

jupyter version:4.10.0

Caveat: Without more information (such as OP's command history and environment settings), one can't answer this question with 100% confidence, but there is a most likely explanation:

Running pip install seaborn via cmd installed seaborn in a directory that is not part of the Python path of the conda environment that the Jupyter Notebook was running in. It seems most likely you were not using a conda command prompt to pip install seaborn , but you were using a conda command prompt to pip install numpy and pandas , which is why they were installed in a directory included in the Jupyter Notebook's conda environment's Python path.

For example, a standard conda package install location in a Windows-style filesystem for a conda environment named <env-name> is the site-packages directory for that environment, C:\Users\<User>\<Conda_Distribution>\envs\<env-name>\Lib\site-packages . This directory is in the Python path of a its corresponding environment by default.

This knowledge of where to find your actual conda packages in a directory comes with a warning: Unless you have expert knowledge of the Python import system and conda's package management infrastructure, it is a generally a bad idea to manually add or delete directories in your conda environment's site-packages directory.

A related warning: Although the interoperability of pip with conda has been greatly improved in the last few years, it is generally a bad idea to use pip to install standard Python packages in your conda environment. conda install exists, and you should use it for a reason .

For more detailed information about what your Python path is and how it's set, see this informational guide from Real Python.

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