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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34573159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 15:11:37  来源:igfitidea点击:

How to install pip3 on my Mac?

pythonpython-3.xpip

提问by user3697597

I'm trying to install pip3, but I'm not having any luck. Also, I tried sudo installand it did not work. How could I install pip3 on my Mac?

我正在尝试安装 pip3,但我没有任何运气。另外,我试过了sudo install,没有用。如何在 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')

回答by aizimmer

You could use home-brew

你可以使用自制的

Then just run:

然后运行:

brew install python3

回答by doru

To install or upgrade pip, download get-pip.pyfrom the official site. Then run the following command:

要安装或升级 pip,官方站点下载get-pip.py。然后运行以下命令:

sudo python get-pip.py 

and it will install pipfor your python version which runs the script.

它将pip为您运行脚本的 python 版本安装。

回答by Itai

Python3 was working successfully but without pip3. Tried many advises from stackoverflow, quora and others. (numerous installs and uninstalls)

Python3 运行成功,但没有 pip3。尝试了来自 stackoverflow、quora 和其他人的许多建议。(无数次安装和卸载)

Python3 was always fine but without pip3. Finally I downloaded Python3 from: https://www.python.org/downloads/

Python3 总是很好,但没有 pip3。最后我从以下位置下载了 Python3:https://www.python.org/downloads/

By simple mouse clicks and everything (Python3 + pip3) is working fine now.

通过简单的鼠标点击,一切(Python3 + pip3)现在都可以正常工作。

回答by Blaszard

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). We will maintain python2, python3 and python@3 aliases.

2018 年 3 月 1 日,python 公式将升级到 Python 3.x,并且将添加 python@2 公式以安装 Python 2.7(尽管这将仅用于桶,因此默认情况下 python 和 python2 都不会添加到 PATH 中手动 brew 链接 --force)。我们将维护 python2、python3 和 python@3 别名。

So to install Python 3, run the following command:

因此,要安装 Python 3,请运行以下命令:

brew install python3

Then, the pipor pip3is 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 python3but also brew postinstall python3

不仅brew install python3而且brew 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 pip3is NOT installed.

请注意,您应该检查控制台,因为它可能会给您带来错误,在这种情况下,未pip3安装。

回答by Oksana Romaniv

For me brew postinstall python3didn't work. Found this solution on GitHub homebrew issues page:

对我来说brew postinstall python3没有用。在 GitHub homebrew 问题页面上找到了这个解决方案:

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

回答by sunu_park

I solved the same problem with these commands:

我用这些命令解决了同样的问题:

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

回答by Dennis Ng

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

回答by tkjef

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

回答by Pay C.

I also encountered the same problem but brew install python3does 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/localto homebrew so it can access them:

将内部权限授予/usr/localhomebrew,以便它可以访问它们:

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

Now ostinstall python3

现在 ostinstall python3

brew postinstall python3

This will give you a successful installation

这将使您安装成功

回答by jvonehr

After upgrading to Mac OS Catalina, and upgrading all my vEnv modules, pip3 stopped working (gave error: "TypeError: 'module' object is not callable").

升级到 Mac OS Catalina 并升级我所有的 vEnv 模块后,pip3 停止工作(给出错误:“TypeError: 'module' object is not callable”)。

Found question 58386953which led to here and solution.

发现问题58386953导致这里和解决方案。

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