简体   繁体   English

从命令提示符运行python脚本时没有模块错误

[英]No module error when running python script from command prompt

I have a python script which is running successfully when i run it from spyder. 我有一个python脚本,当我从spyder运行它时成功运行。 But the same script gives "ImportError: No module named pandas" when run from windows command prompt. 但是,当从Windows命令提示符运行时,相同的脚本会给出“ImportError:没有名为pandas的模块”。

This Q&A mentioned similar problem https://stackoverflow.com/a/10741803/5088142 此问答提到了类似的问题https://stackoverflow.com/a/10741803/5088142

Can you please check which folders are mentioned in Spyder Tools/PYTHONPATH manager? 您能否查看Spyder Tools / PYTHONPATH管理器中提到的文件夹?

Also you can execute the following two lines in Spyder, and identify the location of pandas library: 你也可以在Spyder中执行以下两行,并确定pandas库的位置:

import pandas 
print pandas.__file__

The output should be the path to pandas module Please add this path to Windows path (reference https://docs.python.org/2/using/windows.html ) 输出应该是pandas模块的路径请将此路径添加到Windows路径(参考https://docs.python.org/2/using/windows.html

Python: 蟒蛇:

import sys
sys.path.append('_location_of_python_lib_')

Windows CMD: Windows CMD:

set PYTHONPATH=%PYTHONPATH%;C:\_location_of_python_lib_

Windows: 视窗:

Simply add this path to your PYTHONPATH environment variable. 只需将此路径添加到PYTHONPATH环境变量中即可。 To do this, go to Control Panel / System / Advanced / Environment variable, and in the "User variables" sections, check if you already have PYTHONPATH. 要执行此操作,请转到“控制面板/系统/高级/环境”变量,然后在“用户变量”部分中,检查是否已有PYTHONPATH。 If yes, select it and click "Edit", if not, click "New" to add it. 如果是,请选择它并单击“编辑”,否则,单击“新建”以添加它。 Paths in PYTHONPATH should be separated with ";". PYTHONPATH中的路径应以“;”分隔。

The following link show you how to set environment variable in Windows 7 permanently http://www.nextofwindows.com/how-to-addedit-environment-variables-in-windows-7 以下链接将向您展示如何在Windows 7中永久设置环境变量http://www.nextofwindows.com/how-to-addedit-environment-variables-in-windows-7

You should then install pandas using the windows interpreter. 然后,您应该使用Windows解释器安装pandas。

Open Windows command prompt and type: 打开Windows命令提示符并键入:

pip install pandas

or 要么

easy_install pandas

depending on which package manager you use. 取决于您使用的包管理器。

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

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