如何使用 Python 3 安装 pip?

发布于 2024-11-18 20:25:04 字数 159 浏览 3 评论 0 原文

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

如何使用Python 3安装pip?

I want to install pip. It should support Python 3, but it requires setuptools, which is available only for Python 2.

How can I install pip with Python 3?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(23

木落 2024-11-25 20:25:05

旧版本的 Homebrew

如果您使用的是 macOS,请使用 homebrew

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

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


更新 - 1.5 之后的 Homebrew 版本

根据 官方 Homebrew 页面

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

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

brew install python3

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

Older version of Homebrew

If you are on macOS, use homebrew.

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

Also note that you should check the console if the install finished successfully. Sometimes it doesn't (e.g. an error due to ownership), but people simply overlook the log.


UPDATED - Homebrew version after 1.5

According to the official Homebrew page:

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.

So to install Python 3, run the following command:

brew install python3

Then, the pip is installed automatically, and you can install any package by pip install <package>.

欲拥i 2024-11-25 20:25:05

这是我复制并粘贴的一行:

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

备用:

curl -L get-pip.io | python3

来自 使用 get-pip.py 安装

要安装 pip,请通过以下链接安全下载 get-pip.py
get-pip.py。或者,使用
卷曲:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

然后在下载的文件夹中运行以下命令
获取 pip.py:

python get-pip.py

警告:如果您使用托管的 Python 安装,请务必小心
由您的操作系统或其他包管理器。 get-pip.py 确实
不与这些工具协调,可能会使您的系统陷入困境
状态不一致。

This is the one-liner I copy-and-paste:

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

Alternate:

curl -L get-pip.io | python3

From Installing with get-pip.py:

To install pip, securely download get-pip.py by following this link:
get-pip.py. Alternatively, use
curl:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Then run the following command in the folder where you have downloaded
get-pip.py:

python get-pip.py

Warning: Be cautious if you are using a Python install that is managed
by your operating system or another package manager. get-pip.py does
not coordinate with those tools, and may leave your system in an
inconsistent state.

放血 2024-11-25 20:25:05

如果您的 Linux 发行版已经安装了 Python,您应该能够使用系统的包管理器安装 PIP。这是更好的选择,因为系统安装的 Python 版本不能很好地与 Windows 和 Mac 上使用的 get-pip.py 脚本配合使用。

高级软件包工具 (Python 2.x)

sudo apt-get install python-pip

高级软件包工具 (Python 3.x)

sudo apt-get install python3-pip

pacman 软件包管理器

sudo pacman -S python2-pip

(Python 2.x) pacman 软件包管理器 (Python 3.x)

sudo pacman -S python-pip

Yum 软件包管理器 (Python 2.x)

sudo yum upgrade python-setuptools
sudo yum install python-pip python-wheel

Yum 软件包管理器 (Python) 3.x)

sudo yum install python3 python3-wheel

Dandified Yum (Python 2.x)

sudo dnf upgrade python-setuptools
sudo dnf install python-pip python-wheel

Dandified Yum (Python 3.x)

sudo dnf install python3 python3-wheel

Zypper 包管理器 (Python 2.x)

sudo zypper install python-pip python-setuptools python-wheel

Zypper 包管理器 (Python 3.x)

sudo zypper install python3-pip python3-setuptools python3-wheel

If your Linux distro came with Python already installed, you should be able to install PIP using your system’s package manager. This is preferable since system-installed versions of Python do not play nicely with the get-pip.py script used on Windows and Mac.

Advanced Package Tool (Python 2.x)

sudo apt-get install python-pip

Advanced Package Tool (Python 3.x)

sudo apt-get install python3-pip

pacman Package Manager (Python 2.x)

sudo pacman -S python2-pip

pacman Package Manager (Python 3.x)

sudo pacman -S python-pip

Yum Package Manager (Python 2.x)

sudo yum upgrade python-setuptools
sudo yum install python-pip python-wheel

Yum Package Manager (Python 3.x)

sudo yum install python3 python3-wheel

Dandified Yum (Python 2.x)

sudo dnf upgrade python-setuptools
sudo dnf install python-pip python-wheel

Dandified Yum (Python 3.x)

sudo dnf install python3 python3-wheel

Zypper Package Manager (Python 2.x)

sudo zypper install python-pip python-setuptools python-wheel

Zypper Package Manager (Python 3.x)

