简体   繁体   English

ModuleNotFoundError:Jupyter Notebooks 中没有名为“pandas”的模块

[英]ModuleNotFoundError: No module named 'pandas' in Jupyter Notebooks

I am using a Jupyter Notebook in VSCode for a simple data science project.我在 VSCode 中使用 Jupyter Notebook 进行简单的数据科学项目。 I've imported pandas in the past and had no problems, only now when I try to execute the code, "ModuleNotFoundError: No module named 'pandas'" is raised in the Notebook.我过去导入了 pandas 并且没有问题,只是现在当我尝试执行代码时,笔记本中出现“ModuleNotFoundError:没有名为'pandas'的模块”。

I installed pandas with pip, and when I type pip install pandas into the terminal, I get "requirement already satisfied".我用 pip 安装了 pandas,当我在终端中输入pip install pandas时,我得到“要求已经满足”。 Note: I have no problems importing pandas into a basic.py file.注意:我将 pandas 导入 basic.py 文件没有问题。 The error only occurs in the Jupyter Notebook.该错误仅发生在 Jupyter Notebook 中。 (Also, I am not using a virtual environment.) (另外,我没有使用虚拟环境。)

I tried using the solution found in (Jupyter Notebook) ModuleNotFoundError: No module named 'pandas' ) by adding "C:\Users\AppData\Local\Programs\Python\Python39" to the path, but it hasn't made a difference.我尝试使用在(Jupyter Notebook) ModuleNotFoundError: No module named 'pandas' ) 中找到的解决方案,方法是将 "C:\Users\AppData\Local\Programs\Python\Python39" 添加到路径中,但它没有任何区别.

    ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-9-2e52ded19b86> in <module>
----> 1 import pandas as pd
      2 df = pd.read_csv("archive\IPIP-FFM-data-8Nov2018\data-final.csv", delimiter="\t")
      3 df

ModuleNotFoundError: No module named 'pandas'

Pandas (1.2.3) Pandas (1.2.3)

Python (3.9) Python (3.9)

But below could help you to get to the root cause.但下面可以帮助您找到根本原因。

run pip freeze in jupiter and review if you see pandas installed.在木星中运行 pip 冻结并查看是否安装了 pandas。 Seems like your notebook and terminal are in different environments for sure.似乎您的笔记本电脑和终端肯定处于不同的环境中。

!pip freeze !pip 冻结

There I was going through the same problem, but Thank God I found the solution, you are using your command line but perhaps it's not in as same location as in your Juypter notebook so, what solved my problem was installing the library in Anaconda prompt, so just do pip install the library name... Hope that answers your question;)在那里我遇到了同样的问题,但谢天谢地我找到了解决方案,你正在使用你的命令行,但也许它与你的 Juypter 笔记本的位置不同,所以解决我的问题是在 Anaconda 提示符下安装库,所以只需做 pip 安装库名称......希望能回答你的问题;)

I had the same problem.我有同样的问题。 Are you using anaconda?您使用的是 anaconda 吗? If so it may be an issue with the kernel/ multiple envrionments.如果是这样,则可能是内核/多个环境的问题。 This link https://jupyter-notebook.readthedocs.io/en/stable/troubleshooting.html tells you everything you need.这个链接https://jupyter-notebook.readthedocs.io/en/stable/troubleshooting.html告诉你你需要的一切。

Essentially: I had multiple versions of python installed and stored in separate locations.本质上:我安装了多个版本的 python 并存储在不同的位置。 The ~/opt/anaconda location and also a ~/.pyenv. ~/opt/anaconda 位置以及 ~/.pyenv。 After installing anaconda I was encountering errors in both VS code and Jupyter through Anaconda- Navigator.安装 anaconda 后,我通过 Anaconda-Navigator 在 VS 代码和 Jupyter 中遇到错误。 My kernel was using the original python location, and this was causing issues.我的 kernel 使用原来的 python 位置,这导致了问题。 Once I realized this it was an easy fix.一旦我意识到这一点,这很容易解决。

For VS code: I simply had to click the drop down and select the anaconda kernel location.对于 VS 代码:我只需单击下拉菜单 select anaconda kernel 位置。 Mine was already listed, each option indicates the file path in the drop down.我的已经列出来了,每个选项都在下拉列表中指示文件路径。

