简体   繁体   English

无法更新 Windows 10 上 pip 的 PATH 变量

[英]Unable to update PATH variable for pip on Windows 10

I know there are thousands of similar topics but my pip command has suddenly stopped to work and, despite all my researchs, I can't figure out why.我知道有成千上万个类似的主题,但我的 pip 命令突然停止工作,尽管我进行了所有研究,但我不知道为什么。 It has been a while since I last used pip and surprisingly my computer doesn't recognize the command anymore.自从我上次使用 pip 已经有一段时间了,令人惊讶的是我的计算机不再识别该命令。 I reinstalled pip and the prompt tells me that the PATH variable is not correctly updated.我重新安装了 pip 并且提示告诉我 PATH 变量没有正确更新。 So I update it but that doesn't solve the problem, the prompt still tells me the PATH variable is not updated.所以我更新了它,但这并没有解决问题,提示仍然告诉我 PATH 变量没有更新。 I've tried uninstalling and reinstalling python and pip and nothing works.我已经尝试卸载并重新安装 python 和 pip 并且没有任何效果。 In my environment variables, I have a user variable named PATH and a system variable named PATH, both of them have the value:在我的环境变量中,我有一个名为 PATH 的用户变量和一个名为 PATH 的系统变量,它们都具有以下值:
C:\Users\mertz\AppData\Local\Programs\Python\Python38\Scripts\

The user variable was already written by itself and I had to write the system variable myself.用户变量已经自己写了,我必须自己写系统变量。

When I'm installing pip I get this warning:当我安装 pip 时,我收到以下警告:

WARNING: The scripts pip.exe, pip3.6.exe and pip3.exe are installed in 'C:\Users\mertz\AppData\Local\Programs\Python\Python36-32\Scripts' which is not on PATH.警告:脚本 pip.exe、pip3.6.exe 和 pip3.exe 安装在不在 PATH 上的“C:\Users\mertz\AppData\Local\Programs\Python\Python36-32\Scripts”中。 Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.考虑将此目录添加到 PATH,或者,如果您希望禁止显示此警告,请使用 --no-warn-script-location。

And when I type pip in the command prompt, it tells me that pip is not recognized.当我在命令提示符下键入 pip 时,它告诉我 pip 无法识别。

What did I do wrong?我做错了什么?

Thanks in advance提前致谢

I had a similar problem, at one time: I could only use administrative privileges to use python cmd or pip easy_install .我曾经遇到过类似的问题:我只能使用管理权限来使用 python cmdpip easy_install

PLEASE follow these procedures:请遵循以下程序:

  1. Get to your environmental variables by pressing window + r and type-in, sysdm.cpl and click ok.通过按window + r并输入sysdm.cpl并单击确定来获取您的环境变量。

  2. Copy the pip link directory to the script folder in python, but first check for pip , pip3 , easy_easy , etc. If it doesn't contain pip , you have to uninstall python and delete the folder, and then reinstall python.将pip链接目录复制到python中的脚本文件夹中,但首先检查pippip3easy_easy等,如果不包含pip ,则必须卸载python并删除文件夹,然后重新安装python。

ie IE

C:\\Users\\mickeymouse\\AppData\\Local\\Programs\\Python\\Python38-32\\Scripts. C:\\Users\\mickeymouse\\AppData\\Local\\Programs\\Python\\Python38-32\\Scripts。

  1. You will see user variables and system variables.您将看到用户变量和系统变量。 (user variables are applied for only that user's account; system variable are applied to all accounts on the pc). (用户变量仅适用于该用户的帐户;系统变量适用于 PC 上的所有帐户)。

Create a path for both, then restart cmd .为两者创建一个路径,然后重新启动cmd

I'm not a specialist in Pip or Python, but I faced a similar problem and used a different procedure.我不是 Pip 或 Python 的专家,但我遇到了类似的问题并使用了不同的程序。

I believe Pip cached directories depend on user permissions during installation and update.我相信 Pip 缓存目录在安装和更新期间取决于用户权限。

At first, the Pip installer defaults to the Python home directory for caching files.首先,Pip 安装程序默认为 Python 主目录用于缓存文件。 If such a directory is unreachable, the installer creates a cached directory inside the current user's home directory.如果这样的目录不可访问,安装程序会在当前用户的主目录中创建一个缓存目录。

Since Python includes Pip by default, the issue reported should not happen at the first install, yet it is due to trying to run the update without administrative privileges.由于 Python 默认包含 Pip,因此报告的问题不应在首次安装时发生,但这是由于尝试在没有管理权限的情况下运行更新所致。

If that is the case, you could try the following steps:如果是这种情况,您可以尝试以下步骤:

  1. Assert the system PATH has proper Python directories assigned, eg:断言系统 PATH 已分配正确的 Python 目录,例如:
  • C:\Program Files\Python310\ for Python executable files; C:\Program Files\Python310\用于 Python 可执行文件;
  • C:\Program Files\Python310\Scripts\ for Python scripts and extensions. C:\Program Files\Python310\Scripts\用于 Python 脚本和扩展。
  1. Remove Pip's registered cached directories using the command py -m pip cache purge.使用命令py -m pip cache purge.

  2. Search for and remove any Pip content outside the Python subdirectory.在 Python 子目录之外搜索并删除任何 Pip 内容。 For example, you could check for contents such as [user home directory]\.pip and [user home directory]\pip.例如,您可以检查[user home directory]\.pip[user home directory]\pip.

  3. Remove Pip references from the system and the user PATH variables.从系统和用户 PATH 变量中删除 Pip 引用。

  4. Open Windows Terminal with administrator privileges and rerun the Pip installer command.以管理员权限打开 Windows 终端并重新运行 Pip 安装程序命令。 You should not use the --no-warn-script-location option, or else you will not be able to see if there is any unexpected behavior.不应使用--no-warn-script-location选项,否则您将无法查看是否有任何意外行为。

Finally, to my knowledge, Pip's documentation lacks a consistent reference for directory options.最后,据我所知,Pip 的文档缺乏对目录选项的一致参考。 Anyway, the following links provided me with some clarity:无论如何,以下链接为我提供了一些清晰度:

Pip general reference: https://pip.pypa.io/en/stable/ Pip 通用参考: https://pip.pypa.io/en/stable/

On Pip caching strategies: https://pip.pypa.io/en/stable/topics/caching/关于 Pip 缓存策略: https://pip.pypa.io/en/stable/topics/caching/

On Pip caching problems, including older versions: https://www.techiediaries.com/python-pip-local-cache/关于Pip缓存问题,包括旧版本: https://www.techiediaries.com/python-pip-local-cache/

All the best!一切顺利!

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

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