sudo zypper install python3-pip python3-setuptools python3-wheel
千仐 2024-11-25 20:25:05

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

第 1 步:从在此处下载安装 Python a>

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

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

步骤4:在cmd中输入命令python get-pip.py

第5步:pip安装成功,在cmd中输入命令pip --version验证pip安装

Please follow below steps to install python 3 with pip:

Step 1 : Install Python from download here

Step 2 : you’ll need to download get-pip.py

Step 3 : After download get-pip.py , open your commant prompt and go to directory where your get-pip.py file saved .

Step 4 : Enter command python get-pip.py in cmd.

Step 5 : Pip installed successfully , Verify pip installation by type command in cmd pip --version

一梦浮鱼 2024-11-25 20:25:05

如果您使用多个不同版本的 python,请尝试使用 virtualenv http ://www.virtualenv.org/en/latest/virtualenv.html#installation

利用pip针对每个本地环境的优势。

然后安装本地当前环境下目录:

virtualenv -p /usr/local/bin/python3.3 ENV --verbose

请注意,您指定了系统上安装的 python 二进制文件的路径。

然后,该文件夹中现在就有一个本地 python 环境。 ./ENV

现在应该有 ./ENV/pip-3.3

使用
./ENV/pip-3.3 freeze 以列出本地安装的库。

使用 ./ENV/pip-3.3 install packagename 在本地环境安装。

使用 ./ENV/python3.3 pythonfile.py 运行 python 脚本。

If you use several different versions of python try using virtualenv http://www.virtualenv.org/en/latest/virtualenv.html#installation

With the advantage of pip for each local environment.

Then install a local environment in the current directory by:

virtualenv -p /usr/local/bin/python3.3 ENV --verbose

Note that you specify the path to a python binary you have installed on your system.

Then there are now an local pythonenvironment in that folder. ./ENV

Now there should be ./ENV/pip-3.3

use
./ENV/pip-3.3 freeze to list the local installed libraries.

use ./ENV/pip-3.3 install packagename to install at the local environment.

use ./ENV/python3.3 pythonfile.py to run your python script.

小清晰的声音 2024-11-25 20:25:05

这是我在 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 将自动安装。

Here is my way to solve this problem at ubuntu 12.04:

sudo apt-get install build-essential libncursesw5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev

Then install the python3 from source code:

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

When you finished installing all of them, pip3 will get installed automatically.

贵在坚持 2024-11-25 20:25:05

这就是我在 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

我希望这有帮助。

This is what I did on OS X Mavericks to get this to work.

Firstly, have brew installed

Install python 3.4

brew install python3

Then I get the latest version of distribute:

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

I hope this helps.

淡墨 2024-11-25 20:25:05

如果您使用命令“python get-pip.py”,您应该具有Python3的“pip”功能。但是,Python2 的“pip”可能仍然存在。就我而言,我卸载了“pip”,从而将其从 Python2 中删除。

之后我再次运行“python get-pip.py”。 (确保“get-pip.py”保存在与 Python3 相同的文件夹中。)最后一步是将带有“pip”命令的目录添加到 $PATH。这为我解决了。

If you used the command "python get-pip.py", you should have the 'pip' function for Python3. However, 'pip' for Python2 might still be present. In my case I uninstalled 'pip', which removed it from Python2.

After that I ran "python get-pip.py" again. (Make sure that 'get-pip.py' is saved in the same folder as Python3.) The final step was to add the directory with 'pip' command to $PATH. That solved it for me.

美人如玉 2024-11-25 20:25:05

对于 python3 试试这个:

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python

好处是它还会检测您拥有的 python 版本(即使它是您自定义位置中的 python 环境)。
之后,您可以正常使用(例如)

pip install numpy

源:
https://pypi.python.org/pypi /setuptools/1.1.6#upgrading-from-setuptools-0-6

For python3 try this:

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python

The good thing is that It will also detect what version of python you have (even if it's an environment of python in your custom location).
After this you can proceed normally with (for example)

pip install numpy

source:
https://pypi.python.org/pypi/setuptools/1.1.6#upgrading-from-setuptools-0-6

蒗幽 2024-11-25 20:25:05

假设您处于高度受限的计算机环境中(例如我自己),没有 root 访问权限或安装软件包的能力...

在这篇文章之前,我从未设置过 Python+virtualenv 的新/独立/原始/非 root 实例。我做了很多谷歌搜索才能完成这项工作。

  1. 确定您使用的是 python (python2) 还是 python3 并正确设置 PATH。 (我严格来说是一个 python3 用户。)如果您是 python2 用户,下面的所有命令都可以用 python3 替换 python
  2. wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-xyztar.gz
  3. tar -xzvf virtualenv-xyztar.gz
  4. python3 virtualenv-xyz/virtualenv.py --python $(which python3) /path/to/new/virtualenv
  5. 源/path/to/new/virtualenv/bin/activate
    • 假设您使用的是 Bourne 兼容的 shell,例如 bash
    • 出色的是,这个virtualenv软件包包含独立版本的pipsetuptools,它们会自动安装到每个新的virtualenv中。这就解决了先有鸡还是先有蛋的问题。
    • 您可能需要为这个最终命令创建一个别名(或更新您的 ~/.bashrc 等),以便在每次登录期间激活 python virtualenv。记住所有这些路径和命令可能会很痛苦。
  6. 现在检查您的 python 版本: which python3 应该给出: /path/to/new/virtualenv/bin/python3
  7. 检查 pip 是否也可用在 virtualenv 中通过 which pip... 应该给出: /path/to/new/virtualenv/bin/pip

然后... pip,pip,pip!

给 Python 新手的最后提示:刚开始时你并不认为需要 virtualenv,但稍后你会很高兴拥有它。帮助解决开源/共享包的“假设”安装/升级方案。

参考:https://virtualenv.pypa.io/en/latest/installation.html

Assuming you are in a highly restricted computer env (such as myself) without root access or ability to install packages...

I had never setup a fresh/standalone/raw/non-root instance of Python+virtualenv before this post. I had do quite a bit of Googling to make this work.

  1. 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.
  2. wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-x.y.z.tar.gz
  3. tar -xzvf virtualenv-x.y.z.tar.gz
  4. python3 virtualenv-x.y.z/virtualenv.py --python $(which python3) /path/to/new/virtualenv
  5. 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.
  6. Check your version of python now: which python3 should give: /path/to/new/virtualenv/bin/python3
  7. Check pip is also available in the virtualenv via which pip... should give: /path/to/new/virtualenv/bin/pip

Then... pip, pip, pip!

Final tip to newbie Pythoneers: You don't think you need virtualenv when you start, but you will be happy to have it later. Helps with "what if" installation / upgrade scenarios for open source / shared packages.

Ref: https://virtualenv.pypa.io/en/latest/installation.html

终止放荡 2024-11-25 20:25:05

要安装 pip,请安全下载 get-pip.py

然后运行以下命令:

python get-pip.py

如果您使用的是由您的管理员管理的 Python 安装,请务必小心
操作系统或其他包管理器。 get-pip.py 没有
与这些工具协调,可能会让您的系统处于
状态不一致。

参考:PIP安装

To install pip, securely download get-pip.py.

Then run the following:

python get-pip.py

Be cautious if you're using a Python install that's managed by your
operating system or another package manager. get-pip.py does not
coordinate with those tools, and may leave your system in an
inconsistent state.

Refer: PIP Installation

淡笑忘祈一世凡恋 2024-11-25 20:25:05

Python 3.4 的新增功能

...

pip 应始终可用

...

默认情况下,命令 pipX 和 pipX.Y 将安装在所有平台上(其中 XY 代表 Python 安装的版本),以及 pip Python 包及其依赖项。

https://docs.python.org/3/whatsnew/ 3.4.html#whatsnew-pep-453

所以如果你安装了 python 3.4,你可以: sudo pip3 install xxx

What’s New In Python 3.4

...

pip should always be available

...

By default, the commands pipX and pipX.Y will be installed on all platforms (where X.Y stands for the version of the Python installation), along with the pip Python package and its dependencies.

https://docs.python.org/3/whatsnew/3.4.html#whatsnew-pep-453

so if you have python 3.4 installed, you can just: sudo pip3 install xxx

灵芸 2024-11-25 20:25:05

对于Windows 8.1/10操作系统用户,只需打开 cmd(命令提示符)

编写:C:\Users\%USERNAME%\AppData\Local\Programs\ Python\Python36-32\Scripts

然后

只需编写以下内容:pip3 install {包名}

提示:文件夹的位置对于新的 python 3.x 版本,Python36-32 可能会有所不同

And for Windows 8.1/10 OS Users just open cmd (command prompt)

write this : C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python36-32\Scripts

then

just write this : pip3 install {name of package}

Hint: the location of folder Python36-32 may get different for new python 3.x versions

四叶草在未来唯美盛开 2024-11-25 20:25:05

pip 是在安装 Python 时一起安装的。你可以使用
sudo pip install(模块)
或者
python3 -m pip install(模块)

pip is installed together when you install Python. You can use
sudo pip install (module)
or
python3 -m pip install (module).

柏拉图鍀咏恒 2024-11-25 20:25:05

=>在 Ubuntu 18.04 或 Ubuntu 20.04 上安装 Python 任何版本的简单方法请按照以下步骤操作:-

步骤 1:更新本地存储库:-

sudo apt update

步骤 2:安装支持软件:-

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

步骤 3:在主目录上创建目录 要下载最新版本的 Python 源代码,请导航到 /python-source-files 目录并使用 wget 命令:-

mkdir python-source -files

步骤 4:下载最新版本的 Python 源代码:-

wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz

“你可以改变python 版本只需修改此:-“3.7.5”与您想要的版本示例:-“3.5.2”

步骤 5:提取压缩文件:-

tar –xf Python-3.7.5.tgz
或者
tar xvzf Python-3.7.5.tgz

第 6 步:测试系统并优化 Python:-

cd python-3.7.5 或您的 Python 版本。

第 7 步:现在配置(使用 ––optimization 选项将代码执行速度提高 10-20%。):-

./configure ––enable–optimizations

或者,如果您面对 ssl,您也可以执行此操作错误:-

./configure --with-openssl

步骤 8:安装第二个 Python 实例:-

sudo make altinstall

“建议您使用altinstall 方法。您的 Ubuntu 系统可能有依赖于 Python 2.x 的软件包,

或者

如果您想覆盖默认的 Python 安装/版本:-

sudo make install"

步骤 9:现在检查 Python 版本: -

python3 ––version

第 10 步:要为 python3 安装 pip,只需使用以下命令:-

sudo apt-get install python3-pip

=>Easy way to install Python any version on Ubuntu 18.04 or Ubuntu 20.04 follow these steps:-

Step 1: Update Local Repositories:-

sudo apt update

Step 2: Install Supporting Software:-

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

Step3: Create directory on your home directory To download the newest release of Python Source Code, navigate to the /python-source-files directory and use the wget command:-

mkdir python-source-files

Step 4: Download the Latest Version of Python Source Code:-

wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz

"you can change python version by just modifies this:-"3.7.5" with the version you want example:-"3.5.2"

Step 5: Extract Compressed Files:-

tar –xf Python-3.7.5.tgz
or
tar xvzf Python-3.7.5.tgz

Step 6: Test System and Optimize Python:-

cd python-3.7.5 or your version of python.

Step 7: Now configure(Using the ––optimization option speeds code execution by 10-20%.):-

./configure ––enable–optimizations

OR you can also do this also if you facing ssl error:-

./configure --with-openssl

Step 8: Install a Second Instance of Python:-

sudo make altinstall

"It is recommended that you use the altinstall method. Your Ubuntu system may have software packages dependent on Python 2.x.

OR

If you want to Overwrite Default Python Installation/version:-

sudo make install"

Step 9:Now check Python Version:-

python3 ––version

Step 10: To install pip for python3 just go with this command:-

sudo apt-get install python3-pip

紫竹語嫣☆ 2024-11-25 20:25:04

编辑:手动安装和使用 setuptools 不再是标准过程。

如果您运行的是 Python 2.7.9+ 或 Python 3.4+

恭喜,您应该已经安装了 pip。如果您不这样做,请继续阅读。

如果您运行的是类 Unix 系统

如果您的 Python 版本早于 2.7.9 或 3.4,或者您的系统不包含,您通常可以通过包管理器安装 pip 包无论出于何种原因。

下面是一些更常见发行版的说明。

在 Debian(Wheezy 及更新版本)和 Ubuntu(Trusty Tahr 及更新版本)上安装 Python 2.x

从终端运行以下命令:

sudo apt-get install python-pip 

在 Debian(Wheezy 及更新版本)和 Ubuntu(Trusty Tahr 及更新版本)上安装 Python 3.x

从终端运行以下命令:

sudo apt-get install python3-pip

Note:

在全新安装的 Debian/Ubuntu 上,可能无法找到该软件包,直到您这样做:

sudo apt-get update

在 CentOS 7 for Python 上安装 pip 2.x

在 CentOS 7 上,您必须先安装安装工具,然后使用它来安装 pip,因为没有直接的软件包。

sudo yum install python-setuptools
sudo easy_install pip

在 CentOS 7 上安装 Python 3.x 的 pip

假设您从 EPEL 安装了 Python 3.4 ,您可以安装Python 3的安装工具并使用它来安装pip

# First command requires you to have enabled EPEL for CentOS7
sudo yum install python34-setuptools
sudo easy_install pip

如果您的 Unix/Linux 发行版在软件包存储库中没有它,

请使用下面详细介绍的手动方式安装。

手动方式

如果您想以手动方式进行安装,现在推荐的方法是使用 get-pip.py 脚本进行安装。 io/en/stable/installing.html" rel="noreferrer">pip 的安装说明

安装pip

要安装 pip,请安全下载 get-pip.py

然后运行以下命令(可能需要管理员访问权限):

python get-pip.py 

如果尚未安装 setuptoolsget-pip.py 将为您安装 setuptools。

edit: Manual installation and use of setuptools is not the standard process anymore.

If you're running Python 2.7.9+ or Python 3.4+

Congrats, you should already have pip installed. If you do not, read onward.

If you're running a Unix-like System

You can usually install the package for pip through your package manager if your version of Python is older than 2.7.9 or 3.4, or if your system did not include it for whatever reason.

Instructions for some of the more common distros follow.

Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 2.x

Run the following command from a terminal:

sudo apt-get install python-pip 

Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 3.x

Run the following command from a terminal:

sudo apt-get install python3-pip

Note:

On a fresh Debian/Ubuntu install, the package may not be found until you do:

sudo apt-get update

Installing pip on CentOS 7 for Python 2.x

On CentOS 7, you have to install setup tools first, and then use that to install pip, as there is no direct package for it.

sudo yum install python-setuptools
sudo easy_install pip

Installing pip on CentOS 7 for Python 3.x

Assuming you installed Python 3.4 from EPEL, you can install Python 3's setup tools and use it to install pip.

# First command requires you to have enabled EPEL for CentOS7
sudo yum install python34-setuptools
sudo easy_install pip

If your Unix/Linux distro doesn't have it in package repos

Install using the manual way detailed below.

The manual way

If you want to do it the manual way, the now-recommended method is to install using the get-pip.py script from pip's installation instructions.

Install pip

To install pip, securely download get-pip.py

Then run the following (which may require administrator access):

python get-pip.py 

If setuptools is not already installed, get-pip.py will install setuptools for you.

书信已泛黄 2024-11-25 20:25:04

我只需运行 sudo apt-get install python3-pip 就可以在 Ubuntu 上安装适用于 python 3 的 pip。

I was able to install pip for python 3 on Ubuntu just by running sudo apt-get install python3-pip.

请远离我 2024-11-25 20:25:04

Python 3.4+ 和 Python 2.7.9+

好消息! Python 3.4(2014 年 3 月发布)随 Pip 一起提供。这是所有 Python 版本中最好的特性。它使每个人都可以访问社区丰富的图书馆。新手不再因设置难度过高而被排除在外。在附带包管理器的过程中,Python 加入了 Ruby、Nodejs、Haskell、Perl、Go 等几乎所有其他拥有大多数开源社区的当代语言。谢谢你,Python。

当然,这并不意味着Python打包问题就解决了。这种经历仍然令人沮丧。我在 Python 有包/模块管理吗系统?

唉,对于每个使用早期 Python 的人来说都是如此。以下是手动说明。

Python ≤ 2.7.8 和 Python ≤ 3.3

请按照我的详细说明进行操作:https://stackoverflow.com/a/12476379/284795 .基本上

官方说明

按照 https://pip.pypa.io/en/stable/installing.html 的

下载get-pip.py,小心将其保存为 .py 文件而不是 .txt。然后,从命令提示符运行它。

python get-pip.py

您可能需要管理员命令提示符才能执行此操作。关注 http://technet.microsoft.com/en -us/library/cc947813(v=ws.10).aspx

对于我来说,这将 Pip 安装在C:\Python27\Scripts\pip.exe。在您的计算机上找到 pip.exe,然后将其文件夹(例如 C:\Python27\Scripts)添加到您的路径(开始/编辑环境变量)。现在您应该能够从命令行运行pip。尝试安装一个包:

pip install httpie

你就可以了(希望如此)!

Python 3.4+ and Python 2.7.9+

Good news! Python 3.4 (released March 2014) ships with Pip. This is the best feature of any Python release. It makes the community's wealth of libraries accessible to everyone. Newbies are no longer excluded by the prohibitive difficulty of setup. In shipping with a package manager, Python joins Ruby, Nodejs, Haskell, Perl, Go--almost every other contemporary language with a majority open-source community. Thank you Python.

Of course, that doesn't mean Python packaging is problem solved. The experience remains frustrating. I discuss this at Does Python have a package/module management system?

Alas for everyone using an earlier Python. Manual instructions follow.

Python ≤ 2.7.8 and Python ≤ 3.3

Follow my detailed instructions at https://stackoverflow.com/a/12476379/284795 . Essentially

Official instructions

Per https://pip.pypa.io/en/stable/installing.html

Download get-pip.py, being careful to save it as a .py file rather than .txt. Then, run it from the command prompt.

python get-pip.py

You possibly need an administrator command prompt to do this. Follow http://technet.microsoft.com/en-us/library/cc947813(v=ws.10).aspx

For me, this installed Pip at C:\Python27\Scripts\pip.exe. Find pip.exe on your computer, then add its folder (eg. C:\Python27\Scripts) to your path (Start / Edit environment variables). Now you should be able to run pip from the command line. Try installing a package:

pip install httpie

There you go (hopefully)!

油焖大侠 2024-11-25 20:25:04

如果您使用的是 python 3.4+,

只需输入:

python3 -m pip

if you're using python 3.4+

just type:

python3 -m pip
迷路的信 2024-11-25 20:25:04

对于 Ubuntu 12.04 或更早版本,

sudo apt-get install python3-pip

不起作用。相反,使用:

sudo apt-get install python3-setuptools ca-certificates
sudo easy_install3 pip

For Ubuntu 12.04 or older,

sudo apt-get install python3-pip

won't work. Instead, use:

sudo apt-get install python3-setuptools ca-certificates
sudo easy_install3 pip
我喜欢麦丽素 2024-11-25 20:25:04

2015 年 1 月 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

Update 2015-01-20:

As per https://pip.pypa.io/en/latest/installing.html the current way is:

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

I think that should work for any version


Original Answer:

wget http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
春夜浅 2024-11-25 20:25:04

系统中只有一个 Python

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

  1. 如果软件包适用于 python 2.xsudo python -m pip install [package]
  2. 如果包适用于 python 3.xsudo python3 -m pip install [package]

注意:假设没有为 设置别名python

通过这个方法,不会有关于哪个 python 版本正在接收包的混乱。

多个 Python/虚拟环境

假设您有 python3 ↔ python3.6python3.7 ↔ python3.7

  1. 要安装 python3.6sudo python3 -m pip install [package]
  2. 要安装python3.7sudo python3.7 -m pip install [package]

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

注1

如何找到哪个python?执行以下操作之一:

~ » 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

更改 python3python指向:https://askubuntu.com/questions/320996/how-to- make-python-program-command-execute-python-3

Single Python in system

To install packages in Python always follow these steps:

  1. If the package is for python 2.x: sudo python -m pip install [package]
  2. If the package is for python 3.x: sudo python3 -m pip install [package]

Note: This is assuming no alias is set for python

Through this method, there will be no confusion regarding which python version is receiving the package.

Multiple Pythons/Virtual Envs

Say you have python3 ↔ python3.6 and python3.7 ↔ python3.7

  1. To install for python3.6: sudo python3 -m pip install [package]
  2. To instal for python3.7: sudo python3.7 -m pip install [package]

This is essentially the same method as shown previously.

Note 1

How to find which python? Do one of the following:

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

your python3 command spawns:

~ » 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.
>>> 

Notice python 3.9.5 in the second line.

or say you are using virtual env and see where your python points to:

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

Note 2

Change what python3 or python points to: https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3

不一样的天空 2024-11-25 20:25:04
python3 -m ensurepip

我不确定它是什么时候引入的,但它在 pip3 还不存在时为我安装了。

python3 -m ensurepip

I'm not sure when exactly this was introduced, but it's installed pip3 for me when it didn't already exist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文