由于pip 和python 命令都没有在 Windows 中随 Python 一起安装,因此您需要使用 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 =%
或者,为了让pip 在没有py -m 部分的情况下工作,您需要add pip to the PATH environment variable。
C:\> setx PATH "%PATH%;C:\<path\to\python\folder>\Scripts"
现在您可以按预期运行以下命令了。
C:\> pip install pandas
疑难解答:
问题:
connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
解决办法:
这是由于您的 SSL 证书无法验证主机服务器造成的。您可以将 pypi.python.org 添加到受信任的主机或指定备用 SSL 证书。如需更多信息,请参阅此post。 (感谢 Anuj Varshney 的建议)
C:\> py -m pip install --trusted-host pypi.python.org pip pandas
问题:
PermissionError: [WinError 5] Access is denied
解决办法:
这是由于您没有permission to modify 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