For Jupyter via the Anaconda- Navigator: (This is all explained in greater and more technical detail in the link above.) For Jupyter notebooks I had to go in and create a new kernel file with the correct location.对于通过 Anaconda-Navigator 的 Jupyter:(这在上面的链接中有更多和更多的技术细节解释。)对于 Jupyter 笔记本,我必须输入 go 并在正确的位置创建一个新的 kernel 文件。 I would check the location of your anaconda python file, and then use the $ jupyter kernelspec list command in your terminal to see a list of your kernels, I personally had one "python 3" you can then look at this folder and the kernel.json file within it.我会检查您的 anaconda python 文件的位置,然后在您的终端中使用$ jupyter kernelspec list命令查看您的内核列表,我个人有一个“python 3”,然后您可以查看此文件夹和 kernel.json 文件在里面。 The kernel.json file has the location of your kernel stored, its very straight forward. kernel.json 文件存储了您的 kernel 的位置,非常简单。 If those locations do not match up you may be encountering the same problem.如果这些位置不匹配,您可能会遇到同样的问题。 I just duplicated the whole "python 3" file, renamed the duplicate "Anaconda Python" and changed the kernel path.我刚刚复制了整个“python 3”文件,将复制的文件重命名为“Anaconda Python”并更改了 kernel 路径。 I can now see both options in the kernel drop down in Jupyter.我现在可以在 Jupyter 的 kernel 下拉列表中看到这两个选项。 I switched to the new kernel and everything is running fine:)我切换到新的 kernel 一切正常:)

After installing Jupyter Notebook, I re-ran the anaconda install.安装 Jupyter Notebook 后,我重新运行 anaconda 安装。 Seemed to fix it.似乎修复它。

I got a solution:我有一个解决方案:

1 - open anaconda cmd prompt (not windows one) 1 - 打开 anaconda cmd 提示(不是 windows 一个)

2 - type in prompt: 2 - 输入提示:

conda info --envs畅达信息--envs

to see if you have another virtual envirovment, and if you have, it will appear a list with the NAME of env, and the current one you are marked with a *.看看你是否有另一个虚拟环境,如果有,它会出现一个名称为 env 的列表,当前你用 * 标记。

3 - if you see a second env, so type in prompt: 3 - 如果您看到第二个环境,请输入提示:

conda activate NameOfEnv conda 激活 NameOfEnv

where NameOfEnv is the name you saw in the list, unmarked.其中 NameOfEnv 是您在列表中看到的未标记的名称。

4 - now it will appear a () with the name of your new env. 4 - 现在它会出现一个 () 和你的新环境的名称。 and you can type im prompt:您可以输入 im 提示符:

pip install pandas pip 安装 pandas

5 - as a last step, you must restart you Jupyter notebook kernel, if you dont know how to do, just close and open it again. 5 - 最后一步,你必须重启你的 Jupyter notebook kernel,如果你不知道该怎么做,只需关闭并再次打开它。

6 - Now you can import pandas and use it:-) 6 - 现在您可以导入 pandas 并使用它:-)

All of the answers above work if you don't have pandas installed.如果您没有安装 pandas,以上所有答案都有效。 I had similar problem, but it was jupyter related.我有类似的问题,但它与 jupyter 相关。 I fixed it with:我修复了它:

pip3 install pandas jupyter

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

相关问题 ModuleNotFoundError: No module named... Jupyter Notebooks - ModuleNotFoundError: No module named... Jupyter Notebooks ModuleNotFoundError:没有名为“pandas”的模块 - Jupyter - ModuleNotFoundError: No module named 'pandas' - Jupyter ModuleNotFoundError:没有名为“camelot”的模块 | 适用于 Jupyter Notebooks 但不适用于 VSCode - ModuleNotFoundError: No module named 'camelot' | Works in Jupyter Notebooks but not VSCode ModuleNotFoundError:没有名为“pandas”的模块(jupyter notebook) - ModuleNotFoundError: No module named 'pandas' (jupyter notebook) ModuleNotFoundError:Jupyter Notebook 上没有名为“pandas”的模块 - ModuleNotFoundError: No module named 'pandas' on Jupyter Notebook (Jupyter Notebook) ModuleNotFoundError: No module named 'pandas' - (Jupyter Notebook) ModuleNotFoundError: No module named 'pandas' ModuleNotFoundError:没有名为 pandas 的模块 - ModuleNotFoundError: No module named pandas ModuleNotFoundError:没有名为“pandas”的模块 - ModuleNotFoundError: No module named 'pandas' ModuleNotFoundError:没有名为“skmultilearn”Jupyter 的模块 - ModuleNotFoundError: No module named 'skmultilearn' Jupyter ModuleNotFoundError:Jupyter 中没有名为“matploitlib”的模块 - ModuleNotFoundError: No module named 'matploitlib' in Jupyter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM