import pandas as pd ImportError: No module named pandas

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/54497098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 06:18:40  来源:igfitidea点击:

import pandas as pd ImportError: No module named pandas

python-3.xpandasimportimporterror

提问by Thibault Monsel

I can't seem to import panda package. I use Visual Studio code to code. I use a mac and have osX 10.14 Majove.

我似乎无法导入Pandas包。我使用 Visual Studio 代码进行编码。我使用 mac 并且有 osX 10.14 Majove。

The code that i am trying to compile is :

我试图编译的代码是:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
house_data = pd.read_csv('house.csv')
plt.plot(house_data['surface'], house_data['loyer'], 'ro', markersize=4)
plt.show()

When I try to use pip install pandasi get on my terminal :

当我尝试使用pip install pandas我的终端时:

(base) Thibaults-MBP-5d47:ML_folder thibaultmonsel$ pip install pandas
Requirement already satisfied: pandas in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.24.0)
Requirement already satisfied: pytz>=2011k in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2018.9)
Requirement already satisfied: python-dateutil>=2.5.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2.7.5)
Requirement already satisfied: numpy>=1.12.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (1.15.3)
Requirement already satisfied: six>=1.5 in /Users/thibaultmonsel/Library/Python/3.7/lib/python/site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)
(base) Thibaults-MBP-5d47:ML_folder thibaultmonsel$

Then when i execute my code i get :

然后当我执行我的代码时,我得到:

Traceback (most recent call last):
  File "ML1.py", line 5, in <module>
    import pandas as pd
ImportError: No module named pandas

After if i try sudo pip install pandasi get :

如果我尝试sudo pip install pandas我得到:

(base) Thibaults-MBP-5d47:ML_folder thibaultmonsel$ sudo pip3 install pandas --upgrade
Password:
The directory '/Users/thibaultmonsel/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory.If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/thibaultmonsel/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pandas
  Downloading https://files.pythonhosted.org/packages/34/63/529fd1391044051514f2f22d61754245db2133cd37c4dad7150a1cbe2ece/pandas-0.24.1-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (15.9MB)
    100% |████████████████████████████████| 15.9MB 901kB/s
Requirement already satisfied, skipping upgrade: python-dateutil>=2.5.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2.7.5)
Requirement already satisfied, skipping upgrade: numpy>=1.12.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (1.15.3)
Requirement already satisfied, skipping upgrade: pytz>=2011k in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2018.9)
Requirement already satisfied, skipping upgrade: six>=1.5 in /Users/thibaultmonsel/Library/Python/3.7/lib/python/site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)
Installing collected packages: pandas
  Found existing installation: pandas 0.24.0
    Uninstalling pandas-0.24.0:
      Successfully uninstalled pandas-0.24.0
Successfully installed pandas-0.24.1

However, i still get no modules named pandas

但是,我仍然得到 no modules named pandas

Lastly, when i try pip3 install pandasi get :

最后,当我尝试时,pip3 install pandas我得到:

Requirement already satisfied: pandas in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.24.0)
Requirement already satisfied: pytz>=2011k in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2018.9)
Requirement already satisfied: numpy>=1.12.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (1.15.3)
Requirement already satisfied: python-dateutil>=2.5.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2.7.5)
Requirement already satisfied: six>=1.5 in /Users/thibaultmonsel/Library/Python/3.7/lib/python/site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)

When i try to execute the program i get the same error mentioned above after using pip3 install pandas....

当我尝试执行该程序时,我在使用pip3 install pandas...后遇到上述相同的错误。

I also did an import.sysif can help :

我也做了一个import.sysif 可以帮助:

base) Thibaults-MBP-5d47:ML_folder thibaultmonsel$ python help1.py
2.7.10 (default, Aug 17 2018, 17:41:52)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)]

Here is also my sys.path:

这也是我的sys.path

['/Users/thibaultmonsel/Desktop/ML_folder', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

回答by PJW

You need to install pandaswith:

您需要安装pandas

pip install pandas

pip install pandas

If you run into issues with privileges, you may need to run:

如果您遇到权限问题,您可能需要运行:

sudo pip install pandas

sudo pip install pandas

It is also possible on Python 3 that you may need to run:

您也可能需要在 Python 3 上运行:

pip3 install pandas(although pipmay be pointing to pip3already). You can read about differences between pip versions on this SO post.

pip3 install pandas(虽然pip可能pip3已经指向)。您可以在此 SO post上阅读 pip 版本之间的差异。

If you don't have pipinstalled, see herefor installation.

如果您还没有pip安装,请参阅此处进行安装。

回答by FC.coder

Check pandas package path from your env with:
jupyter kernelspec list

从您的 env 中检查 pandas 包路径:
jupyter kernelspec list

If you see the path: /Users/yourname/Library/Jupyter/kernels/yourenv

如果您看到路径: /Users/yourname/Library/Jupyter/kernels/yourenv

Delete that Jupyterfolder from Libraryand run again.

Jupyter从中删除该文件夹Library并再次运行。

回答by Simin Maleki

if you see such thisin your IDE and the error "no module named pandas" when you run your code, it means that pandas has not been installed although you have done "pip install pandas" or whatever.

如果您在 IDE 中看到这样的信息,并且在运行代码时出现错误“没有名为 pandas 的模块”,则意味着尽管您已经完成了“pip install pandas”或其他任何操作,但尚未安装 pandas。

Go to file > settings > project interpreterand see if pandas is available in the list of packages. if not simply click + (plus), choose pandas and install it in your project environment .
see picturethen wait for you IDE update your project skeletons ... voila , the error disappears !

转到文件 > 设置 > 项目解释器,然后查看列表中是否有 pandas 可用。如果不是简单地单击 +(加号),请选择 pandas 并将其安装在您的项目环境中。
看图片然后等你 IDE 更新你的项目骨架......瞧,错误消失了!

回答by Noyon Islam

When entering the command to run your file, make sure you specify which version of python you're using. For example, instead of python filename.py, use python3 filename.pyor python2 filename.py

输入命令以运行文件时,请确保指定您使用的 Python 版本。例如,代替 python filename.py,使用python3 filename.pypython2 filename.py

回答by martin

your pandas is installed in python3 (3.7):

您的Pandas安装在 python3 (3.7) 中:

Requirement already satisfied: pandas in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.24.0)

but you are running python2.7 and pandas isn't in your path 2.7:

但是您正在运行 python2.7 并且 Pandas 不在您的路径 2.7 中:

['/Users/thibaultmonsel/Desktop/ML_folder', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', 
'/Library/Python/2.7/site-packages', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

try to simply run your script using python3:

尝试使用 python3 简单地运行您的脚本:

python3 help1.py

or add python3 header, example:

或添加 python3 标头,例如:

#!/usr/bin/env python3

or 

#!/usr/local/bin/python3

and if that doesn't work (like I had the same problem because I was importing pandas from jupyter notebook, macos), you can ultimately import from your --user path, example:

如果这不起作用(就像我遇到了同样的问题,因为我从 jupyter notebook、macos 导入Pandas),您最终可以从您的 --user 路径导入,例如:

sys.path.append("/Users/<USER>/Library/Python/3.7/lib/python/site-packages")

but make sure you have pandas installed there (..python/site-packages/pandas) using

但请确保您在那里安装了Pandas (..python/site-packages/pandas) 使用

pip3 install pandas --user

pip3 安装Pandas --user