Python 导入错误:没有名为“pandas”的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38061426/
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-08-19 20:16:06  来源:igfitidea点击:

ImportError: No module named 'pandas'

pythonpandas

提问by Tthieme

I am trying to learn pandas and I haven't been able to import it into my code.

我正在尝试学习熊猫,但无法将其导入到我的代码中。

I have looked at other answers on this site and none of them have worked.

我查看了本网站上的其他答案,但没有一个有效。

I just installed anaconda and installed everything through conda.

我刚刚安装了 anaconda 并通过 conda 安装了所有东西。

Here is a sample script that I am trying to run.

这是我尝试运行的示例脚本。

import pandas as pd

writer = pd.ExcelWriter('farm_data.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1')

workbook = writer.book
worksheet = writer.sheets['Sheet1']

chart = workbook.add_chart({'type': 'column'})

And the error it kicks back.

以及它反弹的错误。

Traceback (most recent call last):

File "C:\Users\thiet01\Documents\Python Scripts\new 1.py", line 1, in

import pandas

ImportError: No module named 'pandas'

回溯(最近一次调用最后一次):

文件“C:\Users\thiet01\Documents\Python Scripts\new 1.py”,第 1 行,在

进口大熊猫

导入错误:没有名为“pandas”的模块

If you need any more information, please let me know and I can provide it.

如果您需要更多信息,请告诉我,我可以提供。

Thanks in advance for any help.

在此先感谢您的帮助。

回答by Marcos

below solved my issue:

下面解决了我的问题:

apt-get install python3-pandas or apt-get install python2-pandas

apt-get install python3-pandas 或 apt-get install python2-pandas

Font: https://ask.fedoraproject.org/en/question/36529/installing-python-pandas/

字体:https: //ask.fedoraproject.org/en/question/36529/installing-python-pandas/

回答by Daniel

I had the same problem for a long time. Today I tried a whole day and it finally worked. Below is the steps how I did it. I don't have theory for why the problem exist and how it is solved. I just know the following steps helped me get pandasgoing.

我有同样的问题很长一段时间。今天我试了一整天,终于成功了。以下是我如何做到的步骤。我没有关于问题存在的原因以及如何解决的理论。我只知道以下步骤帮助我pandas开始。

A. downloadfirst and install minicondausing the following code:

A.首先下载miniconda使用以下代码安装:

bash Miniconda2-latest-MacOSX-x86_64.sh

B. create an env for your project using following code:

B. 使用以下代码为您的项目创建一个 env:

conda create --name trypandas numpy pandas jupyter

C. going to your env and try jupyter notebook with pandas using:

C. 转到您的 env 并使用以下命令尝试使用带有 Pandas 的 jupyter notebook:

source activate trypandas
jupyter notebook

Note: my own experience indicates:

注意:我自己的经验表明:

  1. when I missed conda install jupyter, pandas only work in pure python environment, not in ipython nor in jupyter notebook;

  2. after conda install jupyter, pandasworks in jupyter notebooknow.

  3. the step B above installing jupytertogether with numpyand pandas, there should not be a problem.

  1. 当我错过时conda install jupyter,pandas 只能在纯 python 环境中工作,不能在 ipython 或 jupyter notebook 中工作;

  2. 之后conda install jupyterpandas工作在jupyter notebook现在。

  3. 上面的步骤 Bjupyternumpy和一起安装pandas,应该没有问题。

回答by David C

Hereis the basic documentation on how to instal python packages.

是有关如何安装 python 包的基本文档。

For OS X and Linux users, the following command ought to work:

对于 OS X 和 Linux 用户,以下命令应该可以工作:

pip install pandas

回答by sujay

Even I had same issue but this solved my problem-

即使我有同样的问题,但这解决了我的问题-

sudo apt-get install python-pandas

sudo apt-get install python-pandas

To check if pandas is installed or not:

要检查是否安装了熊猫:

Open up a Python prompt by running the following:

通过运行以下命令打开 Python 提示符:

python

python

At the prompt, type the following:

在提示符下,键入以下内容:

import pandas

print pandas.\__version__

This will print the installed version of pandas in the system

这将打印系统中已安装的熊猫版本

回答by mattyb

I wanted to add this as a comment but Im not special enough yet in the eyes of stackoverflow.

我想将此添加为评论,但在 stackoverflow 眼中我还不够特别。

Some modules need to be separately installed into your libraries folder of your python directory.Using pip (https://pip.pypa.io/en/stable/) is helpful for this. Otherwise manually add the module to your library folder by installing the module at:

有些模块需要单独安装到 python 目录的库文件夹中。使用 pip ( https://pip.pypa.io/en/stable/) 对此很有帮助。否则,通过在以下位置安装模块手动将模块添加到您的库文件夹:

https://pypi.python.org/pypi/pandas/0.18.1/

https://pypi.python.org/pypi/pandas/0.18.1/

running the setup through the command line ((pandas location)>setup.py install), and finally adding it to your python directory.

通过命令行运行安装程序 ((pandas location)>setup.py install),最后将其添加到您的 python 目录中。

Hope this helps!

希望这可以帮助!

回答by Tasos Dalis

What worked for me was to make sure that I run the command sudo apt-getso you run as root to make sure I download python3 like below

对我有用的是确保我运行命令,sudo apt-get以便您以 root 身份运行以确保我下载 python3,如下所示

sudo apt-get install python3

The reason you need to use sudoit's because environments such as Ubuntu lock the root automatically according to Wikihow

您需要使用sudo它的原因是因为 Ubuntu 等环境会根据Wikihow自动锁定 root

Then I used

然后我用

sudo apt-get update
sudo apt-get upgrade

And then I used the pip install pandas

然后我用 pip install pandas

That worked for me. I hope that's helpful

那对我有用。我希望这有帮助