简体   繁体   English

Python3问题的PIP安装:考虑将这个目录添加到PATH

[英]PIP installation for Python3 problem: Consider adding this directory to PATH

I tried to install pip in python $ python get-pip.py through terminal but had this warning in Terminal.我试图通过终端在python $ python get-pip.py中安装pip ,但在终端中出现了这个警告。

Python3.8 Python3.8
MacOS Catalina MacOS 卡特琳娜

Please help:(. I have been trying to search for answers for days请帮助:(。我这几天一直在寻找答案

WARNING: The scripts pip, pip3 and pip3.8 are installed in '/Library/Frameworks/Python.framework/Versions/3.8/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

You are getting this error because of the absence of the location that pip is installed from your PATH.您收到此错误是因为缺少从您的 PATH 安装 pip 的位置。

You need add:您需要添加:

export PATH="$PATH:/Library/Frameworks/Python.framework/Versions/3.8/bin"

to the end of your .bash_profile , like @hoefling commented.到你的.bash_profile结尾,就像@hoefling 评论的那样。

As of March 2022, under macOS Monterey 12.2.1, I had to use a different PATH change to reach pip :截至 2022 年 3 月,在 macOS Monterey 12.2.1 下,我不得不使用不同的 PATH 更改来访问pip

export PATH="$PATH:/Users/<username>/Library/Python/3.8/bin"

Notes:笔记:

  1. My python installation is not at /Library/ but rather at ~/Library/ , possibly because it arrived via brew - or that Monterey uses a different location.我的 python 安装不在/Library/而是在~/Library/ ,可能是因为它是通过brew到达的 - 或者 Monterey 使用不同的位置。
  2. $PATH does not seem to tolerate ~/ - so one rather has to use /Users/<username>/... in at least this case. $PATH 似乎不能容忍~/ - 所以至少在这种情况下必须使用/Users/<username>/...
  3. I think it's better to append rather than to prepend the updated path, because by default one might want/expect the system's main paths ( /usr/bin etc.) to take precedence.我认为最好附加而不是预先添加更新的路径,因为默认情况下可能希望/期望系统的主要路径( /usr/bin等)优先。 On the other hand, installing eg python to those main paths will also take precedence over any python setup that depends on the updated path and could therefore damage it.另一方面,将 python 安装到这些主要路径也将优先于依赖于更新路径的任何 python 安装,因此可能会损坏它。 Choose your poison.选择你的毒药。
  4. This answer is not the same as the currently-top answer because (i) the required path is different for me and (ii) the OS version is different.这个答案与当前最佳答案不同,因为 (i) 所需的路径对我来说不同,并且 (ii) 操作系统版本不同。

You need to add to your .bash_profile or .zshrc in your system root directory:您需要在系统根目录中添加.bash_profile.zshrc

export PATH=/Library/Frameworks/Python.framework/Versions/3.9/bin:$PATH

If you are on a Raspberry Pi (Raspbian OS) then do the following:如果您使用的是 Raspberry Pi(Raspbian OS),请执行以下操作:

nano /home/pi/.profile

At the end of the file add:在文件末尾添加:

# set PATH to pip
PATH="$HOME/pi/.local/bin:$PATH"

Ctrl+X, Y, Enter <-- to save changes on the.profile file Ctrl+X, Y, Enter <-- 保存对.profile文件的更改

Then reboot your Raspberry Pi to apply changes.然后重新启动您的 Raspberry Pi 以应用更改。

You can check now with pip --version您现在可以使用pip --version检查

I am using Ubuntu and the following worked for me:我正在使用 Ubuntu,以下对我有用:

sudo nano ~/.bashrc # to open the .bashrc file

Then Ctrl+End #to reach the end of the file.然后Ctrl+End #到达文件末尾。

On a new line, put the following line:在新的一行中,放置以下行:

export PATH=$PATH:/home/$USER/.local/bin

Save changes and finally logout and login again to make this work保存更改,最后注销并再次登录以完成这项工作

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

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