我想安装pip。它应该支持Python 3,但它需要setuptools,这只适用于Python 2。

如何在python3中安装pip ?


当前回答

我可以通过运行sudo apt-get install python3-pip在Ubuntu上为python3安装pip。

其他回答

老版本的Homebrew

如果你使用的是macOS系统,请使用自制软件。

brew install python3 # this installs python only
brew postinstall python3 # this command installs pip

还要注意,如果安装成功完成,您应该检查控制台。有时它不会(例如,由于所有权导致的错误),但人们只是忽略了日志。


更新- 1.5之后的自制版本

Homebrew官方页面显示:

2018年3月1日,python公式将升级到python 3。x和一个python@2公式将用于安装Python 2.7(尽管这将是keg-only,因此Python和python2在默认情况下都不会被添加到PATH中,除非手动酿造链接——force)。我们将维护python2、python3和python@3别名。

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

brew install python3

然后自动安装pip,您可以通过pip install <package>安装任何包。

请按照以下步骤安装python 3和pip:

步骤1:从这里下载安装Python

步骤2:需要下载get-pip.py

步骤3:下载get-pip.py后,打开命令提示符并进入保存get-pip.py文件的目录。

第四步:在cmd下输入命令python get-pip.py。

步骤5:Pip installed successfully, Verify Pip installation by type command in cmd Pip——version

假设你在一个高度受限的计算机环境中(比如我自己),没有root权限或安装包的能力……

在这篇文章之前,我从来没有设置过Python+virtualenv的新/独立/原始/非根实例。为了做到这一点,我在谷歌上搜索了很多。

Decide if you are using python (python2) or python3 and set your PATH correctly. (I am strictly a python3 user.) All commands below can substitute python3 for python if you are python2 user. wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-x.y.z.tar.gz tar -xzvf virtualenv-x.y.z.tar.gz python3 virtualenv-x.y.z/virtualenv.py --python $(which python3) /path/to/new/virtualenv source /path/to/new/virtualenv/bin/activate Assumes you are using a Bourne-compatible shell, e.g., bash Brilliantly, this virtualenv package includes a standalone version of pip and setuptools that are auto-magically installed into each new virtualenv. This solves the chicken and egg problem. You may want to create an alias (or update your ~/.bashrc, etc.) for this final command to activate the python virtualenv during each login. It can be a pain to remember all these paths and commands. Check your version of python now: which python3 should give: /path/to/new/virtualenv/bin/python3 Check pip is also available in the virtualenv via which pip... should give: /path/to/new/virtualenv/bin/pip

然后……皮皮,皮皮,皮皮!

给python新手的最后一个提示:在开始时,您认为不需要virtualenv,但以后会很高兴拥有它。帮助开源/共享包的“假设”安装/升级场景。

裁判:https://virtualenv.pypa.io/en/latest/installation.html

这就是我在OS X Mavericks上所做的工作。

首先,安装brew

安装python 3.4

brew install python3

然后我得到最新版本的分发:

wget https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip#md5=c6c59594a7b180af57af8a0cc0cf5b4a

unzip distribute-0.7.3.zip
cd distribute-0.7.3
sudo setup.py install
sudo easy_install-3.4 pip
sudo pip3.4 install virtualenv
sudo pip3.4 install virtualenvwrapper

mkvirtualenv py3 

python --version
Python 3.4.1

我希望这能有所帮助。

系统中单个Python

要在Python中安装包,请遵循以下步骤:

如果该包用于python 2。X: sudo python -m PIP install [package] 如果该包用于python 3。X: sudo python3 -m PIP install [package]

注意:这是假设python没有设置别名

通过这种方法,不会混淆哪个python版本正在接收包。

多个python /虚拟环境

比如有python3↔python3.6和python3.7↔python3.7

安装python3.6: sudo python3 -m pip install [package] 安装python3.7: sudo python3.7 -m pip install [package]

这本质上与前面所示的方法相同。

注1

如何找到哪条蟒蛇?做以下其中一件事:

~ » python3 -c "import sys; print(sys.version)"
3.9.5 (default, Nov 18 2021, 16:00:48)

你的python3命令生成:

~ » python3
Python 3.9.5 (default, Nov 18 2021, 16:00:48) 
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

注意第二行中的python 3.9.5。

或者说你正在使用虚拟环境,看看你的python指向哪里:

» which python
/home/ganesh/os/np-test/bin/python

注2

更改python3或python指向的内容:https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3