简体   繁体   English

如何在我的 Mac 上安装 Python 的 pip3?

[英]How can I install Python's pip3 on my Mac?

I'm trying to install pip3, but I'm not having any luck.我正在尝试安装 pip3,但我没有任何运气。 Also, I tried sudo install and it did not work.另外,我试过sudo install但它没有用。 How could I install pip3 on my Mac?如何在我的 Mac 上安装 pip3?

sudo easy_install pip3
Password:
Searching for pip3
Reading https://pypi.python.org/simple/pip3/
Couldn't find index page for 'pip3' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
   
No local packages or download links found for pip3
error: Could not find suitable distribution for Requirement.parse('pip3')

UPDATED - Homebrew version after 1.5更新 - 1.5 之后的 Homebrew 版本

According to the official Homebrew page :根据官方 Homebrew 页面

On 1st March 2018 the python formula will be upgraded to Python 3.x and a python@2 formula will be added for installing Python 2.7 (although this will be keg-only so neither python nor python2 will be added to the PATH by default without a manual brew link --force). 2018 年 3 月 1 日,python 公式将升级到 Python 3.x,并且将添加 python@2 公式以安装 Python 2.7(尽管这将仅用于桶,因此默认情况下 python 和 python2 都不会添加到 PATH 中手动 brew 链接 --force)。 We will maintain python2, python3 and python@3 aliases.我们将维护 python2、python3 和 python@3 别名。

So to install Python 3, run the following command:因此,要安装 Python 3,请运行以下命令:

brew install python3

Then, the pip or pip3 is installed automatically, and you can install any package by pip install <package> .然后, pippip3会自动安装,您可以通过pip install <package>安装任何包。


The older version of Homebrew旧版本的 Homebrew

Not only brew install python3 but also brew postinstall python3不仅brew install python3brew postinstall python3

So you must run:所以你必须运行:

brew install python3
brew postinstall python3

Note that you should check the console, as it might get you errors and in that case, the pip3 is not installed.请注意,您应该检查控制台,因为它可能pip3您带来错误,在这种情况下,安装pip3

You could use Homebrew .你可以使用Homebrew

Then just run:然后运行:

brew install python3

I solved the same problem with these commands:我用这些命令解决了同样的问题:

curl -O https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py

For me brew postinstall python3 didn't work.对我来说brew postinstall python3没有用。 I found this solution on the GitHub Homebrew issues page:我在 GitHub Homebrew问题页面上找到了这个解决方案:

$ brew rm python
$ rm -rf /usr/local/opt/python
$ brew cleanup
$ brew install python3

Python 3 was working successfully, but without pip3. Python 3 运行成功,但没有 pip3。 I tried advice from Stack Overflow, Quora and others (numerous installs and uninstalls).我尝试了 Stack Overflow、Quora 和其他人的建议(多次安装和卸载)。

Python 3 was always fine, but without pip3. Python 3 一直很好,但没有 pip3。 Finally I downloaded Python3 from: https://www.python.org/downloads/最后我从以下位置下载了 Python3: https ://www.python.org/downloads/

By simple mouse clicks and everything (Python 3 + pip3), it is working fine now.通过简单的鼠标点击和一切(Python 3 + pip3),它现在工作正常。

Similar to Oksana but add python3类似于 Oksana 但添加了 python3

$ brew rm python 
$ brew rm python3 
$ rm -rf /usr/local/opt/python
$ rm -rf /usr/local/opt/python3
$ brew prune 
$ brew install python3
$ brew postinstall python3

Seem now work for pip3 under mac os x 10.13.3 Xcode 9.2似乎现在适用于 mac os x 10.13.3 Xcode 9.2 下的 pip3

To install or upgrade pip, download get-pip.py from the official site .要安装或升级 pip,官方站点下载get-pip.py Then run the following command:然后运行以下命令:

sudo python get-pip.py 

and it will install pip for your python version which runs the script.它将为您运行脚本的 python 版本安装pip

I ran the below where <user>:<group> matched the other <user>:<group> for other files in the /usr/local/lib/python3.7/site-packages/ directory:我运行了下面,其中<user>:<group>匹配其他<user>:<group>以获取/usr/local/lib/python3.7/site-packages/目录中的其他文件:

sudo chown -R <user>:<group> /usr/local/lib/python3.7/site-packages/pip*
brew postinstall python3

I also encountered the same problem but brew install python3 does not work properly to install pip3 .我也遇到了同样的问题,但是brew install python3无法正常安装pip3

brre will throw the warning The post-install step did not complete successfully . brre 会抛出警告The post-install step did not complete successfully

It has to do with homebrew does not have permission to /usr/local它与自制软件没有权限有关/usr/local

Create the directory if not exist如果目录不存在则创建

sudo mkdir lib 
sudo mkdir Frameworks

Give the permissions inside /usr/local to homebrew so it can access them:/usr/local的权限授予 homebrew,以便它可以访问它们:

sudo chown -R $(whoami) $(brew --prefix)/*

Now ostinstall python3现在 ostinstall python3

brew postinstall python3

This will give you a successful installation这将使您安装成功

After upgrading to macOS v10.15 (Catalina), and upgrading all my vEnv modules, pip3 stopped working (gave error: "TypeError: 'module' object is not callable").升级到macOS v10.15 (Catalina) 并升级我所有的 vEnv 模块后,pip3 停止工作(给出错误:“TypeError: 'module' object is not callable”)。

I found question 58386953 which led to here and solution.我发现问题 58386953导致这里和解决方案。

  1. Exit from the vEnv (I started a fresh shell)从 vEnv 退出(我启动了一个新的 shell)
  2. sudo python3 -m pip uninstall pip (this is necessary, but it did not fix problem, because it removed the base Python pip, but it didn't touch my vEnv pip) sudo python3 -m pip uninstall pip (这是必要的,但它没有解决问题,因为它删除了基本的 Python pip,但它没有触及我的 vEnv pip)
  3. sudo easy_install pip (reinstalling pip in base Python, not in vEnv) sudo easy_install pip (在基础 Python 中重新安装 pip,而不是在 vEnv 中)
  4. cd to your vEnv/bin and type "source activate" to get into vEnv cd 到你的vEnv/bin并输入“source activate”进入 vEnv
  5. rm pip pip3 pip3.6 (it seems to be the only way to get rid of the bogus pip's in vEnv) rm pip pip3 pip3.6 (这似乎是摆脱 vEnv 中虚假 pip 的唯一方法)
  6. Now pip is gone from vEnv, and we can use the one in the base Python (I wasn't able to successfully install pip into vEnv after deleting)现在 pip 从 vEnv 中消失了,我们可以使用基础 Python 中的那个(删除后我无法将 pip 成功安装到 vEnv 中)

Installing Pip3安装 Pip3

  • Follow this link to download pip3 on your computer按照此链接在您的计算机上下载 pip3
  • Follow the instructions on the page and then after successfully downloading Pip3, run python3 get-pip.py in your terminal按照页面上的说明进行操作,然后在成功下载 Pip3 后,在终端中运行 python3 get-pip.py
  • This will install pip3 into your laptop and then you can check the installation of pip3 by running which pip3 in your terminal.这会将 pip3 安装到您的笔记本电脑中,然后您可以通过在终端中运行 which pip3 来检查 pip3 的安装。

Now simply do pip3 install <package>现在只需执行pip3 install <package>

If you're using Python 3, just execute python3 get-pip.py .如果您使用的是 Python 3,只需执行python3 get-pip.py It is just a simple command.这只是一个简单的命令。

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

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