简体   繁体   English

(Jupyter Notebook) ModuleNotFoundError: No module named 'pandas'

[英](Jupyter Notebook) ModuleNotFoundError: No module named 'pandas'

In my terminal, I ran:在我的终端中,我运行了:

pip install pandas
pip3 install pandas

Installation seemed to go well. go 似乎安装得很好。 When I write some code in a file and execute it in my terminal (prompting 'python filename.py' or 'python3 filename.py'), the pandas library can be imported and used without a problem.当我在一个文件中编写一些代码并在我的终端中执行它(提示'python filename.py'或'python3 filename.py')时,可以毫无问题地导入和使用pandas库。 However, when using Jupyter Lab and Jupyter Notebook, and I get this error when trying to import pandas:但是,当使用 Jupyter Lab 和 Jupyter Notebook 时,尝试导入 pandas 时出现此错误:

ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-38d4b0363d82> in <module>
----> 1 import pandas


ModuleNotFoundError: No module named 'pandas'

It seems like Jupyter Notebook does not recognize this library. Jupyter Notebook 似乎无法识别该库。 Very confused as of why and what I should do.非常困惑为什么以及我应该做什么。 FYI reinstalling anaconda did not help, and I am using 'pip' and 'pip3' to install libraries.仅供参考,重新安装 anaconda 没有帮助,我正在使用“pip”和“pip3”来安装库。

you've got at least 3 versions of Python installed (the system version, a copy of 3.7 and 3.8).您至少安装了 3 个版本的 Python(系统版本,3.7 和 3.8 的副本)。 you need to figure out which is which, ie what you've done to your system!你需要弄清楚哪个是哪个,即你对你的系统做了什么!

to know which version of Python is being run you can use something like (from your shell/command prompt, not in Python):要知道正在运行 Python 的哪个版本,您可以使用类似的东西(从您的 shell/命令提示符,而不是在 Python 中):

which python3

see here for an explanation and alternatives.有关解释和替代方案,请参见此处 this tells you where some version of Python is, but you can also ask for pip3 and conda , jupyter , etc, to see where those have ended up, and to make sure you're running the right one.这会告诉您 Python 的某个版本在哪里,但您也可以要求pip3condajupyter等,以查看它们的最终结果,并确保您运行的是正确的。 note that this involves your "shell's path" which you can customise so it picks the right one请注意,这涉及您可以自定义的“shell路径” ,以便选择正确的

next you need tools to figure out the equivalent "within Python".接下来,您需要工具来找出等效的“在 Python 中”。 Python libraries aren't independent programs/executables (ie what $PATH determines) so this is a seperate set of options Python 库不是独立的程序/可执行文件(即$PATH确定的)所以这是一组单独的选项

to display where Python looks for code you can do this (inside Python):要显示 Python 查找代码的位置,您可以执行以下操作(在 Python 中):

import sys
print(sys.path)

see here for more info about what's going on here有关此处发生的情况的更多信息,请参见此处

note that what happens when you "open jupyter notebook by clicking on the icon with Anaconda Navigator" is a bit more difficult to debug.请注意,当您“通过单击带有 Anaconda Navigator 的图标打开 jupyter notebook”时会发生什么,调试起来有点困难。 sys.executable might be useful to figure out what's going on sys.executable可能有助于弄清楚发生了什么

if you know xkcd, we're sort of in this state如果你知道 xkcd,我们就属于这个 state

I had a similar problem.我有一个类似的问题。 Your best bet is to install your packages direct from Jupyter notebook, then you can be sure that the packages are being installed into the local python instance.您最好的选择是直接从 Jupyter 笔记本安装您的包,然后您可以确保这些包被安装到本地 python 实例中。

! pip install --user <package>

The ! ! tells the notebook to execute the cell as a shell command.告诉笔记本将单元格作为 shell 命令执行。

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

相关问题 ModuleNotFoundError:没有名为“pandas”的模块(jupyter notebook) - ModuleNotFoundError: No module named 'pandas' (jupyter notebook) ModuleNotFoundError:Jupyter Notebook 上没有名为“pandas”的模块 - ModuleNotFoundError: No module named 'pandas' on Jupyter Notebook ModuleNotFoundError:没有名为“pandas”的模块 - Jupyter - ModuleNotFoundError: No module named 'pandas' - Jupyter Jupyter Notebook ModuleNotFoundError-&gt;没有名为&#39;sql&#39;的模块 - Jupyter Notebook ModuleNotFoundError --> No module named 'sql' ModuleNotFoundError:Jupyter Notebook 上没有名为“_tkinter”的模块 - ModuleNotFoundError: No module named '_tkinter' on Jupyter Notebook ModuleNotFoundError:在jupyter笔记本python中没有名为“可视化”的模块 - ModuleNotFoundError: No module named 'visualization' in jupyter notebook python Jupyter 笔记本:ModuleNotFoundError:没有名为“scipy”的模块 - Jupyter notebook: ModuleNotFoundError: No module named 'scipy' ModuleNotFoundError:Jupyter Notebook 中没有名为“tensorflow”的模块 - ModuleNotFoundError: No module named 'tensorflow' In Jupyter Notebook ModuleNotFoundError:Jupyter Notebook 没有名为“keras”的模块 - ModuleNotFoundError: No module named 'keras' for Jupyter Notebook 进入 Jupyter 笔记本:ModuleNotFoundError:没有名为“podman”的模块 - Getting in Jupyter notebook: ModuleNotFoundError: No module named 'podman'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM