简体   繁体   English

如何在 Windows cmd 上从 pip 安装熊猫?

[英]How to install pandas from pip on windows cmd?

I am trying to install pandas using pip to run some pandas-based Python programs.我正在尝试使用 pip 安装熊猫来运行一些基于熊猫的 Python 程序。 I already installed pip.我已经安装了点子。 I tried googling and SO'ing but didn't find a solution to this error.我尝试了谷歌搜索和 SO'ing,但没有找到解决此错误的方法。 Can somebody share your inputs on this?有人可以分享您对此的意见吗?

C:\> pip install pandas

Error:错误:

pip is not recognized as an internal or external command, operable program or batch file.

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.由于pippython命令都没有在 Windows 中随 Python 一起安装,因此您需要使用 Windows 替代py ,它在安装 Python 时默认包含。 Then you have the option to specify a general or specific version number after the py command.然后,您可以选择在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.这是由于您的 SSL 证书无法验证主机服务器造成的。 You can add pypi.python.org to the trusted host or specify an alternative SSL certificate.您可以将 pypi.python.org 添加到受信任的主机或指定备用 SSL 证书。 For more information, please see this post .有关更多信息,请参阅此帖子 (Thanks to Anuj Varshney for suggesting this) (感谢 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 modify the Python site-package folders.这是由于您无权修改Python 站点包文件夹引起的。 You can avoid this with one of the following methods:您可以通过以下方法之一避免这种情况:

  • Run Windows Command Prompt as administrator (thanks to DataGirl's suggestion) by:通过以下方式以管理员身份运行 Windows 命令提示符(感谢 DataGirl 的建议):

    1. Windows键 + R to open run + R打开运行
    2. type in cmd.exe in the search box在搜索框中输入cmd.exe
    3. CTRL + SHIFT + ENTER CTRL + SHIFT + ENTER
    4. An alternative method for step 1-3 would be to manually locate cmd.exe, right click, then click Run as Administrator.步骤 1-3 的另一种方法是手动找到 cmd.exe,右键单击,然后单击以管理员身份运行。
  • Run pip in user mode by adding --user option when installing with pip.使用 pip 安装时,通过添加--user选项在用户模式下运行 pip。 Which typically install the package to the local %APPDATA% Python folder.通常将包安装到本地 %APPDATA% Python 文件夹。

C:\> py -m pip install --user pandas
C:\> py -m venv c:\path\to\new\venv
C:\> <path\to\the\new\venv>\Scripts\activate.bat

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,这应该可以工作。

Assuming you are using Windows OS.假设您使用的是 Windows 操作系统。

All you need to add the pip.exe path to the Environment Variables (Path).您只需将pip.exe路径添加到环境变量(路径)。

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\

Reply to abccd and Question to anyone:回复 abccd 和向任何人提问:

The command: C:\Python34\Scripts>py -3 -m pip install pandas executed just fine.命令: C:\Python34\Scripts>py -3 -m pip install pandas执行得很好。 Unfortunately, I can't import 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 的熊猫)* 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.安装 Miniconda 后,我创建了一个新的环境区域来重新安装和导入 Pandas。 This new environment included the current Python version 3.6.3.这个新环境包括当前的 Python 版本 3.6.3。 I could not import Pandas using Python 3.4.4.我无法使用 Python 3.4.4 导入 Pandas。

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

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

If you are a windows user:如果您是 Windows 用户:
make sure you added the script(dir) path to environment variables确保将脚本(dir)路径添加到环境变量
C:\Python34\Scripts C:\Python34\脚本
for more how to set path vist有关如何设置路径访问的更多信息

pip install pandas make sure, this is 'pandas' not 'panda' pip install pandas 确保这是“pandas”而不是“panda”

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.或者,您可以在 Windows 机器的环境变量中添加 C:\Python37\Scripts。 Hope this helps.希望这可以帮助。

在 Python 目录中使用pip install pandaspython -m pip install pandas

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

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