简体   繁体   English

Conda 安装与 pip 安装(导入 seaborn 包时出现问题)

[英]Conda install vs pip install(issues in importing seaborn package)

I am facing an issue in importing module in jupyter notebook.我在 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. 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 在笔记本中给出了错误ModuleNotFoundError: No module named 'seaborn'我什至重新启动了 kernel、笔记本和 anacond,但问题仍然存在。 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.但是当我在笔记本中执行“conda list”时,package 不存在,但是在“conda install seaborn”之后,package 被安装,ZEFE90A8E604A7C840E88D03A67F6D8 被导入。 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) 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 python版本:3.10.5

conda version:4.14.0康达版本:4.14.0

jupyter version:4.10.0 jupyter 版本: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:警告:如果没有更多信息(例如 OP 的命令历史记录和环境设置),无法 100% 自信地回答这个问题,但最可能的解释是:

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. 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 .例如,用于名为<env-name>的 conda 环境的 Windows 样式文件系统中的标准 conda package 安装位置是该环境的site-packages目录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.该目录默认在其对应环境的Python路径下。

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.这种关于在目录中哪里可以找到实际 conda 包的知识带有警告:除非您对 Python 导入系统和 conda 的 package 管理基础架构有专业知识,否则在 conda 中手动添加或删除目录通常是一个坏主意环境的site-packages目录。

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.相关警告:尽管 pip 与 conda 的互操作性在过去几年中得到了很大改善,但在您的 conda 环境中使用 pip 安装标准 ZA7F5F35426B927411FC9231B5638217 包通常不是一个好主意。 conda install exists, and you should use it for a reason . conda install存在, 你应该使用它是有原因的

For more detailed information about what your Python path is and how it's set, see this informational guide from Real Python.有关 Python 路径是什么以及如何设置的更多详细信息,请参阅 Real Python 的此信息指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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