我想安装pip。它应该支持Python 3,但它需要setuptools,这只适用于Python 2。
如何在python3中安装pip ?
我想安装pip。它应该支持Python 3,但它需要setuptools,这只适用于Python 2。
如何在python3中安装pip ?
当前回答
如果你使用的是python 3.4+
类型:
python3 -m pip
其他回答
假设你在一个高度受限的计算机环境中(比如我自己),没有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
老版本的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>安装任何包。
这就是我在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
我希望这能有所帮助。
更新2015-01-20:
根据https://pip.pypa.io/en/latest/installing.html,目前的方式是:
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
我认为这适用于任何版本
最初的回答:
wget http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
下面是我在ubuntu 12.04中解决这个问题的方法:
sudo apt-get install build-essential libncursesw5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev
然后从源代码安装python3:
wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tar.xz
tar xvf Python-3.4.0.tar.xz
cd Python-3.4.0
./configure
make
make test
sudo make install
当您完成所有这些程序的安装后,pip3将自动安装。