Python 如何在windows cmd上从pip安装pandas?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42907331/
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
How to install pandas from pip on windows cmd?
提问by Teja
I am trying to install pandas using pip to run some pandas-based Python programs. I already installed pip. I tried googling and SO'ing but didn't find a solution to this error. Can somebody share your inputs on this?
我正在尝试使用 pip 安装 Pandas 来运行一些基于 Pandas 的 Python 程序。我已经安装了pip。我尝试使用谷歌搜索和 SO'ing 但没有找到解决此错误的方法。有人可以分享您对此的意见吗?
C:\> pip install pandas
Error:
错误:
pip is not recognized as an internal or external command, operable program or batch file.
回答by abccd
Since both pip
nor python
commands are not installed along Python in Windows, you will need to use the Windows alternative py
, which is included by default when you installed Python. Then you have the option to specify a general or specific version number after the py
command.
由于Windows 中未随 Python 安装pip
norpython
命令,因此您需要使用 Windows 替代项py
,安装 Python 时默认包含该替代项。然后您可以选择在py
命令后指定通用或特定版本号。
C:\> py -m pip install pandas %= one of Python on the system =%
C:\> py -2 -m pip install pandas %= one of Python 2 on the system =%
C:\> py -2.7 -m pip install pandas %= only for Python 2.7 =%
C:\> py -3 -m pip install pandas %= one of Python 3 on the system =%
C:\> py -3.6 -m pip install pandas %= only for Python 3.6 =%
Alternatively, in order to get pip
to work without py -m
part, you will need to add pip to the PATH environment variable.
或者,为了在pip
没有py -m
部分的情况下开始工作,您需要将 pip 添加到 PATH 环境变量。
C:\> setx PATH "%PATH%;C:\<path\to\python\folder>\Scripts"
Now you can run the following command as expected.
现在您可以按预期运行以下命令。
C:\> pip install pandas
Troubleshooting:
故障排除:
Problem:
问题:
connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
Solution:
解决方案:
This is caused by your SSL certificate is unable to verify the host server. You can add pypi.python.org to the trusted host or specify an alternative SSL certificate. For more information, please see this post. (Thanks to Anuj Varshney for suggesting this)
这是由于您的 SSL 证书无法验证主机服务器造成的。您可以将 pypi.python.org 添加到受信任的主机或指定替代 SSL 证书。有关更多信息,请参阅此帖子。(感谢 Anuj Varshney 提出这个建议)
C:\> py -m pip install --trusted-host pypi.python.org pip pandas
Problem:
问题:
PermissionError: [WinError 5] Access is denied
Solution:
解决方案:
This is a caused by when you don't permission to modifythe Python site-package folders. You can avoid this with one of the following methods:
这是由您无权修改Python 站点包文件夹引起的。您可以使用以下方法之一来避免这种情况:
Run Windows Command Prompt as administrator (thanks to DataGirl's suggestion) by:
+ Rto open run
- type in
cmd.exe
in the search box - CTRL+ SHIFT+ ENTER
- An alternative method for step 1-3 would be to manually locate cmd.exe, right click, then click Run as Administrator.
Run pip in user modeby adding
--user
option when installing with pip. Which typically install the package to the local %APPDATA% Python folder.
通过以下方式以管理员身份运行 Windows 命令提示符(感谢 DataGirl 的建议):
+R打开运行
- 键入
cmd.exe
在搜索框中 - CTRL+ SHIFT+ENTER
- 步骤 1-3 的另一种方法是手动找到 cmd.exe,右键单击,然后单击以管理员身份运行。
通过在使用 pip 安装时添加选项在用户模式下运行
--user
pip。通常将包安装到本地 %APPDATA% Python 文件夹。
C:\> py -m pip install --user pandas
- Create a virtual environment.
- 创建虚拟环境。
C:\> py -m venv c:\path\to\new\venv
C:\> <path\to\the\new\venv>\Scripts\activate.bat
回答by Rahul Yadav
In my opinion, the issue is because the environment variable is not set up to recognize pip as a valid command.
在我看来,问题是因为环境变量没有设置为将 pip 识别为有效命令。
In general, the pip in Python is at this location:
一般来说,Python中的pip在这个位置:
C:\Users\user\AppData\Local\Programs\Python\Python36\Scripts > pip
So all we need to do is go to Computer Name> Right Click > Advanced System Settings > Select Env Variable then under system variables > reach to Path> Edit path and add the Path by separating this path by putting a semicolon after the last path already was in the Env Variable.
所以我们需要做的就是转到计算机名称>右键单击>高级系统设置>选择环境变量,然后在系统变量下>到达路径>编辑路径并通过在最后一个路径后面放置一个分号来分隔此路径来添加路径在环境变量中。
Now run Python shell, and this should work.
现在运行 Python shell,这应该可以工作。
回答by Raj
Assuming you are using Windows OS.
假设您使用的是 Windows 操作系统。
All you need to add the pip.exe
path to the Environment Variables (Path).
所有您需要将pip.exe
路径添加到环境变量 (Path)。
Generally, you can find it under ..Python\Scripts folder.
一般来说,你可以在下面找到它 ..Python\Scripts folder.
For me it is, C:\Program Files\Python36\Scripts\
对我来说是, C:\Program Files\Python36\Scripts\
回答by inhoser
Reply to abccd and Question to anyone:
回复 abccd 和任何人的问题:
The command: C:\Python34\Scripts>py -3 -m pip install pandas
executed just fine. Unfortunately, I can't import Pandas.
命令:C:\Python34\Scripts>py -3 -m pip install pandas
执行得很好。不幸的是,我无法导入 Pandas。
Directory path: C:\users\myname\downloads\miniconda3\lib\site-packages
目录路径: C:\users\myname\downloads\miniconda3\lib\site-packages
My Question: How is it that Pandas' dependency packages(numpy, python-dateutil, pytz, six) also having the same above directory path are able to import just fine but Pandas does not?
我的问题:Pandas 的依赖包(numpy、python-dateutil、pytz、6 个)也具有上述相同的目录路径,如何能够很好地导入而 Pandas 却不能?
import pandas
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
import pandas
ImportError: No module named 'pandas'
I finally got Pandas reinstalled and imported with the help of the following web pages: *http://pandas.pydata.org/pandas-docs/stable/pandas.pdf(Pages 403 and 404 of 2215 ... 2.2.2 Installing Pandas with Miniconda) *https://conda.io/docs/user-guide/install/download.html*https://conda.io/docs/user-guide/getting-started.html
我终于在以下网页的帮助下重新安装并导入了 Pandas: * http://pandas.pydata.org/pandas-docs/stable/pandas.pdf(2215 年的第 403 和 404 页 ... 2.2.2 安装带有 Miniconda 的 Pandas) * https://conda.io/docs/user-guide/install/download.html* https://conda.io/docs/user-guide/getting-started.html
After installing Miniconda, I created a new environment area to get Pandas reinstalled and imported. This new environment included the current Python version 3.6.3. I could not import Pandas using Python 3.4.4.
安装 Miniconda 后,我创建了一个新的环境区域来重新安装和导入 Pandas。这个新环境包括当前的 Python 版本 3.6.3。我无法使用 Python 3.4.4 导入 Pandas。
回答by Hilmi Reda
Please Ensure you are using a virtualEnv this is how :
请确保您使用的是 virtualEnv,方法如下:
virtualenv -p python3 envname
source env/bin/activate
pip install pandas
on windows you have to add scripts exe in the CLASSPATH in order to use pip command
在 Windows 上,您必须在 CLASSPATH 中添加脚本 exe 才能使用 pip 命令
C:\Python34\Scripts\pip3.exe
i suggest you to use MINGW he can gives you a better environment to work with python
我建议你使用 MINGW 他可以给你一个更好的环境来使用 python
回答by Ajay Singh
install pip, securely download get-pip.py
安装pip,安全下载get-pip.py
Then run the following:
然后运行以下命令:
python get-pip.py
python get-pip.py
On Windows, to get Pandas running,follow the step given in following link
在 Windows 上,要运行 Pandas,请按照以下链接中给出的步骤操作
https://github.com/svaksha/PyData-Workshop-Sprint/wiki/windows-install-pandas
https://github.com/svaksha/PyData-Workshop-Sprint/wiki/windows-install-pandas
回答by Arslan Ahmad
回答by Jyoti
pip install pandas make sure, this is 'pandas' not 'panda'
pip install pandas 确保这是“熊猫”而不是“熊猫”
If you are not able to access pip, then got to C:\Python37\Scripts and run pip.exe install pandas.
如果您无法访问 pip,请转到 C:\Python37\Scripts 并运行 pip.exe install pandas。
Alternatively, you can add C:\Python37\Scripts in the env variables for windows machines. Hope this helps.
或者,您可以在 Windows 机器的 env 变量中添加 C:\Python37\Scripts。希望这可以帮助。