如何覆盖对Python3

如何覆盖对Python3

本文介绍了如何覆盖对Python3.x而不是Python2.7的pip命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OSX,并且已经为Python3.5和Python2.7安装了pip.我知道我可以运行命令pip2来使用Python2,并且当我使用命令pip3时将使用Python3.x.问题在于pip的默认设置为Python2.7,而我希望它为Python3.x.

I am using OSX and I have pip installed for both Python3.5 and Python2.7. I know I can run the command pip2 to use Python2 and when I use the command pip3 Python3.x will be used.The problem is that the default of pip is set to Python2.7 and I want it to be Python3.x.

我该如何更改?

不,我还没有运行虚拟环境.如果这是一个虚拟环境,我可以只运行Python3.x并忘记所有关于Python2.7的信息,不幸的是,由于OSX需要使用Python2.7,因此我无法做到这一点.因此,为什么我要问这个.

edit:No, I am not running a virtual environment yet. If it was a virtual environment I could just run Python3.x and forget all about Python2.7, unfortunately since OSX requires Python2.7 for it's use I can't do that. Hence why I'm asking this.

感谢您的回答.但是,我不想更改运行python的功能.相反,我想更改运行pip的路径.目前pip -V向我显示pip 8.1.2 from /Library/Python/2.7/site-packages (python 2.7),但是我正在寻找pip 8.1.2 from /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (python 3.5),我确信必须有一种方法可以做到这一点.有什么想法吗?

Thanks for the answer. I however don't want to change what running python does. Instead I would like to change the path that running pip takes. At the moment pip -V shows me pip 8.1.2 from /Library/Python/2.7/site-packages (python 2.7), but I am looking for pip 8.1.2 from /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (python 3.5) I am sure there has to be a way to do this. Any ideas?

推荐答案

运行此命令:

pip3 install --upgrade --force pip

或更明确:

python3 -m pip install --upgrade --force pip

这将为Python 3安装pip,并使pip的Python 3版本为默认版本.

This will install pip for Python 3 and make Python 3 version of pip default.

验证:

pip -V

这篇关于如何覆盖对Python3.x而不是Python2.7的pip命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 20:30