标签归档:pip

将pip软件包安装到$ HOME文件夹

问题:将pip软件包安装到$ HOME文件夹

可能吗?安装时pip,将python软件包安装在我的$HOME文件夹中。(例如,我想使用安装,但mercurial使用而不是)pip$HOME/usr/local

我在Mac机器上,只是考虑了这种可能性,而不是“污染”我的/usr/local$HOME而是使用我的。

PEP370正是与此有关。只是创建一个˜/.localpip install package足以将这些软件包安装在我的$ HOME文件夹中?

Is it possible? When installing pip, install the python packages inside my $HOME folder. (for example, I want to install mercurial, using pip, but inside $HOME instead of /usr/local)

I’m with a mac machine and just thought about this possibility, instead of “polluting” my /usr/local, I would use my $HOME instead.

PEP370 is exactly about this. Is just creating a ˜/.local and do a pip install package enough to make these packages to be installed only at my $HOME folder?


回答 0

虽然您可以使用virtualenv,但不需要。诀窍是将PEP370 --user参数传递给setup.py脚本。使用的最新版本pip,一种方法是:

pip install --user mercurial

这应导致hg脚本已安装在中$HOME/.local/bin/hg,而hg软件包的其余部分已安装在中$HOME/.local/lib/pythonx.y/site-packages/

请注意,以上内容适用于Python 2.6。一直有一些争议的关于什么是PEP370风格的Mac OS X上的相应目录位置Python的核心开发者user安装。在Python 2.7和3.2中,Mac OS X上的位置从更改$HOME/.local$HOME/Library/Python。这可能会在将来的版本中更改。但是,目前,在2.7(和3.2,如果hgPython 3支持的话)上,上述位置将是$HOME/Library/Python/x.y/bin/hg$HOME/Library/Python/x.y/lib/python/site-packages

While you can use a virtualenv, you don’t need to. The trick is passing the PEP370 --user argument to the setup.py script. With the latest version of pip, one way to do it is:

pip install --user mercurial

This should result in the hg script being installed in $HOME/.local/bin/hg and the rest of the hg package in $HOME/.local/lib/pythonx.y/site-packages/.

Note, that the above is true for Python 2.6. There has been a bit of controversy among the Python core developers about what is the appropriate directory location on Mac OS X for PEP370-style user installations. In Python 2.7 and 3.2, the location on Mac OS X was changed from $HOME/.local to $HOME/Library/Python. This might change in a future release. But, for now, on 2.7 (and 3.2, if hg were supported on Python 3), the above locations will be $HOME/Library/Python/x.y/bin/hg and $HOME/Library/Python/x.y/lib/python/site-packages.


回答 1

我会在您的HOME目录中使用virtualenv。

$ sudo easy_install -U virtualenv
$ cd ~
$ virtualenv .
$ bin/pip ...

然后~/.(login|profile|bash_profile),您还可以更改,无论哪种方式都适合您的shell将〜/ bin添加到您的PATH中,然后pip|python|easy_install默认情况下使用。

I would use virtualenv at your HOME directory.

$ sudo easy_install -U virtualenv
$ cd ~
$ virtualenv .
$ bin/pip ...

You could then also alter ~/.(login|profile|bash_profile), whichever is right for your shell to add ~/bin to your PATH and then that pip|python|easy_install would be the one used by default.


回答 2

您可以指定-t选项(--target)来指定目标目录。请参阅pip install --help以获取详细信息。这是您需要的命令:

pip install -t path_to_your_home package-name

例如,要在我的$HOME目录中安装说“ mxnet”,请输入:

pip install -t /home/foivos/ mxnet

You can specify the -t option (--target) to specify the destination directory. See pip install --help for detailed information. This is the command you need:

pip install -t path_to_your_home package-name

for example, for installing say mxnet, in my $HOME directory, I type:

pip install -t /home/foivos/ mxnet

“ pip install unroll”:“ python setup.py egg_info”失败,错误代码为1

问题:“ pip install unroll”:“ python setup.py egg_info”失败,错误代码为1

我是Python的新手,并一直在尝试使用安装某些软件包pip

但是pip install unroll给我

命令“ python setup.py egg_info”在C:\ Users \ MARKAN〜1 \ AppData \ Local \ Temp \ pip-build-wa7uco0k \ unroll \中失败,错误代码为1

我该如何解决?

I’m new to Python and have been trying to install some packages with pip.

But pip install unroll gives me

Command “python setup.py egg_info” failed with error code 1 in C:\Users\MARKAN~1\AppData\Local\Temp\pip-build-wa7uco0k\unroll\

How can I solve this?


回答 0

关于错误代码

根据Python文档

该模块提供了可用的标准errno系统符号。每个符号的值是相应的整数值。名称和描述是从linux / include / errno.h借来的,应该十分全面。

错误代码1在errno.h和中定义Operation not permitted

关于您的错误

您的setuptools似乎未安装。只需遵循Installation InstructionsPyPI网站上的即可。

如果已经安装,请尝试

pip install --upgrade setuptools

如果已经更新,请检查模块ez_setup是否缺失。如果是的话

pip install ez_setup

然后再试一次

pip install unroll

如果仍然无法正常运行,则可能是pip没有正确安装/升级setup_tools,因此您可能需要尝试

easy_install -U setuptools

然后再次

pip install unroll

About the error code

According to the Python documentation:

This module makes available standard errno system symbols. The value of each symbol is the corresponding integer value. The names and descriptions are borrowed from linux/include/errno.h, which should be pretty all-inclusive.

Error code 1 is defined in errno.h and means Operation not permitted.

About your error

Your setuptools do not appear to be installed. Just follow the Installation Instructions from the PyPI website.

If it’s already installed, try

pip install --upgrade setuptools

If it’s already up to date, check that the module ez_setup is not missing. If it is, then

pip install ez_setup

Then try again

pip install unroll

If it’s still not working, maybe pip didn’t install/upgrade setup_tools properly so you might want to try

easy_install -U setuptools

And again

pip install unroll

回答 1

这是一些指南,解释了我通常如何在Python + Windows上安装新软件包。看来您使用的是Windows路径,因此此答案将遵循特定的SO:

  • 我从不使用系统范围的Python安装。我只使用virtualenvs,通常我会尝试使用最新版本的2.x和3.x。
  • 我的第一次尝试总是pip install package_i_want在某些Visual Studio命令提示符下进行。什么Visual Studio命令提示符?好吧,理想情况下是与用来构建Python的Visual Studio相匹配的Visual Studio。例如,假设您的Python安装提示Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32。可以在此处找到用于编译Python的Visual Studio版本,因此v1500表示我将使用vs2008 x64命令提示符
  • 如果上一步由于某种原因而失败,我只是尝试使用 easy_install package_i_want
  • 如果上一步由于某种原因失败,我将转到gohlke网站,并检查我的包裹是否在那儿。如果是这样,我很幸运,我将其下载到virtualenv中,然后使用命令提示符转到该位置,然后执行pip install package_i_want.whl
  • 如果上一步没有成功,我将尝试自己制作轮子,一旦生成,我将尝试使用 pip install package_i_want.whl

现在,如果我们专注于您的特定问题,那么您将很难安装展开软件包。似乎最快的安装方式是执行以下操作:

  • git clone https://github.com/Zulko/unroll
  • cd unroll && python setup.py bdist_wheel
  • 将创建的dist文件夹中生成的unroll-0.1.0-py2-none-any.whl文件复制到virtualenv中。
  • pip install unroll-0.1.0-py2-none-any.whl

这样,它将安装没有任何问题。要检查它是否确实有效,只需登录Python安装并尝试import unroll,不要抱怨。

最后一点:这种方法几乎在99%的时间内都有效,有时您会发现一些特定于Unix或Mac OS X的pip程序包,在这种情况下,恐怕最好的方法是Windows版本正在向主要开发人员发布一些问题,或者您可以通过自己移植到Windows来获得一些乐趣(如果不走运,通常需要几个小时):)

Here’s a little guide explaining a little bit how I usually install new packages on Python + Windows. It seems you’re using Windows paths, so this answer will stick to that particular SO:

  • I never use a system-wide Python installation. I only use virtualenvs, and usually I try to have the latest version of 2.x & 3.x.
  • My first attempt is always doing pip install package_i_want in some of my Visual Studio command prompts. What Visual Studio command prompt? Well, ideally the Visual Studio which matches the one which was used to build Python. For instance, let’s say your Python installation says Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32. The version of Visual Studio used to compile Python can be found here, so v1500 means I’d be using vs2008 x64 command prompt
  • If the previous step failed for some reason I just try using easy_install package_i_want
  • If the previous step failed for some reason I go to gohlke website and I check whether my package is available over there. If it’s so, I’m lucky, I just download it into my virtualenv and then I just go to that location using a command prompt and I do pip install package_i_want.whl
  • If the previous step didn’t succeed I’ll just try to build the wheel myself and once it’s generated I’ll try to install it with pip install package_i_want.whl

Now, if we focus in your specific problem, where you’re having a hard time installing the unroll package. It seems the fastest way to install it is doing something like this:

  • git clone https://github.com/Zulko/unroll
  • cd unroll && python setup.py bdist_wheel
  • Copy the generated unroll-0.1.0-py2-none-any.whl file from the created dist folder into your virtualenv.
  • pip install unroll-0.1.0-py2-none-any.whl

That way it will install without any problems. To check it really works, just login into the Python installation and try import unroll, it shouldn’t complain.

One last note: This method works almost 99% of the time, and sometimes you’ll find some pip packages which are specific to Unix or Mac OS X, in that case, when that happens I’m afraid the best way to get a Windows version is either posting some issues to the main developers or having some fun by yourself porting to Windows (typically a few hours if you’re not lucky) :)


回答 2

升级点数后已解决:

python -m pip install --upgrade pip
pip install "package-name"

It was resolved after upgrading pip:

python -m pip install --upgrade pip
pip install "package-name"

回答 3

我完全陷入了与相同的错误psycopg2。看来我在安装Python和相关软件包时跳过了几个步骤。

  1. sudo apt-get install python-dev libpq-dev
  2. 转到您的虚拟环境
  3. pip install psycopg2

(在您的情况下,您需要替换psycopg2遇到问题的软件包。)

它无缝地工作。

I got stuck exactly with the same error with psycopg2. It looks like I skipped a few steps while installing Python and related packages.

  1. sudo apt-get install python-dev libpq-dev
  2. Go to your virtual env
  3. pip install psycopg2

(In your case you need to replace psycopg2 with the package you have an issue with.)

It worked seamlessly.


回答 4

在安装我得到同样的错误mitmproxy使用pip3。下面的命令解决了这个问题:

pip3 install --upgrade setuptools

I got this same error while installing mitmproxy using pip3. The below command fixed this:

pip3 install --upgrade setuptools

回答 5

  • Microsoft Visual C++ Compiler for Python 2.7https://www.microsoft.com/zh-cn/download/details.aspx?id=44266下载并安装-此程序包包含为Python 2.7程序包生成二进制文件所需的编译器和系统标头集。
  • 在提升模式下打开命令提示符(以管理员身份运行)
  • 首先要做 pip install ez_setup
  • 然后做pip install unroll(它将开始安装numpy, music21, decorator, imageio, tqdm, moviepy, unroll)#请耐心等待music21安装

使用python 2.7.11 64位

  • Download and install the Microsoft Visual C++ Compiler for Python 2.7 from https://www.microsoft.com/en-in/download/details.aspx?id=44266 – this package contains the compiler and set of system headers necessary for producing binary wheels for Python 2.7 packages.
  • Open a command prompt in elevated mode (run as administrator)
  • Firstly do pip install ez_setup
  • Then do pip install unroll (It will start installing numpy, music21, decorator, imageio, tqdm, moviepy, unroll) # Please be patient for music21 installation

Python 2.7.11 64 bit used


回答 6

另一种方式:

sudo apt-get install python-psycopg2 python-mysqldb

Other way:

sudo apt-get install python-psycopg2 python-mysqldb

回答 7

我有同样的问题。

问题是

pyparsing 2.2已经安装好了,我requirements.txt正在尝试安装pyparsing 2.0.1,抛出此错误

上下文:我使用的是virtualenv,似乎2.2来自我的全局操作系统Python site-packages,但是即使带有--no-site-packages标志(默认为上一个virtualenv中的默认标志),2.2仍然存在。肯定是因为我从他们的网站安装了Python,并将Python库添加到了我的$PATH

也许一个pip install --ignore-installed会工作。

解决方案:因为我需要向前移动,我只是删除了pyparsing==2.0.1从我的requirements.txt

I had the same problem.

The problem was:

pyparsing 2.2 was already installed and my requirements.txt was trying to install pyparsing 2.0.1 which throw this error

Context: I was using virtualenv, and it seems the 2.2 came from my global OS Python site-packages, but even with --no-site-packages flag (now by default in last virtualenv) the 2.2 was still present. Surely because I installed Python from their website and it added Python libraries to my $PATH.

Maybe a pip install --ignore-installed would have worked.

Solution: as I needed to move forwards, I just removed the pyparsing==2.0.1 from my requirements.txt.


回答 8

尝试使用pip安装Python模块时遇到了相同的错误代码。@Hackndo指出文档指出了安全问题。

基于该答案,我的问题通过运行带有sudo前缀的pip install命令得以解决:

sudo pip install python-mpd2

I ran into the same error code when trying to install a Python module with pip. @Hackndo noted that the documentation indicate a security issue.

Based on that answer, my problem was solved by running the pip install command with sudo prefixed:

sudo pip install python-mpd2

回答 9

在安装“ Twisted”库时遇到了相同的问题,并通过在Ubuntu 16.04(Xenial Xerus)上运行以下命令解决了该问题:

sudo apt-get install python-setuptools python-dev build-essential

I had the same issue when installing the “Twisted” library and solved it by running the following command on Ubuntu 16.04 (Xenial Xerus):

sudo apt-get install python-setuptools python-dev build-essential

回答 10

我尝试了以上所有方法,但均未成功。然后,我将Python版本从2.7.10更新到2.7.13,它解决了我遇到的问题。

I tried all of the above with no success. I then updated my Python version from 2.7.10 to 2.7.13, and it resolved the problems that I was experiencing.


回答 11

这意味着pip中的某些软件包较旧或未正确安装。

  1. 尝试检查版本,然后升级pip。如果可行,请使用自动删除。

  2. 如果pip命令始终对任何命令显示错误或冻结,等等。

  3. 最好的解决方案是将其卸载或完全删除。

  4. 安装一个新的点,然后更新和升级您的系统。

  5. 我给出了在此处新鲜安装pip的解决方案-python:无法打开文件get-pip.py错误2]没有此类文件或目录

That means some packages in pip are old or not correctly installed.

  1. Try checking version and then upgrading pip.Use auto remove if that works.

  2. If the pip command shows an error all the time for any command or it freezes, etc.

  3. The best solution is to uninstall it or remove it completely.

  4. Install a fresh pip and then update and upgrade your system.

  5. I have given a solution to installing pip fresh here – python: can’t open file get-pip.py error 2] no such file or directory


回答 12

这对我来说是更简单的方法:

pip2 install Name

因此,如果您使用的是pip,请尝试使用pip3pip2

它应该解决问题。

This was the easier way for me:

pip2 install Name

So if you was using pip, try to use pip3 or pip2

It should solve the problem.


回答 13

pip3 install –upgrade setuptools警告:pip正在由旧的脚本包装程序调用。这将在以后的pip版本中失败。请参阅https://github.com/pypa/pip/issues/5599,以获取有关解决基本问题的建议。

******为了避免此问题,您可以使用-m pip调用Python,而不是直接运行pip。******

使用python3 -m pip“命令”例如:python3 -m pip install –user pyqt5

pip3 install –upgrade setuptools WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.

******To avoid this problem you can invoke Python with ‘-m pip’ instead of running pip directly.******

use python3 -m pip “command” eg: python3 -m pip install –user pyqt5


回答 14

这为我工作:

sudo xcodebuild -license

This worked for me:

sudo xcodebuild -license

回答 15

将Python升级到版本3解决了我的问题。什么都没做。

Upgrading Python to version 3 fixed my problem. Nothing else did.


回答 16

我从http://www.lfd.uci.edu/~gohlke/pythonlibs/下载了.whl文件,然后执行了以下操作:

pip install scipy-0.19.1-cp27-cp27m-win32.whl

请注意,您需要使用的版本(win32 / win_amd-64)取决于Python的版本,而不取决于Windows的版本。

I downloaded the .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/ and then did:

pip install scipy-0.19.1-cp27-cp27m-win32.whl

Note that the version you need to use (win32/win_amd-64) depends on the version of Python and not that of Windows.


回答 17

我在新的开发设置上使用virtualenvs(带有pipenv)遇到了这个问题。

我只能通过将psycopg2版本从2.6.2升级到2.7.3来解决它。更多信息在https://github.com/psycopg/psycopg2/issues/594

I had this problem using virtualenvs (with pipenv) on my new development setup.

I could only solve it by upgrading the psycopg2 version from 2.6.2 to 2.7.3. More information is at https://github.com/psycopg/psycopg2/issues/594


回答 18

我在使用相同的错误消息时遇到了同样的问题,但是在Ubuntu 16.04 LTS(Xenial Xerus)上却相反:

命令“ python setup.py egg_info”在/ tmp / pip-install-w71uo1rg / poster /中失败,错误代码为1

我测试了上面提供的所有解决方案,但没有一个对我有用。我阅读了完整的TraceBack,发现我必须使用python版本2.7创建虚拟环境(默认情况下使用Python 3.5):

virtualenv --python=/usr/bin/python2.7 my_venv

激活它后,我将pip install unirest成功运行。

I faced the same problem with the same error message but on Ubuntu 16.04 LTS (Xenial Xerus) instead:

Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-install-w71uo1rg/poster/

I tested all the solutions provided above and none of them worked for me. I read the full TraceBack and found out I had to create the virtual environment with Python version 2.7 instead (the default one uses Python 3.5 instead):

virtualenv --python=/usr/bin/python2.7 my_venv

Once I activated it, I run pip install unirest successfully.


回答 19

尝试在Linux上:

sudo apt install python-pip python-bluez libbluetooth-dev libboost-python-dev libboost-thread-dev libglib2.0-dev bluez bluez-hcidump

try on linux:

sudo apt install python-pip python-bluez libbluetooth-dev libboost-python-dev libboost-thread-dev libglib2.0-dev bluez bluez-hcidump

回答 20

我使用以下方法在Centos 7上解决了该问题:

sudo yum install libcurl-devel

I solved it on Centos 7 by using:

sudo yum install libcurl-devel

回答 21

我的Win10 PC上使用不同的软件包时遇到了相同的问题,并尝试了到目前为止提到的所有内容。

最后通过禁用Comodo Auto-Containment解决了该问题。

由于没有人提及它,我希望它能对某人有所帮助。

Had the same problem on my Win10 PC with different packages and tried everything mentioned so far.

Finally solved it by disabling Comodo Auto-Containment.

Since nobody has mentioned it yet, I hope it helps someone.


回答 22

我遇到了同样的问题,可以通过以下操作解决。

Windows Python需要通过SDK安装的Visual C ++库来构建代码,例如通过setuptools.extension.Extension或numpy.distutils.core.Extension。例如,在Windows中使用Python构建f2py模块需要安装上述Visual C ++ SDK。在Linux和Mac上,C ++库随编译器一起安装。

https://www.scivision.co/python-windows-visual-c++-14-required/

I had the same problem and was able to fix by doing the following.

Windows Python needs Visual C++ libraries installed via the SDK to build code, such as via setuptools.extension.Extension or numpy.distutils.core.Extension. For example, building f2py modules in Windows with Python requires Visual C++ SDK as installed above. On Linux and Mac, the C++ libraries are installed with the compiler.

https://www.scivision.co/python-windows-visual-c++-14-required/


回答 23

以下命令对我有用

[root@sandbox ~]# pip install google-api-python-client==1.6.4

Following below command worked for me

[root@sandbox ~]# pip install google-api-python-client==1.6.4

回答 24

更新setuptools时解决setup.pu egg_info问题的方法或其他方法不起作用。

  1. 如果CONDA可以安装版本的库,请使用conda而不是pip。
  2. 克隆库回购,然后尝试通过pip install -e .或通过进行安装python setup.py install

Methods to solve setup.pu egg_info issue when updating setuptools or not other methods doesnot works.

  1. If CONDA version of the library is available to install use conda instead of pip.
  2. Clone the library repo and then try installation by pip install -e . or by python setup.py install

pip在哪里安装其软件包?

问题:pip在哪里安装其软件包?

我激活了已安装pip的virtualenv。我做了

pip3 install Django==1.8

和Django成功下载。现在,我想打开Django文件夹。文件夹在哪里?通常它会在“下载”中,但是我不确定如果在virtualenv中使用pip安装它会在哪里。

I activated a virtualenv which has pip installed. I did

pip3 install Django==1.8

and Django successfully downloaded. Now, I want to open up the Django folder. Where is the folder located? Normally it would be in “downloads” but I’m not sure where it would be if I installed it using pip in a virtualenv.


回答 0

virtualenv一起使用时,pip通常会在路径中安装软件包<virtualenv_name>/lib/<python_ver>/site-packages

例如,我使用Python 2.7 创建了一个名为venv_test的测试virtualenv ,该文件夹位于中。djangovenv_test/lib/python2.7/site-packages/django

pip when used with virtualenv will generally install packages in the path <virtualenv_name>/lib/<python_ver>/site-packages.

For example, I created a test virtualenv named venv_test with Python 2.7, and the django folder is in venv_test/lib/python2.7/site-packages/django.


回答 1

根据大众需求,通过发布的答案提供了一个选项:

pip show <package name>将提供Windows和macOS的位置,我猜是任何系统。:)

例如:

> pip show cvxopt
Name: cvxopt
Version: 1.2.0
...
Location: /usr/local/lib/python2.7/site-packages

By popular demand, an option provided via posted answer:

pip show <package name> will provide the location for Windows and macOS, and I’m guessing any system. :)

For example:

> pip show cvxopt
Name: cvxopt
Version: 1.2.0
...
Location: /usr/local/lib/python2.7/site-packages

回答 2

pip list -v可用于列出软件包的安装位置,该位置在https://pip.pypa.io/zh/stable/news/#b1-2018-03-31中引入

当列表命令与“ -v”选项一起运行时,显示安装位置。(#979)

>pip list -v
Package                  Version   Location                                                             Installer
------------------------ --------- -------------------------------------------------------------------- ---------
alabaster                0.7.12    c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
apipkg                   1.5       c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
argcomplete              1.10.3    c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
astroid                  2.3.3     c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
...

更新pip10.0.0b1中引入了此功能。在Ubuntu 18.04上,pippip3安装有sudo apt install python-pip或是sudo apt install python3-pip9.0.1的版本,但没有此功能。检查https://github.com/pypa/pip/issues/5599,了解升级pip或升级的合适方法pip3

pip list -v can be used to list packages’ install locations, introduced in https://pip.pypa.io/en/stable/news/#b1-2018-03-31

Show install locations when list command ran with “-v” option. (#979)

>pip list -v
Package                  Version   Location                                                             Installer
------------------------ --------- -------------------------------------------------------------------- ---------
alabaster                0.7.12    c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
apipkg                   1.5       c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
argcomplete              1.10.3    c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
astroid                  2.3.3     c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
...

Update: This feature is introduced in pip 10.0.0b1. On Ubuntu 18.04, pip or pip3 installed with sudo apt install python-pip or sudo apt install python3-pip is 9.0.1 which doesn’t have this feature. Check https://github.com/pypa/pip/issues/5599 for suitable ways of upgrading pip or pip3.


回答 3

默认情况下,在Linux上,Pip将软件包安装到/usr/local/lib/python2.7/dist-packages。

在安装过程中使用virtualenv或–user将更改此默认位置。如果使用,请pip show确保使用的用户正确,否则pip可能看不到您所引用的软件包。

By default, on Linux, Pip installs packages to /usr/local/lib/python2.7/dist-packages.

Using virtualenv or –user during install will change this default location. If you use pip show make sure you are using the right user or else pip may not see the packages you are referencing.


回答 4

在Python解释器或脚本中,您可以执行

import site
site.getsitepackages() # list of global package locations

site.getusersitepackages() #string for user-specific package location

位置安装了第三方软件包(不在核心Python发行版中)。

在MacOS上我的Brew安装的Python上,前者输出

['/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']

pip show如上一个答案所述,它规范化到所输出的相同路径:

$ readlink -f /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
/usr/local/lib/python3.7/site-packages

参考:https : //docs.python.org/3/library/site.html#site.getsitepackages

In a Python interpreter or script, you can do

import site
site.getsitepackages() # list of global package locations

and

site.getusersitepackages() #string for user-specific package location

for locations 3rd party packages (those not in the core Python distribution) are installed to.

On my Brew-installed Python on MacOS, the former outputs

['/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages'],

which canonicalizes to the same path output by pip show, as mentioned in a previous answer:

$ readlink -f /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
/usr/local/lib/python3.7/site-packages

Reference: https://docs.python.org/3/library/site.html#site.getsitepackages


删除pip安装的所有软件包的最简单方法是什么?

问题:删除pip安装的所有软件包的最简单方法是什么?

我正在尝试修复我的virtualenv之一-我想将所有已安装的库重置为与生产相匹配的库。

有没有一种快速简便的方法来使用pip?

I’m trying to fix up one of my virtualenvs – I’d like to reset all of the installed libraries back to the ones that match production.

Is there a quick and easy way to do this with pip?


回答 0

我已找到此代码段作为替代解决方案。与重建virtualenv相比,这是对库的更优雅的删除:

pip freeze | xargs pip uninstall -y

如果您通过VCS安装了软件包,则需要排除这些行并手动删除软件包(从下面的注释中升高):

pip freeze | grep -v "^-e" | xargs pip uninstall -y

I’ve found this snippet as an alternative solution. It’s a more graceful removal of libraries than remaking the virtualenv:

pip freeze | xargs pip uninstall -y

In case you have packages installed via VCS, you need to exclude those lines and remove the packages manually (elevated from the comments below):

pip freeze | grep -v "^-e" | xargs pip uninstall -y

回答 1

这将适用于所有Mac,Windows和Linux系统。要在requirements.txt文件中获取所有pip包的列表(注意:如果存在,它将覆盖requirements.txt,否则将创建新的pip包,如果您不想替换旧的requirements.txt,请提供其他文件名在所有以下命令中将它们放置在requirements.txt中)。

pip freeze > requirements.txt

现在一一删除

pip uninstall -r requirements.txt

如果我们想一次删除所有

pip uninstall -r requirements.txt -y

如果您正在处理具有requirements.txt文件的现有项目,并且您的环境有所不同,只需requirements.txt将上面的示例替换为toberemoved.txt。然后,完成上述步骤后,您可以使用requirements.txt来更新您现在干净的环境。

对于不创建任何文件的单个命令(如@joeb建议)。

pip uninstall -y -r <(pip freeze)

This will work for all Mac, Windows, and Linux systems. To get the list of all pip packages in the requirements.txt file (Note: This will overwrite requirements.txt if exist else will create the new one, also if you don’t want to replace old requirements.txt then give different file name in the all following command in place requirements.txt).

pip freeze > requirements.txt

Now to remove one by one

pip uninstall -r requirements.txt

If we want to remove all at once then

pip uninstall -r requirements.txt -y

If you’re working on an existing project that has a requirements.txt file and your environment has diverged, simply replace requirements.txt from the above examples with toberemoved.txt. Then, once you have gone through the steps above, you can use the requirements.txt to update your now clean environment.

And For single command without creating any file (As @joeb suggested).

pip uninstall -y -r <(pip freeze)

回答 2

这适用于最新版本。我认为这是最短,最声明的方式。

virtualenv --clear MYENV

但是通常由于不变性规则,我只是删除并重新创建virtualenv!

This works with the latest. I think it’s the shortest and most declarative way to do it.

virtualenv --clear MYENV

But usually I just delete and recreate the virtualenv since immutability rules!


回答 3

我想在评论部分中提出这个答案,因为它是线程中最优雅的解决方案之一。此答案的全部功劳归@joeb

pip uninstall -y -r <(pip freeze)

对于清除在virtualenv上下文之外的我的用户包文件夹的用例来说,这对我来说非常有用,上面的许多答案都无法解决。

编辑:有人知道如何使此命令在Makefile中工作吗?

奖励:bash别名

为了方便起见,我将其添加到我的bash个人资料中:

alias pipuninstallall="pip uninstall -y -r <(pip freeze)"

然后运行:

pipuninstallall

Pipenv的替代品

如果碰巧正在使用pipenv,则可以运行:

pipenv uninstall --all

I wanted to elevate this answer out of a comment section because it’s one of the most elegant solutions in the thread. Full credit for this answer goes to @joeb.

pip uninstall -y -r <(pip freeze)

This worked great for me for the use case of clearing my user packages folder outside the context of a virtualenv which many of the above answers don’t handle.

Edit: Anyone know how to make this command work in a Makefile?

Bonus: A bash alias

I add this to my bash profile for convenience:

alias pipuninstallall="pip uninstall -y -r <(pip freeze)"

Then run:

pipuninstallall

Alternative for pipenv

If you happen to be using pipenv you can just run:

pipenv uninstall --all

回答 4

使用pip listpip freeze 必须包含--local其他内容的其他答案也将卸载在通用命名空间中找到的软件包。

这是我经常使用的代码段

 pip freeze --local | xargs pip uninstall -y

参考: pip freeze --help

Other answers that use pip list or pip freeze must include --local else it will also uninstall packages that are found in the common namespaces.

So here are the snippet I regularly use

 pip freeze --local | xargs pip uninstall -y

Ref: pip freeze --help


回答 5

方法1(带有pip freeze

pip freeze | xargs pip uninstall -y

方法2(带有pip list

pip list | awk '{print $1}' | xargs pip uninstall -y

方法3(带有virtualenv

virtualenv --clear MYENV

Method 1 (with pip freeze)

pip freeze | xargs pip uninstall -y

Method 2 (with pip list)

pip list | awk '{print $1}' | xargs pip uninstall -y

Method 3 (with virtualenv)

virtualenv --clear MYENV

回答 6

最快的方法是完全重新制作virtualenv。我假设您有一个与生产匹配的requirements.txt文件,如果不匹配:

# On production:
pip freeze > reqs.txt

# On your machine:
rm $VIRTUALENV_DIRECTORY
mkdir $VIRTUALENV_DIRECTORY
pip install -r reqs.txt

The quickest way is to remake the virtualenv completely. I’m assuming you have a requirements.txt file that matches production, if not:

# On production:
pip freeze > reqs.txt

# On your machine:
rm $VIRTUALENV_DIRECTORY
mkdir $VIRTUALENV_DIRECTORY
pip install -r reqs.txt

回答 7

我通过执行以下操作来管理它:

使用当前安装的软件包列表创建名为reqs.txt的需求文件

pip freeze > reqs.txt

然后从reqs.txt卸载所有软件包

pip uninstall \
   -y # remove the package with prompting for confirmation
   -r reqs.txt

我喜欢这种方法,因为您总是有一个pip要求文件,以防您出错。这也是可重复的。

I managed it by doing the following:

Create the requirements file called reqs.txt with currently installed packages list

pip freeze > reqs.txt

then uninstall all the packages from reqs.txt

pip uninstall \
   -y # remove the package with prompting for confirmation
   -r reqs.txt

I like this method as you always have a pip requirements file to fall back on should you make a mistake. It’s also repeatable.


回答 8

在Windows上,如果path配置正确,则可以使用:

pip freeze > unins && pip uninstall -y -r unins && del unins

对于类似Unix的系统,情况应该类似:

pip freeze > unins && pip uninstall -y -r unins && rm unins

只是警告说这并不完全可靠,因为您可能会遇到诸如“找不到文件”之类的问题,但在某些情况下仍然可以使用

编辑:为清楚起见:unins是一个任意文件,当执行此命令时,其数据已写入其中:pip freeze > unins

依次写入的文件将用于通过暗示的同意/事先批准的方式卸载上述软件包。 pip uninstall -y -r unins

该文件最终在完成后被删除。

On Windows if your path is configured correctly, you can use:

pip freeze > unins && pip uninstall -y -r unins && del unins

It should be a similar case for Unix-like systems:

pip freeze > unins && pip uninstall -y -r unins && rm unins

Just a warning that this isn’t completely solid as you may run into issues such as ‘File not found’ but it may work in some cases nonetheless

EDIT: For clarity: unins is an arbitrary file which has data written out to it when this command executes: pip freeze > unins

That file that it written in turn is then used to uninstall the aforementioned packages with implied consent/prior approval via pip uninstall -y -r unins

The file is finally deleted upon completion.


回答 9

使用virtualenvwrapper函数:

wipeenv

请参阅wibenv文档


回答 10

首先,将所有软件包添加到 requirements.txt

pip freeze > requirements.txt

然后删除所有

pip uninstall -y -r requirements.txt 

First, add all package to requirements.txt

pip freeze > requirements.txt

Then remove all

pip uninstall -y -r requirements.txt 

回答 11

我知道这是一个古老的问题,但是我确实偶然发现了,因此为了将来参考,您现在可以这样做:

pip uninstall [options] <package> ...
pip uninstall [options] -r <requirements file> ...

-r,-要求文件

卸载给定需求文件中列出的所有软件包。此选项可以多次使用。

pip文档版本8.1

Its an old question I know but I did stumble across it so for future reference you can now do this:

pip uninstall [options] <package> ...
pip uninstall [options] -r <requirements file> ...

-r, –requirement file

Uninstall all the packages listed in the given requirements file. This option can be used multiple times.

from the pip documentation version 8.1


回答 12

对于Windows用户,这是我在Windows PowerShell上使用的

 pip uninstall -y (pip freeze)

For Windows users, this is what I use on Windows PowerShell

 pip uninstall -y (pip freeze)

回答 13

(将此添加为答案,因为我没有足够的声誉来评论@blueberryfields的答案)

@blueberryfields的答案很好用,但如果没有要卸载的软件包则失败(如果此“全部卸载”是脚本或makefile的一部分,则可能是一个问题)。这可以通过xargs -r使用GNU版本的来解决xargs

pip freeze --exclude-editable | xargs -r pip uninstall -y

来自man xargs

-r,–no-run-if-empty

如果标准输入不包含任何非空格,请不要运行该命令。通常,即使没有输入,命令也会运行一次。此选项是GNU扩展。

(adding this as an answer, because I do not have enough reputation to comment on @blueberryfields ‘s answer)

@blueberryfields ‘s answer works well, but fails if there is no package to uninstall (which can be a problem if this “uninstall all” is part of a script or makefile). This can be solved with xargs -r when using GNU’s version of xargs:

pip freeze --exclude-editable | xargs -r pip uninstall -y

from man xargs:

-r, –no-run-if-empty

If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there is no input. This option is a GNU extension.


回答 14

pip3 freeze --local | xargs pip3 uninstall -y

这种情况可能是必须多次运行此命令才能得到一个空的pip3 freeze --local

pip3 freeze --local | xargs pip3 uninstall -y

The case might be that one has to run this command several times to get an empty pip3 freeze --local.


回答 15

这是我卸载所有python软件包的最简单方法。

from pip import get_installed_distributions
from os import system
for i in get_installed_distributions():
    system("pip3 uninstall {} -y -q".format(i.key))

This was the easiest way for me to uninstall all python packages.

from pip import get_installed_distributions
from os import system
for i in get_installed_distributions():
    system("pip3 uninstall {} -y -q".format(i.key))

回答 16

仅使用即可提供跨平台支持pip

#!/usr/bin/env python

from sys import stderr
from pip.commands.uninstall import UninstallCommand
from pip import get_installed_distributions

pip_uninstall = UninstallCommand()
options, args = pip_uninstall.parse_args([
    package.project_name
    for package in
    get_installed_distributions()
    if not package.location.endswith('dist-packages')
])

options.yes = True  # Don't confirm before uninstall
# set `options.require_venv` to True for virtualenv restriction

try:
    print pip_uninstall.run(options, args)
except OSError as e:
    if e.errno != 13:
        raise e
    print >> stderr, "You lack permissions to uninstall this package.
                      Perhaps run with sudo? Exiting."
    exit(13)
# Plenty of other exceptions can be thrown, e.g.: `InstallationError`
# handle them if you want to.

Cross-platform support by using only pip:

#!/usr/bin/env python

from sys import stderr
from pip.commands.uninstall import UninstallCommand
from pip import get_installed_distributions

pip_uninstall = UninstallCommand()
options, args = pip_uninstall.parse_args([
    package.project_name
    for package in
    get_installed_distributions()
    if not package.location.endswith('dist-packages')
])

options.yes = True  # Don't confirm before uninstall
# set `options.require_venv` to True for virtualenv restriction

try:
    print pip_uninstall.run(options, args)
except OSError as e:
    if e.errno != 13:
        raise e
    print >> stderr, "You lack permissions to uninstall this package.
                      Perhaps run with sudo? Exiting."
    exit(13)
# Plenty of other exceptions can be thrown, e.g.: `InstallationError`
# handle them if you want to.

回答 17

这是对我有用的命令:

pip list | awk '{print $1}' | xargs pip uninstall -y

This is the command that works for me:

pip list | awk '{print $1}' | xargs pip uninstall -y

回答 18

跨平台和在pipenv中工作的简单而健壮的方法是:

pip freeze 
pip uninstall -r requirement

通过pipenv:

pipenv run pip freeze 
pipenv run pip uninstall -r requirement

但不会更新piplock或pipfile,因此请注意

the easy robust way cross-platform and work in pipenv as well is:

pip freeze 
pip uninstall -r requirement

by pipenv:

pipenv run pip freeze 
pipenv run pip uninstall -r requirement

but won’t update piplock or pipfile so be aware


回答 19

如果您正在跑步virtualenv

virtualenv --clear </path/to/your/virtualenv>

例如,如果您的virtualenv是/Users/you/.virtualenvs/projectx,那么您将运行:

virtualenv --clear /Users/you/.virtualenvs/projectx

如果您不知道虚拟环境的位置,则可以which python在已激活的虚拟环境中运行以获取路径

If you’re running virtualenv:

virtualenv --clear </path/to/your/virtualenv>

for example, if your virtualenv is /Users/you/.virtualenvs/projectx, then you’d run:

virtualenv --clear /Users/you/.virtualenvs/projectx

if you don’t know where your virtual env is located, you can run which python from within an activated virtual env to get the path


回答 20

就我而言,我意外地使用pip在macOS上安装的Homebrew 在全球范围内安装了许多软件包。恢复默认软件包的最简单方法是:

$ brew reinstall python

或者,如果您使用的是pip3

$ brew reinstall python3

In my case, I had accidentally installed a number of packages globally using a Homebrew-installed pip on macOS. The easiest way to revert to the default packages was a simple:

$ brew reinstall python

Or, if you were using pip3:

$ brew reinstall python3

回答 21

在Windows的Command Shell中,该命令pip freeze | xargs pip uninstall -y将不起作用。因此,对于那些使用Windows的人,我已经找到了一种替代方法。

  1. 将已安装的pip软件包的所有名称从pip freeze命令复制到.txt文件。
  2. 然后,转到您的.txt文件的位置并运行以下命令pip uninstall -r *textfile.txt*

In Command Shell of Windows, the command pip freeze | xargs pip uninstall -y won’t work. So for those of you using Windows, I’ve figured out an alternative way to do so.

  1. Copy all the names of the installed packages of pip from the pip freeze command to a .txt file.
  2. Then, go the location of your .txt file and run the command pip uninstall -r *textfile.txt*

回答 22

如果使用pew,则可以使用擦拭命令:

pew wipeenv [env]

If you are using pew, you can use the wipeenv command:

pew wipeenv [env]


回答 23

我使用–user选项来卸载用户站点中安装的所有软件包。

pip3冻结–user | xargs pip3卸载-y

I use the –user option to uninstall all the packages installed in the user site.

pip3 freeze –user | xargs pip3 uninstall -y


回答 24

Pip无法知道它安装了哪些软件包以及系统的软件包管理器安装了哪些软件包。为此,您需要执行以下操作

对于基于rpm的发行版(将python2.7替换为安装了pip的python版本):

find /usr/lib/python2.7/ |while read f; do
  if ! rpm -qf "$f" &> /dev/null; then
    echo "$f"
  fi
done |xargs rm -fr

对于基于Deb的发行版:

find /usr/lib/python2.7/ |while read f; do
  if ! dpkg-query -S "$f" &> /dev/null; then
    echo "$f"
  fi
done |xargs rm -fr

然后清理剩下的空目录:

find /usr/lib/python2.7 -type d -empty |xargs rm -fr

我发现最重要的答案很容易引起误解,因为它会删除您发行版中的所有(大多数?)python软件包,并可能使您的系统崩溃。

Pip has no way of knowing what packages were installed by it and what packages were installed by your system’s package manager. For this you would need to do something like this

for rpm-based distros (replace python2.7 with your python version you installed pip with):

find /usr/lib/python2.7/ |while read f; do
  if ! rpm -qf "$f" &> /dev/null; then
    echo "$f"
  fi
done |xargs rm -fr

for a deb-based distribution:

find /usr/lib/python2.7/ |while read f; do
  if ! dpkg-query -S "$f" &> /dev/null; then
    echo "$f"
  fi
done |xargs rm -fr

then to clean up empty directories left over:

find /usr/lib/python2.7 -type d -empty |xargs rm -fr

I found the top answer very misleading since it will remove all (most?) python packages from your distribution and probably leave you with a broken system.


使用pip找不到TensorFlow

问题:使用pip找不到TensorFlow

我正在尝试使用pip安装TensorFlow:

$ pip install tensorflow --user
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow

我究竟做错了什么?到目前为止,我使用Python和pip都没有问题。

I’m trying to intstall TensorFlow using pip:

$ pip install tensorflow --user
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow

What am I doing wrong? So far I’ve used Python and pip with no issues.


回答 0

我发现这终于奏效了。

python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py3-none-any.whl

编辑1:已在Windows(8、8.1、10),Mac和Linux上进行了测试。更改python3python根据您的配置。如果使用的是Python 2.x,请更改py3py2url。

编辑2:如果有人需要,列出不同版本:https : //storage.googleapis.com/tensorflow

编辑3:可用车轮包装的URL列表在此处:https : //www.tensorflow.org/install/pip#package-location

I found this to finally work.

python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py3-none-any.whl

Edit 1: This was tested on Windows (8, 8.1, 10), Mac and Linux. Change python3 to python according to your configuration. Change py3 to py2 in the url if you are using Python 2.x.

Edit 2: A list of different versions if someone needs: https://storage.googleapis.com/tensorflow

Edit 3: A list of urls for the available wheel packages is available here: https://www.tensorflow.org/install/pip#package-location


回答 1

您需要Python的64位版本,而您使用的是32位版本。到目前为止,Tensorflow仅64-bit versions of Python 3.5.x and 3.6.x在Windows上支持。请参阅安装文档以了解当前支持什么

要检查您正在运行的Python版本,请键入pythonpython3启动解释器,然后键入import struct;print(struct.calcsize("P") * 8)和将打印3264告诉您您正在运行的Python版本。

来自评论:

要下载适用于Windows的其他版本的Python,请访问python.org/downloads/windows并向下滚动,直到看到所需的版本以“ 64”结尾。那将是应该与tensorflow一起使用的64位版本

You need a 64-bit version of Python and in your case are using a 32-bit version. As of now Tensorflow only supports 64-bit versions of Python 3.5.x and 3.6.x on Windows. See the install docs to see what is currently supported

To check which version of Python you are running, type python or python3 to start the interpreter, and then type import struct;print(struct.calcsize("P") * 8) and that will print either 32 or 64 to tell you which bit version of Python you are running.

From comments:

To download a different version of Python for Windows, go to python.org/downloads/windows and scroll down until you see the version you want that ends in a “64”. That will be the 64 bit version that should work with tensorflow


回答 2

您需要使用正确版本的Python和 pip

在Windows 10(使用Python 3.6.X版本)上,我经过仔细检查后面临着相同的问题,然后发现我在64位计算机上安装了Python-32位。记住TensorFlow 仅与 python的64位安装兼容不是32位的Python

如果我们从python.org下载Python,则默认安装为32位。因此,我们必须手动下载64位安装程序才能安装Python 64位。然后将以下内容添加到PATH环境中。

C:\Users\AppData\Local\Programs\Python\Python36
C:\Users\AppData\Local\Programs\Python\Python36\Scripts

然后gpupdate /Force在命令提示符下运行。如果python命令不适用于64位,请重新启动计算机。

然后在命令提示符下运行python。它应该显示64位

C:\Users\YOURNAME>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

然后运行以下命令以安装tensorflow CPU版本(推荐)

pip3 install --upgrade tensorflow

更新-Python 3.7

目前仅正式支持Python 3.5和Python 3.6。Tensorflow尚未正式发布Python 3.7的二进制文件,我们可能需要稍等片刻才能发布它。您可以暂时使用Python 3.6.x或具有Python <3.7虚拟环境的Anaconda。

You need to use right version of Python and pip

On Windows 10, with Python 3.6.X version I was facing same then after checking deliberately , I noticed I had Python-32 bit installation on my 64 bit machine. Remember TensorFlow is only compatible with 64bit installation of python. Not 32 bit of Python

If we download Python from python.org , the default installation would be 32 bit. So we have to download 64 bit installer manually to install Python 64 bit. And then add below to PATH environment.

C:\Users\AppData\Local\Programs\Python\Python36
C:\Users\AppData\Local\Programs\Python\Python36\Scripts

Then run gpupdate /Force on command prompt. If python command doesnt work for 64 bit restart your machine.

Then run python on command prompt. It should show 64 bit

C:\Users\YOURNAME>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Then run below command to install tensorflow CPU version(recommended)

pip3 install --upgrade tensorflow

Update – Python 3.7

Currently only Python 3.5 and Python 3.6 are supported officially. Tensorflow has not released binaries for Python 3.7 still officially, we might need to wait a little for it to be released. You can use Python 3.6.x alongside or Anaconda with Python<3.7 virtual environment for time being.


回答 3

从tensorflow网站:“您将需要pip版本8.1或更高版本,以下命令才能工作”。运行以下命令以升级您的pip,然后尝试再次安装tensorflow:

pip install --upgrade pip

From tensorflow website: “You will need pip version 8.1 or later for the following commands to work”. Run this command to upgrade your pip, then try install tensorflow again:

pip install --upgrade pip

回答 4

如果您尝试将其安装在Windows计算机上,则需要安装64位版本的python 3.5。这是实际安装它的唯一方法。从网站

TensorFlow在Windows上仅支持64位Python 3.5。我们已经使用以下Python发行版对pip包进行了测试:

Anaconda的Python 3.5

来自python.org的Python 3.5。

您可以从此处下载正确版本的python (确保您抓住显示“ Windows x86-64”的版本之一)

现在,您应该可以使用pip install tensorflow或进行安装python -m pip install tensorflow(如果同时安装了python2和python3,请确保使用的是来自python3的正确点子)

请记住要安装Anaconda 3-5.2.0,因为3-5.3.0的最新版本具有Tensorflow不支持的python 3.7版本。

If you are trying to install it on a windows machine you need to have a 64-bit version of python 3.5. This is the only way to actually install it. From the website:

TensorFlow supports only 64-bit Python 3.5 on Windows. We have tested the pip packages with the following distributions of Python:

Python 3.5 from Anaconda

Python 3.5 from python.org.

You can download the proper version of python from here (make sure you grab one of the ones that says “Windows x86-64”)

You should now be able to install with pip install tensorflow or python -m pip install tensorflow (make sure that you are using the right pip, from python3, if you have both python2 and python3 installed)

Remember to install Anaconda 3-5.2.0 as the latest version which is 3-5.3.0 have python version 3.7 which is not supported by Tensorflow.


回答 5

我发现TensorFlow 1.12.0仅适用于Python版本3.5.2。我有Python 3.7,但没有用。因此,我不得不降级Python,然后可以安装TensorFlow使其工作。

要将python版本从3.7降级到3.6

conda install python=3.6.8

I figured out that TensorFlow 1.12.0 only works with Python version 3.5.2. I had Python 3.7 but that didn’t work. So, I had to downgrade Python and then I could install TensorFlow to make it work.

To downgrade your python version from 3.7 to 3.6

conda install python=3.6.8

回答 6

2016年11月28日更新:从0.12版开始,PyPI中现已提供TensorFlow。您可以输入

pip install tensorflow

…要么…

pip install tensorflow-gpu

…分别安装仅CPU或GPU加速的TensorFlow版本。


先前的答案: TensorFlow尚未存在于PyPI存储库中,因此您必须为操作系统和Python版本指定适当的“ wheel文件”的URL。

TensorFlow网站上列出了受支持的配置的完整列表,但是例如,要仅使用CPU在Linux上为Python 2.7安装版本0.10,您可以键入以下命令:

$ pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0rc0-cp27-none-linux_x86_64.whl

Updated 11/28/2016: TensorFlow is now available in PyPI, starting with release 0.12. You can type

pip install tensorflow

…or…

pip install tensorflow-gpu

…to install the CPU-only or GPU-accelerated version of TensorFlow respectively.


Previous answer: TensorFlow is not yet in the PyPI repository, so you have to specify the URL to the appropriate “wheel file” for your operating system and Python version.

The full list of supported configurations is listed on the TensorFlow website, but for example, to install version 0.10 for Python 2.7 on Linux, using CPU only, you would type the following command:

$ pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0rc0-cp27-none-linux_x86_64.whl

回答 7

在此处安装Python 3.5.x 64位AMD版本。确保将Python添加到PATH变量中。然后打开命令提示符并键入

python -m pip install --upgrade pip

应该给您以下结果:

 Collecting pip
 Using cached pip-9.0.1-py2.py3-none-any.whl
 Installing collected packages: pip
 Found existing installation: pip 7.1.2
 Uninstalling pip-7.1.2:
 Successfully uninstalled pip-7.1.2
 Successfully installed pip-9.0.1

现在输入

 pip3 install --upgrade tensorflow

Install Python 3.5.x 64 bit amd version here. Make sure you add Python to your PATH variable. Then open a command prompt and type

python -m pip install --upgrade pip

should give you the following result :

 Collecting pip
 Using cached pip-9.0.1-py2.py3-none-any.whl
 Installing collected packages: pip
 Found existing installation: pip 7.1.2
 Uninstalling pip-7.1.2:
 Successfully uninstalled pip-7.1.2
 Successfully installed pip-9.0.1

Now type

 pip3 install --upgrade tensorflow

回答 8

我有同样的问题,并解决了这个问题:

# Ubuntu/Linux 64-bit, CPU only, Python 2.7
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl

# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7
# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.

# Mac OS X, CPU only, Python 2.7:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl

# Mac OS X, GPU enabled, Python 2.7:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py2-none-any.whl

# Ubuntu/Linux 64-bit, CPU only, Python 3.4
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp34-cp34m-linux_x86_64.whl

# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4
# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp34-cp34m-linux_x86_64.whl

# Ubuntu/Linux 64-bit, CPU only, Python 3.5
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp35-cp35m-linux_x86_64.whl

# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp35-cp35m-linux_x86_64.whl

# Mac OS X, CPU only, Python 3.4 or 3.5:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py3-none-any.whl

# Mac OS X, GPU enabled, Python 3.4 or 3.5:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py3-none-any.whl

加:

# Python 2
(tensorflow)$ pip install --upgrade $TF_BINARY_URL

# Python 3
(tensorflow)$ pip3 install --upgrade $TF_BINARY_URL

Docs上找到。

更新!

新版本的新链接

例如,要在OSX中安装tensorflow v1.0.0,您需要使用:

https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.0.0-py2-none-any.whl

代替

https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl

I had the same problem and solved with this:

# Ubuntu/Linux 64-bit, CPU only, Python 2.7
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl

# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7
# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.

# Mac OS X, CPU only, Python 2.7:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl

# Mac OS X, GPU enabled, Python 2.7:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py2-none-any.whl

# Ubuntu/Linux 64-bit, CPU only, Python 3.4
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp34-cp34m-linux_x86_64.whl

# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4
# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp34-cp34m-linux_x86_64.whl

# Ubuntu/Linux 64-bit, CPU only, Python 3.5
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp35-cp35m-linux_x86_64.whl

# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp35-cp35m-linux_x86_64.whl

# Mac OS X, CPU only, Python 3.4 or 3.5:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py3-none-any.whl

# Mac OS X, GPU enabled, Python 3.4 or 3.5:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py3-none-any.whl

Plus:

# Python 2
(tensorflow)$ pip install --upgrade $TF_BINARY_URL

# Python 3
(tensorflow)$ pip3 install --upgrade $TF_BINARY_URL

Found on Docs.

UPDATE!

There are new links for new versions

For example, for installing tensorflow v1.0.0 in OSX you need to use:

https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.0.0-py2-none-any.whl

instead of

https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl

回答 9

尝试在Mac上安装(使用Python 2.7)时出现相同的错误。根据Yash Kumar Verma在此页面上给出的不同答案,与我在此处提供的解决方案类似的解决方案似乎也适用于Windows 8.1上的Python 3。

步骤1:前往TensorFlow安装页面的TensorFlow Python软件包的URL部分,并复制与您的Python安装相关的链接的URL。

步骤2:打开终端/命令提示符并运行以下命令:
pip install --upgrade [paste copied url link here]

所以对我来说是这样的:
pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.0-py2-none-any.whl

更新(2017年7月21日):我与其他在运行Windows 3.6且使用Python 3.6的计算机上进行了尝试,他们不得不将步骤2中的行更改为: python -m pip install [paste copied url link here]

更新(2018年7月26日):对于Python 3.6.2(不是3.7,因为它在TF文档中的3.6.2中),您也可以pip3 install --upgrade [paste copied URL here]步骤2中使用。

I had the same error when trying to install on my Mac (using Python 2.7). A similar solution to the one I’m giving here also seemed to work for Python 3 on Windows 8.1 according to a different answer on this page by Yash Kumar Verma

Solution

Step 1: go to The URL of the TensorFlow Python package section of the TensorFlow installation page and copy the URL of the relevant link for your Python installation.

Step 2: open a terminal/command prompt and run the following command:
pip install --upgrade [paste copied url link here]

So for me it was the following:
pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.0-py2-none-any.whl

Update (July 21 2017): I tried this with some others who were running on Windows machines with Python 3.6 and they had to change the line in Step 2 to: python -m pip install [paste copied url link here]

Update (26 July 2018): For Python 3.6.2 (not 3.7 because it’s in 3.6.2 in TF Documentation), you can also use pip3 install --upgrade [paste copied URL here] in Step 2.


回答 10

试试这个,它应该可以工作:

 python.exe -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

Try this, it should work:

 python.exe -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

回答 11

尝试这个:

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py3-none-any.whl
pip3 install --upgrade $TF_BINARY_URL

来源:https//www.tensorflow.org/get_started/os_setup(页面不再存在)

更新2/23/17 文档已移至:https : //www.tensorflow.org/install

Try this:

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py3-none-any.whl
pip3 install --upgrade $TF_BINARY_URL

Source: https://www.tensorflow.org/get_started/os_setup (page no longer exists)

Update 2/23/17 Documentation moved to: https://www.tensorflow.org/install


回答 12

  1. 通过选中将Python添加到路径来安装python
  2. pip3 install –upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

这适用于Windows 10.0

  1. Install python by checking Add Python to Path
  2. pip3 install –upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

This works for windows 10.0


回答 13

如果您最近遇到过此问题(例如,在2018年发布Python 3.7之后),则很可能是由于tensorflow方面缺少Python 3.7支持所致。如果您不介意,请尝试使用Python 3.6。您可以从https://github.com/tensorflow/tensorflow/issues/20444中找到一些技巧,但使用这些技巧需要您自担风险。我使用了建议的一个竖琴-首先下载了适用于Python 3.6的tensorflow轮,然后手动将其重命名…

cp tensorflow-1.11.0-cp36-cp36m-linux_x86_64.whl tensorflow-1.11.0-cp37-cp37m-linux_x86_64.whl
pip install tensorflow-1.11.0-cp37-cp37m-linux_x86_64.whl

好消息是已经有对3.7支持的请求。希望它将尽快发布。

If you run into this issue recently (say, after Python 3.7 release in 2018), most likely this is caused by the lack of Python 3.7 support (yet) from the tensorflow side. Try using Python 3.6 instead if you don’t mind. There are some tricks you can find from https://github.com/tensorflow/tensorflow/issues/20444, but use them at your own risk. I used the one harpone suggested – first downloaded the tensorflow wheel for Python 3.6 and then renamed it manually…

cp tensorflow-1.11.0-cp36-cp36m-linux_x86_64.whl tensorflow-1.11.0-cp37-cp37m-linux_x86_64.whl
pip install tensorflow-1.11.0-cp37-cp37m-linux_x86_64.whl

The good news is that there is a pull request for 3.7 support already. Hope it will be released soon.


回答 14

我有同样的问题。在卸载了32位版本的python并重新安装了64位版本之后,我尝试重新安装TensorFlow并成功了。

链接到TensorFlow指南:https ://www.tensorflow.org/install/install_windows

I had the same problem. After uninstalling the 32-bit version of python and reinstalling the 64-bit version I tried reinstalling TensorFlow and it worked.

Link to TensorFlow guide: https://www.tensorflow.org/install/install_windows


回答 15

如果您试图在anaconda中安装tensorflow并且它无法正常工作,则您可能需要降级python版本,因为只有3.6.xanaconda具有最新版本时才支持python 版本。

  1. 检查python版本: python --version

  2. 如果版本>,3.6.x然后执行步骤3,否则请停止,问题可能出在其他地方

  3. conda search python

  4. conda install python=3.6.6

  5. 再次检查版本: python --version

  6. 如果版本正确,请安装tensorflow(步骤7)

  7. pip install tensorflow

If you’re trying to install tensorflow in anaconda and it isn’t working, then you may need to downgrade python version because only 3.6.x is currently supported while anaconda has the latest version.

  1. check python version: python --version

  2. if version > 3.6.x then follow step 3, otherwise stop, the problem may be somewhere else

  3. conda search python

  4. conda install python=3.6.6

  5. Check version again: python --version

  6. If version is correct, install tensorflow (step 7)

  7. pip install tensorflow


回答 16

如果您正在使用Anaconda Python安装,pip install tensorflow将给出上述错误,如下所示:

Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow

根据TensorFlow安装页面,--ignore-installed在运行pip install时需要使用该标志。

但是,在执行此操作之前,请先查看此链接, 以确保相对于希望安装的TensorFlow所需版本正确设置了TF_BINARY_URL变量。

If you are using the Anaconda Python installation, pip install tensorflow will give the error stated above, shown below:

Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow

According to the TensorFlow installation page, you will need to use the --ignore-installed flag when running pip install.

However, before this can be done see this link to ensure the TF_BINARY_URL variable is set correctly in relation to the desired version of TensorFlow that you wish to install.


回答 17

不幸的是,我的声誉是在@Sujoy答案下无法控制的。

他们在文档中声称支持python 3.6。@mayur提供的链接表明它们确实只是一个python3.5 wheel软件包。这是我尝试安装tensorflow:

Microsoft Windows [Version 10.0.16299.371]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\>python3 -m pip install --upgrade pip
Requirement already up-to-date: pip in d:\python\v3\lib\site-packages (10.0.0)

C:\>python3 -m pip -V
pip 10.0.0 from D:\Python\V3\lib\site-packages\pip (python 3.6)

C:\>python3 -m pip install --upgrade tensorflow
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow

而python 3.5似乎已成功安装。我希望看到一个python3.6版本,因为他们声称它也可以在python3.6上运行。

引用:

"TensorFlow supports Python 3.5.x and 3.6.x on Windows. Note that Python 3 comes with the pip3 package manager, which is the program you'll use to install TensorFlow."

来源:https : //www.tensorflow.org/install/install_windows

Python3.5安装:

Microsoft Windows [Version 10.0.16299.371]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\>python3 -m pip install --upgrade pip
Requirement already up-to-date: pip in d:\python\v3\lib\site-packages (10.0.0)

C:\>python3 -m pip -V
pip 10.0.0 from D:\Python\V3_5\lib\site-packages\pip (python 3.5.2)

C:\>python3 -m pip install --upgrade tensorflow
Collecting tensorflow
  Downloading 
    ....
    ....

我希望我在这里错得很厉害,但是如果不敲响警钟😛

编辑:有人下面的几篇文章指出以下命令将起作用,并且确实起作用。

python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

奇怪的点不起作用🤔

Unfortunately my reputation is to low to command underneath @Sujoy answer.

In their docs they claim to support python 3.6. The link provided by @mayur shows that their is indeed only a python3.5 wheel package. This is my try to install tensorflow:

Microsoft Windows [Version 10.0.16299.371]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\>python3 -m pip install --upgrade pip
Requirement already up-to-date: pip in d:\python\v3\lib\site-packages (10.0.0)

C:\>python3 -m pip -V
pip 10.0.0 from D:\Python\V3\lib\site-packages\pip (python 3.6)

C:\>python3 -m pip install --upgrade tensorflow
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow

while python 3.5 seems to install successfully. I would love to see a python3.6 version since they claim it should also work on python3.6.

Quoted :

"TensorFlow supports Python 3.5.x and 3.6.x on Windows. Note that Python 3 comes with the pip3 package manager, which is the program you'll use to install TensorFlow."

Source : https://www.tensorflow.org/install/install_windows

Python3.5 install :

Microsoft Windows [Version 10.0.16299.371]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\>python3 -m pip install --upgrade pip
Requirement already up-to-date: pip in d:\python\v3\lib\site-packages (10.0.0)

C:\>python3 -m pip -V
pip 10.0.0 from D:\Python\V3_5\lib\site-packages\pip (python 3.5.2)

C:\>python3 -m pip install --upgrade tensorflow
Collecting tensorflow
  Downloading 
    ....
    ....

I hope i am terrible wrong here but if not ring a alarm bell 😛

Edit: A couple of posts below someone pointed out that the following command would work and it did.

python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

Strange pip is not working 🤔


回答 18

在Mac OS X Yosemite 10.10.5上的Python 2.7中,这对我有用:

sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl

This worked for me with Python 2.7 on Mac OS X Yosemite 10.10.5:

sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl

回答 19

这个问题有多组答案。该答案旨在概括一组答案:

可能没有与您的Python版本兼容的TensorFlow版本。如果您正在使用新版本的Python,则尤其如此。例如,在新版本的Python发行与该版本的Python的TensorFlow发行之间可能会有延迟。

在这种情况下,我相信您的选择是:1)降级到Python的先前版本。2)从源代码编译TensorFlow。3)等待TensorFlow的匹配版本。

There are multiple groups of answers to this question. This answer aims to generalize one group of answers:

There may not be a version of TensorFlow that is compatible with your version of Python. This is particularly true if you’re using a new release of Python. For example, there may be a delay between the release of a new version of Python and the release of TensorFlow for that version of Python.

In this case, I believe your options are to: 1) Downgrade to the previous version of Python. 2) Compile TensorFlow from the source code. 3) Wait for a matching version of TensorFlow.


回答 20

对于Windows,这对我有用

从此链接下载车轮。然后从命令行导航到存在转轮的下载文件夹,只需键入以下命令-

pip install tensorflow-1.0.0-cp36-cp36m-win_amd64.whl

For windows this worked for me,

Download the wheel from this link. Then from command line navigate to your download folder where the wheel is present and simply type in the following command –

pip install tensorflow-1.0.0-cp36-cp36m-win_amd64.whl


回答 21

我面临着同样的问题。我尝试了以下方法,它奏效了。为Mac OS X安装,anaconda python 2.7

pip uninstall tensorflow export TF_BINARY_URL=<get the correct url from http://tflearn.org/installation/> pip install --upgrade $TF_BINARY_URL

安装了tensorflow-1.0.0

I was facing the same issue. I tried the following and it worked. installing for Mac OS X, anaconda python 2.7

pip uninstall tensorflow export TF_BINARY_URL=<get the correct url from http://tflearn.org/installation/> pip install --upgrade $TF_BINARY_URL

Installed tensorflow-1.0.0


回答 22

  1. 具有管理权限启动命令提示符
  2. 输入以下命令 python -m pip install --upgrade pip
  3. 下一步输入命令 pip install tensorflow
  1. Start Command Prompt with Administrative Permission
  2. Enter following command python -m pip install --upgrade pip
  3. Next Enter command pip install tensorflow

回答 23

下面是在Windows中安装TensorFlow的URL。对我来说很好。

python -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

The URL to install TensorFlow in Windows, below is the URL. It worked fine for me.

python -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

回答 24

在Windows 10上,这里没有任何内容适合我。也许下面的更新解决方案对我有用。

python -m pip install --upgrade tensorflow

这在Windows 10上使用Python 3.6tensorflow 1.5

Nothing here worked for me on Windows 10. Perhaps an updated solution below that did work for me.

python -m pip install --upgrade tensorflow.

This is using Python 3.6 and tensorflow 1.5 on Windows 10


回答 25

对于pyCharm用户:

  1. 检查pip版本: pip3 -V
  2. 如果pip早于9.0.1: py -3 -m pip install –upgrade pip
  3. 然后:** py -3 -m pip install –upgrade

https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl **

For pyCharm users:

  1. Check pip version: pip3 -V
  2. If pip is older than 9.0.1: py -3 -m pip install –upgrade pip
  3. Then: **py -3 -m pip install –upgrade

https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl**


回答 26

以下步骤允许您安装tensorflow和keras

  1. https://repo.anaconda.com/archive/下载python 3.6随附的Anaconda3-5.2.0
  2. 安装Anaconda并打开Anaconda Prompt并执行以下命令 conda install jupyter conda install scipy pip install sklearn pip install msgpack pip install pandas pip install pandas-datareader pip install matplotlib pip install pillow pip install requests pip install h5py pip install tensorflow pip install keras

Following steps allows you to install tensorflow and keras

  1. downloading Anaconda3-5.2.0 which comes with python 3.6 from https://repo.anaconda.com/archive/
  2. Install Anaconda and open Anaconda Prompt and execute below commands conda install jupyter conda install scipy pip install sklearn pip install msgpack pip install pandas pip install pandas-datareader pip install matplotlib pip install pillow pip install requests pip install h5py pip install tensorflow pip install keras

回答 27

2019年更新:要在Google Colab中安装TensorFlow 2预览版,可以使用:

!wget https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda-repo-ubuntu1604-10-0-local-10.0.130-410.48_1.0-1_amd64 -O cuda-repo-ubuntu1604-10-0-local-10.0.130-410.48_1.0-1_amd64.deb !dpkg -i cuda-repo-ubuntu1604-10-0-local-10.0.130-410.48_1.0-1_amd64.deb !apt-key add /var/cuda-repo-10-0-local-10.0.130-410.48/7fa2af80.pub !apt-get update !apt-get install cuda !pip install tf-nightly-gpu-2.0-preview

对于安装TensorFlow 2 bye pip,您可以使用: pip install tf-nightly-gpu-2.0-preview用于GPU和 pip install tf-nightly-2.0-preview CPU。

update 2019: for install the preview version of TensorFlow 2 in Google Colab you can use:

!wget https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda-repo-ubuntu1604-10-0-local-10.0.130-410.48_1.0-1_amd64 -O cuda-repo-ubuntu1604-10-0-local-10.0.130-410.48_1.0-1_amd64.deb !dpkg -i cuda-repo-ubuntu1604-10-0-local-10.0.130-410.48_1.0-1_amd64.deb !apt-key add /var/cuda-repo-10-0-local-10.0.130-410.48/7fa2af80.pub !apt-get update !apt-get install cuda !pip install tf-nightly-gpu-2.0-preview

and for install the TensorFlow 2 bye pip you can use : pip install tf-nightly-gpu-2.0-preview for GPU and pip install tf-nightly-2.0-preview for CPU.


回答 28

我在OSX Sierra 10.12.2上遇到了这个问题。原来我安装了错误的Python版本(我安装了Python 3.4,但OSX的tensorflow pypi软件包仅适用于python 3.5及更高版本)。

解决方案是安装Python 3.6。这是我为使其正常工作所做的。注意:我使用Homebrew来安装Python 3.6,您可以通过在python.org上使用Python 3.6安装程序来做同样的事情

brew uninstall python3
brew install python3
python3 --version # Verify that you see "Python 3.6.0"
pip install tensorflow # With python 3.6 the install succeeds
pip install jupyter # "ipython notebook" didn't work for me until I installed jupyter
ipython notebook # Finally works!

I had this problem on OSX Sierra 10.12.2. It turns out I had the wrong version of Python installed (I had Python 3.4 but tensorflow pypi packages for OSX are only for python 3.5 and up).

The solution was to install Python 3.6. Here’s what I did to get it working. Note: I used Homebrew to install Python 3.6, you could do the same by using the Python 3.6 installer on python.org

brew uninstall python3
brew install python3
python3 --version # Verify that you see "Python 3.6.0"
pip install tensorflow # With python 3.6 the install succeeds
pip install jupyter # "ipython notebook" didn't work for me until I installed jupyter
ipython notebook # Finally works!

回答 29

摘自tensorflow网站 https://www.tensorflow.org/install/install_windows

使用本机pip安装

如果您的计算机上未安装以下版本的Python,请立即安装:

python.org中的Python 3.5.x TensorFlow在Windows上仅支持Python的3.5.x版本。请注意,Python 3.5.x随附pip3软件包管理器,这是您将用于安装TensorFlow的程序。

要安装TensorFlow,请启动终端。然后在该终端中发出适当的pip3 install命令。要安装TensorFlow的仅CPU版本,请输入以下命令:

C:\> pip3 install --upgrade tensorflow
To install the GPU version of TensorFlow, enter the following command:

C:\> pip3 install --upgrade tensorflow-gpu

Excerpt from tensorflow website https://www.tensorflow.org/install/install_windows

Installing with native pip

If the following version of Python is not installed on your machine, install it now:

Python 3.5.x from python.org TensorFlow only supports version 3.5.x of Python on Windows. Note that Python 3.5.x comes with the pip3 package manager, which is the program you’ll use to install TensorFlow.

To install TensorFlow, start a terminal. Then issue the appropriate pip3 install command in that terminal. To install the CPU-only version of TensorFlow, enter the following command:

C:\> pip3 install --upgrade tensorflow
To install the GPU version of TensorFlow, enter the following command:

C:\> pip3 install --upgrade tensorflow-gpu

如何使用Python 3安装pip?

问题:如何使用Python 3安装pip?

我要安装pip。它应支持Python 3,但需要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?


回答 0

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

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

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

如果您正在运行类似Unix的系统

pip如果您的Python版本低于2.7.9或3.4,或者您的系统出于任何原因未包含该软件包,通常可以通过软件包管理器进行安装。

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

在适用于Python 2.x的Debian(Wheezy和更高版本)和Ubuntu(Trusty Tahr和更高版本)上安装

从终端运行以下命令:

sudo apt-get install python-pip 

在适用于Python 3.x的Debian(Wheezy和更高版本)和Ubuntu(Trusty Tahr和更高版本)上安装

从终端运行以下命令:

sudo apt-get install python3-pip
注意:

在全新安装的Debian / Ubuntu中,只有在执行以下操作后才能找到该软件包:

sudo apt-get update

pip在适用于Python 2.x的CentOS 7上安装

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

sudo yum install python-setuptools
sudo easy_install pip

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

假设您从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发行版未在软件包repos中包含它

使用下面详细介绍的手动方法进行安装。

手动方式

如果您想手动进行操作,现在推荐的方法是使用安装说明中get-pip.py脚本进行pip安装

安装点子

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

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

python get-pip.py 

如果setuptools尚未安装,get-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.


回答 1

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

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


回答 2

Python 3.4以上和Python 2.7.9以上

好消息!Pip随附了Python 3.4(2014年3月发布)。这是所有Python版本中的最佳功能。它使每个人都可以访问社区丰富的图书馆。新手不再因安装的困难而被排除在外。在与软件包管理器一起交付时,Python加入了Ruby,Nodejs,Haskell,Perl,Go以及几乎所有其他具有主流开源社区的当代语言。谢谢Python。

当然,这并不意味着Python打包已解决问题。经验仍然令人沮丧。我在Python是否有软件包/模块管理系统中讨论了这一点

las惜使用早期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

对我来说,此安装点位于C:\Python27\Scripts\pip.exepip.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)!


回答 3

对于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

回答 4

如果您使用的是python 3.4+

只需输入:

python3 -m pip

if you’re using python 3.4+

just type:

python3 -m pip

回答 5

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

回答 6

系统中的单个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

如何找到您的python3命令产生的python :

ganesh@Ganesh:~$ python3 # Type in terminal
Python 3.6.6 (default, Sep 12 2018, 18:26:19) # Your python3 version
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

注意第二行中的python 3.6.6

笔记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

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, your python3 command spawns:

ganesh@Ganesh:~$ python3 # Type in terminal
Python 3.6.6 (default, Sep 12 2018, 18:26:19) # Your python3 version
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Notice python 3.6.6 in the second line.

Note 2

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


回答 7

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.


回答 8

旧版的Homebrew

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

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(尽管这仅是小桶,因此默认情况下,不将python和python2添加到PATH中,而无需手动冲泡链接–force)。我们将维护python2,python3和python @ 3别名。

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

brew install python3

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

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


回答 9

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

具有pip针对每个本地环境的优势。

然后通过以下方式在当前目录中安装本地环境:

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

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

然后在该文件夹中有一个本地pythonenvironment。 ./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.


回答 10

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


回答 11

这就是我在OS X Mavericks上所做的工作,以使其正常工作。

首先,冲泡安装了

安装python 3.4

brew install python3

然后,我得到了最新版本的distribution:

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.


回答 12

Python 3.4新增功能

点子应该总是可用

默认情况下,命令pipX和pipX.Y将连同pip Python软件包及其依赖项一起安装在所有平台上(其中XY代表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


回答 13

对于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


回答 14

假设您处于高度受限的计算机环境中(例如我本人),而没有root访问权限或无法安装软件包…

在发布本文之前,我从未设置过Python / virtualenv的新/独立/原始/非根实例。我已经做了很多谷歌搜索工作。

  1. 确定您使用的是python(python2)还是python3,并正确设置PATH。(我严格是python3用户。)如果您是python2用户python3python则下面的所有命令都可以代替。
  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
    • 假设您使用的是兼容Bourne的外壳,例如bash
    • 出色的是,此virtualenv软件包包括的独立版本,pip并且setuptools会自动神奇地安装到每个新的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

然后…点,点,点!

给新手Pythoneers的最后提示:开始时您不需要虚拟环境,但是以后会很高兴的。帮助开源/共享软件包的“假设情况”安装/升级方案。

参考: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


回答 15

pip在您安装Python时一起安装。您可以使用 sudo pip install (module)python3 -m pip install (module)

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


回答 16

要安装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


回答 17

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

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

然后

只需这样写:pip3 install{软件包名称}

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

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


回答 18

如果您的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软件包管理器(Python 2.x)

sudo pacman -S python2-pip

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

回答 19

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

步骤1:从此处下载安装Python

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

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

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

步骤5:Pip安装成功,通过cmd中的type命令验证pip安装 pip --version

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


回答 20

这是我复制粘贴的单线。

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

使用get-pip.py安装

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

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

然后在下载了get-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

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.


如何从虚拟环境内部更新点子本身?

问题:如何从虚拟环境内部更新点子本身?

我可以更新点子管理的软件包,但是如何更新点子本身?据介绍pip --version,我目前在virtualenv中安装了pip 1.1,我想更新到最新版本。

这是什么命令?我需要使用distribute还是本机pip或virtualenv命令?我已经尝试过pip update,并pip update pip没有成功。

I’m able to update pip-managed packages, but how do I update pip itself? According to pip --version, I currently have pip 1.1 installed in my virtualenv and I want to update to the latest version.

What’s the command for that? Do I need to use distribute or is there a native pip or virtualenv command? I’ve already tried pip update and pip update pip with no success.


回答 0

pip仅仅是一个的PyPI包像任何其他; 您可以像升级任何软件包一样使用它来升级自身:

pip install --upgrade pip

在Windows上,推荐的命令是:

python -m pip install --upgrade pip

pip is just a PyPI package like any other; you could use it to upgrade itself the same way you would upgrade any package:

pip install --upgrade pip

On Windows the recommended command is:

python -m pip install --upgrade pip

回答 1

更安全的方法是通过python模块运行pip

python -m pip install -U pip

在Windows上,尝试替换自身的二进制文件似乎存在问题,此方法可解决该限制。

The more safe method is to run pip though a python module:

python -m pip install -U pip

On windows there seem to be a problem with binaries that try to replace themselves, this method works around that limitation.


回答 2

就我而言,我的pip版本已损坏,因此更新本身无法进行。

固定:

(inside virtualenv):easy_install -U pip

In my case my pip version was broken so the update by itself would not work.

Fix:

(inside virtualenv):easy_install -U pip

回答 3

我在Debian Jessie下尝试了上面提到的所有这些解决方案。它们不起作用,因为它只需要由debian软件包管理器编译的最新版本1.5.6相当于6.0.x版本。某些使用pip作为前提条件的软件包将无法正常运行,例如spaCy(需要使用–no-cache-dir选项才能正常运行)。

因此,解决这些问题的实际最佳方法是运行从wget下载的get-pip.py,它是从网站或使用curl进行的,如下所示:

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

这将安装当前版本,在编写此解决方案时为9.0.1,这远远超出了Debian提供的功能。

 $ pip --version
 pip 9.0.1 from /home/myhomedir/myvirtualenvdir/lib/python2.7/dist-packages (python 2.7)
 $ pip3 --version
 pip 9.0.1 from /home/myhomedir/myvirtualenvdir/lib/python3.4/site-packages (python 3.4)

I tried all of these solutions mentioned above under Debian Jessie. They don’t work, because it just takes the latest version compile by the debian package manager which is 1.5.6 which equates to version 6.0.x. Some packages that use pip as prerequisites will not work as a results, such as spaCy (which needs the option –no-cache-dir to function correctly).

So the actual best way to solve these problems is to run get-pip.py downloaded using wget, from the website or using curl as follows:

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

This will install the current version which at the time of writing this solution is 9.0.1 which is way beyond what Debian provides.

 $ pip --version
 pip 9.0.1 from /home/myhomedir/myvirtualenvdir/lib/python2.7/dist-packages (python 2.7)
 $ pip3 --version
 pip 9.0.1 from /home/myhomedir/myvirtualenvdir/lib/python3.4/site-packages (python 3.4)

回答 4

由于可怕的证书问题,使用’ pip install –upgrade pip ‘ 升级pip 并不总是有效:确认ssl证书时出现问题:[SSL:TLSV1_ALERT_PROTOCOL_VERSION] tlsv1警报协议版本

我喜欢对虚拟环境使用单行命令:

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

或者,如果您想将其安装在宽盒中,则需要

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

如果要在自动化脚本中运行时使输出静音,则可以给curl -s标志。

Upgrading pip using ‘pip install –upgrade pip‘ does not always work because of the dreaded cert issue: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version

I like to use the one line command for virtual envs:

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

Or if you want to install it box wide you will need

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

you can give curl a -s flag if you want to silence the output when running in an automation script.


回答 5

就我而言,这是从Debian Stable中的终端命令行执行的

python3 -m pip install --upgrade pip

In my case this worked from the terminal command line in Debian Stable

python3 -m pip install --upgrade pip

回答 6

为了使它对我有用,我必须使用Python命令提示符(在VS CODE的WIN10上)在Python目录中进行深入研究。就我而言,它位于我的“ AppData \ Local \ Programs \ Python \ python35-32”目录中。从现在开始,我执行命令…

python -m pip install --upgrade pip

这很有效,我很好。

To get this to work for me I had to drill down in the Python directory using the Python command prompt (on WIN10 from VS CODE). In my case it was in my “AppData\Local\Programs\Python\python35-32” directory. From there now I ran the command…

python -m pip install --upgrade pip

This worked and I’m good to go.


回答 7

使用管理员权限打开命令提示符,然后重复以下命令:

python -m pip install --upgrade pip

Open Command Prompt with Administrator Permissions, and repeat the command:

python -m pip install --upgrade pip

回答 8

pip版本10有问题。它将显示为错误:

ubuntu@mymachine-:~/mydir$ sudo pip install --upgrade pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

解决方案是在要升级的venv中,然后运行:

sudo myvenv/bin/pip install --upgrade pip

而不只是

sudo pip install --upgrade pip

pip version 10 has an issue. It will manifest as the error:

ubuntu@mymachine-:~/mydir$ sudo pip install --upgrade pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

The solution is to be in the venv you want to upgrade and then run:

sudo myvenv/bin/pip install --upgrade pip

rather than just

sudo pip install --upgrade pip

回答 9

如果您使用venv,则任何更新到pip的安装都将导致升级系统pip,而不是venv pip。您还需要升级pip引导程序包。

  python3 -m pip install --upgrade pip setuptools wheel

In case you are using venv any update to pip install will result in upgrading the system pip instead of the venv pip. You need to upgrade the pip bootstrapping packages as well.

  python3 -m pip install --upgrade pip setuptools wheel

回答 10

我已经在C:\ Python \ Python36中安装了Python,因此转到Windows命令提示符并键入“ cd C:\ Python \ Python36”以获取正确的目录。然后输入“ python -m install –upgrade pip”全部好!

I had installed Python in C:\Python\Python36 so I went to the Windows command prompt and typed “cd C:\Python\Python36 to get to the right directory. Then entered the “python -m install –upgrade pip” all good!


回答 11

在Windows 7笔记本电脑上,正确安装最新版本的pip的正确方法是:

python.exe -m pip install --upgrade pip

On my lap-top with Windows 7 the right way to install latest version of pip is:

python.exe -m pip install --upgrade pip

回答 12

单行Python程序
我发现的最好方法是编写一个单行程序,该程序可以下载并运行官方的get-pip脚本。参见下面的代码。

官方文档建议使用curl下载get-pip脚本,但是由于我在Windows上工作且未安装curl,因此我更喜欢使用python本身来下载和运行脚本。

这是可以使用Python 3通过命令行运行的单行程序:

python -c "import urllib.request; exec(urllib.request.urlopen('https://bootstrap.pypa.io/get-pip.py').read())"

根据安装说明,该行将获取官方的“ get-pip.py”脚本,并使用“ exec”命令执行该脚本。

对于Python2,您可以将“ urllib.request”替换为“ urllib2”:

python -c "import urllib2; exec(urllib2.urlopen('https://bootstrap.pypa.io/get-pip.py').read())"

预防措施
值得注意的是,盲目运行任何python脚本本质上都是危险的。因此,官方说明建议在运行之前下载脚本并进行检查。

就是说,许多人实际上并不检查代码,而只是运行它。这一单行程序使这一过程变得更加容易。

Single Line Python Program
The best way I have found is to write a single line program that downloads and runs the official get-pip script. See below for the code.

The official docs recommend using curl to download the get-pip script, but since I work on windows and don’t have curl installed I prefer using python itself to download and run the script.

Here is the single line program that can be run via the command line using Python 3:

python -c "import urllib.request; exec(urllib.request.urlopen('https://bootstrap.pypa.io/get-pip.py').read())"

This line gets the official “get-pip.py” script as per the installation notes and executes the script with the “exec” command.

For Python2 you would replace “urllib.request” with “urllib2”:

python -c "import urllib2; exec(urllib2.urlopen('https://bootstrap.pypa.io/get-pip.py').read())"

Precautions
It’s worth noting that running any python script blindly is inherently dangerous. For this reason, the official instructions recommend downloading the script and inspecting it before running.

That said, many people don’t actually inspect the code and just run it. This one-line program makes that easier.


回答 13

我在树莓派上遇到了类似的问题。

问题在于http需要SSL,因此我需要强制它使用https来解决此要求。

sudo pip install --upgrade pip --index-url=https://pypi.python.org/simple

要么

sudo pip-3.2 --upgrade pip --index-url=https://pypi.python.org/simple/

I had a similar problem on a raspberry pi.

The problem was that http requires SSL and so I needed to force it to use https to get around this requirement.

sudo pip install --upgrade pip --index-url=https://pypi.python.org/simple

or

sudo pip-3.2 --upgrade pip --index-url=https://pypi.python.org/simple/

回答 14

我处于类似情况,想更新urllib3软件包。对我有用的是:

pip3 install --upgrade --force-reinstall --ignore-installed urllib3==1.25.3

I was in a similar situation and wanted to update urllib3 package. What worked for me was:

pip3 install --upgrade --force-reinstall --ignore-installed urllib3==1.25.3

回答 15

很简单。只需从https://bootstrap.pypa.io/get-pip.py下载pip 。将文件保存在forlder或dekstop中。我将文件保存在D盘中,然后从命令提示符导航到下载pip的文件夹。然后在那打

python -get-pip.py

Very Simple. Just download pip from https://bootstrap.pypa.io/get-pip.py . Save the file in some forlder or dekstop. I saved the file in my D drive.Then from your command prompt navigate to the folder where you have downloaded pip. Then type there

python -get-pip.py


我可以强迫pip重新安装当前版本吗?

问题:我可以强迫pip重新安装当前版本吗?

我遇到过以下情况:当前版本的软件包似乎无法正常工作,需要重新安装。但是,pip install -U不要触摸已经是最新的软件包。我看到了如何通过先卸载(使用pip uninstall)然后安装来强制进行重新安装,但是有没有办法在一个步骤中简单地将“更新”强制为名义上的当前版本?

I’ve come across situations where a current version of a package seems not to be working and requires reinstallation. But pip install -U won’t touch a package that is already up-to-date. I see how to force a reinstallation by first uninstalling (with pip uninstall) and then installing, but is there a way to simply force an “update” to a nominally current version in a single step?


回答 0

pip install --upgrade --force-reinstall <package>

升级时,请重新安装所有软件包,即使它们已经是最新的。

pip install -I <package>
pip install --ignore-installed <package>

忽略已安装的软件包(改为重新安装)。

pip install --upgrade --force-reinstall <package>

When upgrading, reinstall all packages even if they are already up-to-date.

pip install -I <package>
pip install --ignore-installed <package>

Ignore the installed packages (reinstalling instead).


回答 1

您可能希望拥有所有三个选项:--upgrade--force-reinstall确保重新安装,同时--no-deps避免重新安装依赖项。

$ sudo pip install --upgrade --no-deps --force-reinstall <packagename>

否则,您可能会遇到pip开始重新编译Numpy或其他大型软件包的问题。

You might want to have all three options: --upgrade and --force-reinstall ensures reinstallation, while --no-deps avoids reinstalling dependencies.

$ sudo pip install --upgrade --no-deps --force-reinstall <packagename>

Otherwise you might run into the problem that pip starts to recompile Numpy or other large packages.


回答 2

如果要重新安装Requirements.txt文件中指定的软件包而不进行升级,那么只需重新安装Requirements.txt文件中指定的特定版本:

pip install -r requirements.txt --ignore-installed

If you want to reinstall packages specified in a requirements.txt file, without upgrading, so just reinstall the specific versions specified in the requirements.txt file:

pip install -r requirements.txt --ignore-installed

回答 3

--force-reinstall

似乎没有强制使用python2.7和pip-1.5重新安装

我不得不用

--no-deps --ignore-installed
--force-reinstall

doesn’t appear to force reinstall using python2.7 with pip-1.5

I’ve had to use

--no-deps --ignore-installed

回答 4

如果您的文本文件包含大量软件包,则需要添加-r标志

pip install --upgrade --no-deps --force-reinstall -r requirements.txt

If you have a text file with loads of packages you need to add the -r flag

pip install --upgrade --no-deps --force-reinstall -r requirements.txt

回答 5

如果您需要强制重新安装pip本身,则可以执行以下操作:

python -m pip install --upgrade --force-reinstall pip

In the case you need to force the reinstallation of pip itself you can do:

python -m pip install --upgrade --force-reinstall pip

回答 6

sudo pip3 install --upgrade --force-reinstall --no-deps --no-cache-dir <package-name>==<package-version>

一些相关的答案:

点安装选项“忽略安装”和“强制重新安装”之间的区别

sudo pip3 install --upgrade --force-reinstall --no-deps --no-cache-dir <package-name>==<package-version>

Some relevant answers:

Difference between pip install options “ignore-installed” and “force-reinstall”


如何在Python上使用“ pip”安装psycopg2?

问题:如何在Python上使用“ pip”安装psycopg2?

我在用着 virtualenv,我需要安装“ psycopg2”。

我已经完成以下工作:

pip install http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160

我有以下消息:

Downloading/unpacking http://pypi.python.org/packages/source/p/psycopg2/psycopg2
-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
  Downloading psycopg2-2.4.tar.gz (607Kb): 607Kb downloaded
  Running setup.py egg_info for package from http://pypi.python.org/packages/sou
rce/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
    Error: pg_config executable not found.

    Please add the directory containing pg_config to the PATH
    or specify the full executable path with the option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.
    Complete output from command python setup.py egg_info:
    running egg_info

creating pip-egg-info\psycopg2.egg-info

writing pip-egg-info\psycopg2.egg-info\PKG-INFO

writing top-level names to pip-egg-info\psycopg2.egg-info\top_level.txt

writing dependency_links to pip-egg-info\psycopg2.egg-info\dependency_links.txt

writing manifest file 'pip-egg-info\psycopg2.egg-info\SOURCES.txt'

warning: manifest_maker: standard file '-c' not found

Error: pg_config executable not found.



Please add the directory containing pg_config to the PATH

or specify the full executable path with the option:



    python setup.py build_ext --pg-config /path/to/pg_config build ...



or with the pg_config option in 'setup.cfg'.

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in C:\Documents and Settings\anlopes\Application Data\pip\p
ip.log

我的问题是,我只需要这样做才能使psycopg2工作?

python setup.py build_ext --pg-config /path/to/pg_config build ...

I’m using virtualenv and I need to install “psycopg2”.

I have done the following:

pip install http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160

And I have the following messages:

Downloading/unpacking http://pypi.python.org/packages/source/p/psycopg2/psycopg2
-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
  Downloading psycopg2-2.4.tar.gz (607Kb): 607Kb downloaded
  Running setup.py egg_info for package from http://pypi.python.org/packages/sou
rce/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
    Error: pg_config executable not found.

    Please add the directory containing pg_config to the PATH
    or specify the full executable path with the option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.
    Complete output from command python setup.py egg_info:
    running egg_info

creating pip-egg-info\psycopg2.egg-info

writing pip-egg-info\psycopg2.egg-info\PKG-INFO

writing top-level names to pip-egg-info\psycopg2.egg-info\top_level.txt

writing dependency_links to pip-egg-info\psycopg2.egg-info\dependency_links.txt

writing manifest file 'pip-egg-info\psycopg2.egg-info\SOURCES.txt'

warning: manifest_maker: standard file '-c' not found

Error: pg_config executable not found.



Please add the directory containing pg_config to the PATH

or specify the full executable path with the option:



    python setup.py build_ext --pg-config /path/to/pg_config build ...



or with the pg_config option in 'setup.cfg'.

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in C:\Documents and Settings\anlopes\Application Data\pip\p
ip.log

My question, I only need to do this to get the psycopg2 working?

python setup.py build_ext --pg-config /path/to/pg_config build ...

回答 0

注意:早在不久之前,PyPI中就存在Windows的二进制轮子,因此Windows用户不再是问题。以下是适用于Linux和Mac用户的解决方案,因为他们中的很多人都是通过网络搜索找到这篇文章的。


选项1

psycopg2-binary而是安装PyPI软件包,它具有适用于Linux和Mac OS的Python轮子。

pip install psycopg2-binary

选项2

安装先决条件来构建 psycopg2从源代码软件包:

Debian / Ubuntu

Python 3

sudo apt install libpq-dev python3-dev

您可能需要安装 python3.8-dev或类似的工具,例如Python 3.8。

Python 2 1

sudo apt install libpq-dev python-dev

如果还不够,请尝试

sudo apt install build-essential

要么

sudo apt install postgresql-server-dev-all

在再次安装psycopg2之前。

CentOS的6

参见班杰的答案


1真的吗?2020年

Note: Since a while back, there are binary wheels for Windows in PyPI, so this should no longer be an issue for Windows users. Below are solutions for Linux, Mac users, since lots of them find this post through web searches.


Option 1

Install the psycopg2-binary PyPI package instead, it has Python wheels for Linux and Mac OS.

pip install psycopg2-binary

Option 2

Install the prerequsisites for building the psycopg2 package from source:

Debian/Ubuntu

Python 3

sudo apt install libpq-dev python3-dev

You might need to install python3.8-dev or similar for e.g. Python 3.8.

Python 21

sudo apt install libpq-dev python-dev

If that’s not enough, try

sudo apt install build-essential

or

sudo apt install postgresql-server-dev-all

as well before installing psycopg2 again.

CentOS 6

See Banjer’s answer


1 Really? It’s 2020


回答 1

在CentOS上,您需要postgres开发软件包:

sudo yum install python-devel postgresql-devel

至少这是CentOS 6上的解决方案。

On CentOS, you need the postgres dev packages:

sudo yum install python-devel postgresql-devel

That was the solution on CentOS 6 at least.


回答 2

在安装了Postgres.app 9.3.2.0 RC2的Mac Mavericks上,安装Postgres之后,我需要使用以下代码:

sudo PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin pip install psycopg2

On Mac Mavericks with Postgres.app version 9.3.2.0 RC2 I needed to use the following code after installing Postgres:

sudo PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin pip install psycopg2


回答 3

如果您使用的是Mac,则可以使用自制软件

brew install postgresql

其他所有选项都在这里:http : //www.postgresql.org/download/macosx/

祝好运

if you’re on a mac you can use homebrew

brew install postgresql

And all other options are here: http://www.postgresql.org/download/macosx/

Good luck


回答 4

我最近在Windows机器上配置了psycopg2。最简单的安装是使用Windows可执行二进制文件。您可以在http://stickpeople.com/projects/python/win-psycopg/中找到它。

要在虚拟环境中安装本机二进制文件,请使用easy_install:

C:\virtualenv\Scripts\> activate.bat
(virtualenv) C:\virtualenv\Scripts\> easy_install psycopg2-2.5.win32-py2.7-pg9.2.4-release.exe

I recently configured psycopg2 on a windows machine. The easiest install is using a windows executable binary. You can find it at http://stickpeople.com/projects/python/win-psycopg/.

To install the native binary in a virtual envrionment, use easy_install:

C:\virtualenv\Scripts\> activate.bat
(virtualenv) C:\virtualenv\Scripts\> easy_install psycopg2-2.5.win32-py2.7-pg9.2.4-release.exe

回答 5

对于Python 3,您应该sudo apt-get install libpq-dev python3-dev在Debian下使用。

For Python 3 you should use sudo apt-get install libpq-dev python3-dev under Debian.


回答 6

这对我有用(在RHEL,CentOS上:

sudo yum install postgresql postgresql-devel python-devel

现在在pip install中包含指向您的postgresql二进制目录的路径:

sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2

确保包括正确的路径。就这样 :)

更新:对于python 3,请安装python3-devel而不是python-devel

This is what worked for me (On RHEL, CentOS:

sudo yum install postgresql postgresql-devel python-devel

And now include the path to your postgresql binary dir with you pip install:

sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2

Make sure to include the correct path. Thats all :)

UPDATE: For python 3, please install python3-devel instead of python-devel


回答 7

如果使用Mac OS,则应从源代码安装PostgreSQL。安装完成后,您需要使用以下方法添加此路径:

export PATH=/local/pgsql/bin:$PATH

或者您可以像这样添加路径:

export PATH=.../:usr/local/pgsql/bin

在您的.profile文件或.zshrc文件中。

这可能因操作系统而异。

您可以从http://www.thegeekstuff.com/2009/04/linux-postgresql-install-and-configure-from-source/遵循安装过程

If you using Mac OS, you should install PostgreSQL from source. After installation is finished, you need to add this path using:

export PATH=/local/pgsql/bin:$PATH

or you can append the path like this:

export PATH=.../:usr/local/pgsql/bin

in your .profile file or .zshrc file.

This maybe vary by operating system.

You can follow the installation process from http://www.thegeekstuff.com/2009/04/linux-postgresql-install-and-configure-from-source/


回答 8

到目前为止的答案太像魔术食谱。收到的错误告诉您pip无法找到PostgreSQL查询库的所需部分。可能是因为您在操作系统的非标准位置安装了它,这就是为什么该消息建议使用–pg-config选项的原因。

但是更常见的原因是您根本没有安装libpq。这通常发生在没有安装PostgreSQL服务器的机器上,因为您只想运行客户端应用程序,而不是服务器本身。每个OS /发行版都不相同,例如在Debian / Ubuntu上,您需要安装libpq-dev。这使您可以针对PostgreSQL查询库编译和链接代码。

大多数答案还建议安装Python开发库。小心。如果仅使用发行版中安装的默认Python,则可以使用,但是如果您使用的是较新版本,则可能会引起问题。如果您在此计算机上构建了Python,那么您已经具有编译C / C ++库与Python交互所需的dev库。只要您使用的是正确的pip版本,即与python二进制文件安装在同一bin文件夹中的版本,您便都已准备就绪。无需安装旧版本。

The answers so far are too much like magic recipes. The error that you received tells you that pip cannot find a needed part of the PostgreSQL Query library. Possibly this is because you have it installed in a non-standard place for your OS which is why the message suggests using the –pg-config option.

But a more common reason is that you don’t have libpq installed at all. This commonly happens on machines where you do NOT have PostgreSQL server installed because you only want to run client apps, not the server itself. Each OS/distro is different, for instance on Debian/Ubuntu you need to install libpq-dev. This allows you to compile and link code against the PostgreSQL Query library.

Most of the answers also suggest installing a Python dev library. Be careful. If you are only using the default Python installed by your distro, that will work, but if you have a newer version, it could cause problems. If you have built Python on this machine then you already have the dev libraries needed for compiling C/C++ libraries to interface with Python. As long as you are using the correct pip version, the one installed in the same bin folder as the python binary, then you are all set. No need to install the old version.


回答 9

Debian/Ubuntu

首先安装和构建psycopg2软件包的依赖项:

# apt-get build-dep python-psycopg2

然后在您的虚拟环境中,编译并安装psycopg2模块:

(env)$ pip install psycopg2

On Debian/Ubuntu:

First install and build dependencies of psycopg2 package:

# apt-get build-dep python-psycopg2

Then in your virtual environment, compile and install psycopg2 module:

(env)$ pip install psycopg2

回答 10

我已经在Windows中首先安装到基本python安装中的位置之前完成了此操作。

然后,您手动将已安装的psycopg2复制到virtualenv安装中。

它不漂亮,但是可以用。

I’ve done this before where in windows you install first into your base python installation.

Then, you manually copy the installed psycopg2 to the virtualenv install.

It’s not pretty, but it works.


回答 11

除了安装必需的软件包外,我还需要手动将PostgreSQL bin目录添加到PATH。在之前
$vi ~/.bash_profile
添加。PATH=/usr/pgsql-9.2/bin:$PATHexport PATH
$source ~/.bash_profile
$pip install psycopg2

Besides installing the required packages, I also needed to manually add PostgreSQL bin directory to PATH.
$vi ~/.bash_profile
Add PATH=/usr/pgsql-9.2/bin:$PATH before export PATH.
$source ~/.bash_profile
$pip install psycopg2


回答 12

在Windows XP上,如果未安装postgres,则会出现此错误…

On windows XP you get this error if postgres is not installed …


回答 13

我使用PG下载网站http://www.postgresql.org/download/linux/redhat/上的RedHat / CentOS存储库安装了Postgresql92

要获取pg_config,我必须将/usr/pgsql-9.2/bin添加到PATH。

I installed Postgresql92 using the RedHat / CentOS repository on PG’s downloads site http://www.postgresql.org/download/linux/redhat/

To get pg_config, I had to add /usr/pgsql-9.2/bin to PATH.


回答 14

在安装psycopg2之前,您需要安装python-dev软件包。

如果您使用的是Linux(可能还有其他系统,但我不能从经验上讲),则在安装dev软件包时,需要确保准确地了解运行的python版本。

例如,当我使用命令时:

sudo apt-get install python3-dev

尝试执行以下操作时,我仍然遇到相同的错误

pip install psycopg2

当我使用python 3.7时,我需要使用命令

sudo apt-get install python3.7-dev

完成此操作后,我再也不会遇到任何问题。显然,如果您使用的是python 3.5版,则可以将该7更改为5。

Before you can install psycopg2 you will need to install the python-dev package.

If you’re working from Linux (and possibly other systems but i can’t speak from experience) you will need to make sure to be quite exact about what version of python your running when installing the dev package.

For example when I used the command:

sudo apt-get install python3-dev

I still ran into the same error when trying to

pip install psycopg2

As I am using python 3.7 I needed to use the command

sudo apt-get install python3.7-dev

Once I did this I ran into no more issues. Obviously if your on python version 3.5 you would change that 7 to a 5.


回答 15

我已经为此奋斗了好几天,终于找到了如何使“ pip install psycopg2”命令在Windows(运行Cygwin)的virtualenv中运行的方法。

我碰到了“找不到pg_config可执行文件”。错误,但我已经在Windows中下载并安装了postgres。它也安装在Cygwin中。在Cygwin中运行“哪个pg_config”给出了“ / usr / bin / pg_config”,而运行“ pg_config”给出了合理的输出-但是,与Cygwin一起安装的版本是:

版本= PostgreSQL 8.2.11

这不适用于当前版本的psycopg2,后者似乎至少需要9.1。当我在Windows路径中添加“ c:\ Program Files \ PostgreSQL \ 9.2 \ bin”时,Cygwin pip安装程序能够找到正确的PostgreSQL版本,并且能够使用pip成功安装该模块。(无论如何,这可能比使用Cygwin版本的PostgreSQL更可取,因为本机版本运行得更快)。

I’ve been battling with this for days, and have finally figured out how to get the “pip install psycopg2” command to run in a virtualenv in Windows (running Cygwin).

I was hitting the “pg_config executable not found.” error, but I had already downloaded and installed postgres in Windows. It installed in Cygwin as well; running “which pg_config” in Cygwin gave “/usr/bin/pg_config”, and running “pg_config” gave sane output — however the version installed with Cygwin is:

VERSION = PostgreSQL 8.2.11

This won’t work with the current version of psycopg2, which appears to require at least 9.1. When I added “c:\Program Files\PostgreSQL\9.2\bin” to my Windows path, the Cygwin pip installer was able to find the correct version of PostgreSQL, and I was able to successfully install the module using pip. (This is probably preferable to using the Cygwin version of PostgreSQL anyway, as the native version will run much quicker).


回答 16

在Fedora 24上:对于Python 3.x

sudo dnf install postgresql-devel python3-devel

sudo dnf install redhat-rpm-config

激活您的虚拟环境:

pip install psycopg2

On Fedora 24: For Python 3.x

sudo dnf install postgresql-devel python3-devel

sudo dnf install redhat-rpm-config

Activate your Virtual Environment:

pip install psycopg2

回答 17

Psycopg2取决于Postgres库。在Ubuntu上,您可以使用:

apt-get install libpq-dev

然后:

pip install psycopg2

Psycopg2 Depends on Postgres Libraries. On Ubuntu You can use:

apt-get install libpq-dev

Then:

pip install psycopg2

回答 18

对于Windows较低的用户,他们不得不从下面的链接安装psycopg2,只需将其安装到您设置的任何Python安装中即可。它将名为“ psycopg2”的文件夹放置在python安装的site-packages文件夹中。

之后,只需将该文件夹复制到virtualenv的site-packages目录中,就不会有问题。

这是您可以找到安装psycopg2的可执行文件的链接

http://www.lfd.uci.edu/~gohlke/pythonlibs/

For lowly Windows users were stuck having to install psycopg2 from the link below, just install it to whatever Python installation you have setup. It will place the folder named “psycopg2” in the site-packages folder of your python installation.

After that, just copy that folder to the site-packages directory of your virtualenv and you will have no problems.

here is the link you can find the executable to install psycopg2

http://www.lfd.uci.edu/~gohlke/pythonlibs/


回答 19

在OpenSUSE 13.2上,此操作已修复:

sudo zypper in postgresql-devel 

On OpenSUSE 13.2, this fixed it:

sudo zypper in postgresql-devel 

回答 20

我可以将其安装在Windows计算机上,并通过以下命令将Anaconda / Spyder与python 2.7结合使用:

 !pip install psycopg2

然后建立与数据库的连接:

 import psycopg2
 conn = psycopg2.connect(dbname='dbname',host='host_name',port='port_number', user='user_name', password='password')

I could install it in a windows machine and using Anaconda/Spyder with python 2.7 through the following commands:

 !pip install psycopg2

Then to establish the connection to the database:

 import psycopg2
 conn = psycopg2.connect(dbname='dbname',host='host_name',port='port_number', user='user_name', password='password')

回答 21

Arch基本发行版中:

sudo pacman -S python-psycopg2
pip2 install psycopg2  # Use pip or pip3 to python3

In Arch base distributions:

sudo pacman -S python-psycopg2
pip2 install psycopg2  # Use pip or pip3 to python3

回答 22

如果pip不起作用,则可以从此处https://pypi.python.org/pypi/psycopg2下载.whl文件 。python setup.py install

if pip is not working than you can download .whl file from here https://pypi.python.org/pypi/psycopg2 extract it.. than python setup.py install


回答 23

在Ubuntu上,我只需要postgres dev软件包:

sudo apt-get install postgresql-server-dev-all

*在virtualenv中测试

On Ubuntu I just needed the postgres dev package:

sudo apt-get install postgresql-server-dev-all

*Tested in a virtualenv


回答 24

在OSX 10.11.6(El Capitan)上

brew install postgresql
PATH=$PATH:/Library/PostgreSQL/9.4/bin pip install psycopg2

On OSX 10.11.6 (El Capitan)

brew install postgresql
PATH=$PATH:/Library/PostgreSQL/9.4/bin pip install psycopg2

回答 25

在具有Macports的OSX上:

sudo port install postgresql96
export PATH=/opt/local/lib/postgresql96/bin:$PATH

On OSX with macports:

sudo port install postgresql96
export PATH=/opt/local/lib/postgresql96/bin:$PATH

回答 26

我遇到了这个问题,主要原因是安装了2个相同的版本。一种通过postgres.app,另一种通过HomeBrew。

如果您选择仅保留APP:

brew unlink postgresql
pip3 install psycopg2

I was having this problem, the main reason was with 2 equal versions installed. One by postgres.app and one by HomeBrew.

If you choose to keep only the APP:

brew unlink postgresql
pip3 install psycopg2

回答 27

在macOS Mojave上,请确保您使用适用于我的Command Line Tools 10.3进行了最新更新-通过Software Update对其进行了更新,Mojave上的Command Line Tools的先前版本对我不起作用。

On macOS Mojave make sure you on newest update with Command Line Tools 10.3 – that worked for me – updated it with Software Update, previous version of Command Line Tools on Mojave did not work for me.


回答 28

试试这个Gentoo

emerge dev-libs/libpqxx

Try this in Gentoo:

emerge dev-libs/libpqxx

回答 29

在Windows上是这样工作
的在虚拟环境中通过pip安装flask之后,在命令提示符下运行此命令

>pip install psycopg2

检查一下

On windows this is how it works
On the command prompt after installing flask via pip in virtual environment, run this command

>pip install psycopg2

Check this


处理多个Python版本和PIP?

问题:处理多个Python版本和PIP?

有什么方法可以使pip多个版本的Python正常运行吗?例如,我想用于pip将内容显式安装到站点2.5安装或站点2.6安装中。

例如,使用easy_install,我使用easy_install-2.{5,6}

而且,是的-我了解virtualenv,不是-这不是解决此特定问题的方法。

Is there any way to make pip play well with multiple versions of Python? For example, I want to use pip to explicitly install things to either my site 2.5 installation or my site 2.6 installation.

For example, with easy_install, I use easy_install-2.{5,6}.

And, yes — I know about virtualenv, and no — it’s not a solution to this particular problem.


回答 0

目前的建议是使用python -m pip,这里python是Python的版本,你想使用。这是建议,因为它适用于所有版本的Python和所有形式的virtualenv。例如:

# The system default python:
$ python -m pip install fish

# A virtualenv's python:
$ .env/bin/python -m pip install fish

# A specific version of python:
$ python-3.6 -m pip install fish

先前的答案,留给后代:

从0.8版开始,Pip支持pip-{version}。您可以像使用它一样easy_install-{version}

$ pip-2.5 install myfoopackage
$ pip-2.6 install otherpackage
$ pip-2.7 install mybarpackage

编辑:pip更改其架构以使用,pipVERSION而不是pip-VERSION在1.5版中使用。如果有,则应使用以下内容pip >= 1.5

$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage

检查https://github.com/pypa/pip/pull/1053了解更多详细信息


参考文献:

The current recommendation is to use python -m pip, where python is the version of Python you would like to use. This is the recommendation because it works across all versions of Python, and in all forms of virtualenv. For example:

# The system default python:
$ python -m pip install fish

# A virtualenv's python:
$ .env/bin/python -m pip install fish

# A specific version of python:
$ python-3.6 -m pip install fish

Previous answer, left for posterity:

Since version 0.8, Pip supports pip-{version}. You can use it the same as easy_install-{version}:

$ pip-2.5 install myfoopackage
$ pip-2.6 install otherpackage
$ pip-2.7 install mybarpackage

EDIT: pip changed its schema to use pipVERSION instead of pip-VERSION in version 1.5. You should use the following if you have pip >= 1.5:

$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage

Check https://github.com/pypa/pip/pull/1053 for more details


References:


回答 1

在Windows中,您可以执行使用通过给定的Python版本的PIP模块Python的发射器py.exe如果你选择了Python 3的安装过程中安装它。

py -3 -m pip install packagename
py -2 -m pip install packagename

您甚至可以更加具体,并请求确切的Python子版本:

py -3.6 -m pip install packagename

要获取通过启动器可用的所有已安装Python版本的列表,请运行:

py --list

另外,您可以直接启动所需的Python可执行文件:

C:/path/to/specific/python.exe -m pip install packagename

On Windows, you can execute the pip module using a given Python version through the Python launcher, py.exe, if you chose to install it during Python 3 setup.

py -3 -m pip install packagename
py -2 -m pip install packagename

You can be even more specific and request an exact sub-version of Python:

py -3.6 -m pip install packagename

To get a list of all installed Python versions available through the launcher, run:

py --list

Alternatively, you can launch the desired Python executable directly:

C:/path/to/specific/python.exe -m pip install packagename

回答 2

/path/to/python2.{5,6} /path/to/pip install PackageName 不起作用?

为了使它能够在尚未安装pip的任何python版本上运行,您需要下载pip并执行python*version* setup.py install。例如python3.3 setup.py install。这样可以解决注释中的导入错误。(由@hbdgaf建议)

/path/to/python2.{5,6} /path/to/pip install PackageName doesn’t work?

For this to work on any python version that doesn’t have pip already installed you need to download pip and do python*version* setup.py install. For example python3.3 setup.py install. This resolves the import error in the comments. (As suggested by @hbdgaf)


回答 3

我默认情况下安装了python 2.6(Amazon EC2 AMI),但是我的应用程序需要python2.7以及一些外部软件包。假设您已经安装了python2.7和默认的python(在我的例子中是2.6)。这是如何为非默认python2.7安装pip和软件包

为您的python版本安装pip:

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

使用特定的pip版本来安装软件包:

pip2.7 install mysql-connector-python --allow-external mysql-connector-python

I had python 2.6 installed by default (Amazon EC2 AMI), but needed python2.7 plus some external packages for my application. Assuming you already installed python2.7 alongside with default python (2.6 in my case). Here is how to install pip and packages for non-default python2.7

Install pip for your python version:

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

Use specific pip version to install packages:

pip2.7 install mysql-connector-python --allow-external mysql-connector-python

回答 4

它以这种方式在Windows中为我工作:

  1. 我将python文件python.py和pythonw.exe的名称更改为python3.py pythonw3.py

  2. 然后,我在提示符中运行了此命令:

    python3 -m pip install package

It worked for me in windows this way:

  1. I changed the name of python files python.py and pythonw.exe to python3.py pythonw3.py

  2. Then I just ran this command in the prompt:

    python3 -m pip install package


回答 5

其他答案显示了如何在2.X和3.X Python上同时使用pip,但没有显示如何处理多个Python发行版的情况(例如,原始Python和Anaconda Python)

我总共有3个Python版本:原始Python 2.7和Python 3.5以及Anaconda Python 3.5。

这是我将软件包安装到的方法:

  1. 原始Python 3.5

    /usr/bin/python3 -m pip install python-daemon
  2. 原始Python 2.7

    /usr/bin/python -m pip install python-daemon
  3. Anaconda Python 3.5

    python3 -m pip install python-daemon

    要么

    pip3 install python-daemon

    更简单,因为Anaconda在用户环境中覆盖了原始Python二进制文件。

    当然,在anaconda中安装应使用conda命令完成,这只是一个示例。


另外,请确保已为该特定python安装了pip。您可能需要手动安装pip。在Ubuntu 16.04中可以使用:

sudo apt-get install python-pip 

要么

sudo apt-get install python3-pip

Other answers show how to use pip with both 2.X and 3.X Python, but does not show how to handle the case of multiple Python distributions (eg. original Python and Anaconda Python).

I have a total of 3 Python versions: original Python 2.7 and Python 3.5 and Anaconda Python 3.5.

Here is how I install a package into:

  1. Original Python 3.5:

    /usr/bin/python3 -m pip install python-daemon
    
  2. Original Python 2.7:

    /usr/bin/python -m pip install python-daemon
    
  3. Anaconda Python 3.5:

    python3 -m pip install python-daemon
    

    or

    pip3 install python-daemon
    

    Simpler, as Anaconda overrides original Python binaries in user environment.

    Of course, installing in anaconda should be done with conda command, this is just an example.


Also, make sure that pip is installed for that specific python.You might need to manually install pip. This works in Ubuntu 16.04:

sudo apt-get install python-pip 

or

sudo apt-get install python3-pip

回答 6

我本人最近遇到了这个问题,发现在我的同时具有Python 2的Linux系统上,我对Python 3的了解不正确。

首先,您必须确保已为python版本安装了pip:

对于Python 2:

sudo apt-get install python-pip

对于Python 3:

sudo apt-get install python3-pip

然后,要为一个版本的Python或其他版本安装软件包,只需对Python 2使用以下代码:

pip install <package>

或对于Python 3:

pip3 install <package>

I ran into this issue myself recently and found that I wasn’t getting the right pip for Python 3, on my Linux system that also has Python 2.

First you must ensure that you have installed pip for your python version:

For Python 2:

sudo apt-get install python-pip

For Python 3:

sudo apt-get install python3-pip

Then to install packages for one version of Python or the other, simply use the following for Python 2:

pip install <package>

or for Python 3:

pip3 install <package>

回答 7

pip也是python包。因此,将模块安装到特定python版本的最简单方法如下

 python2.7 /usr/bin/pip install foo

要么

python2.7 -m pip install foo

pip is also a python package. So the easiest way to install modules to a specific python version would be below

 python2.7 /usr/bin/pip install foo

or

python2.7 -m pip install foo

回答 8

因此很明显,有多个版本easy_install pip。这似乎是一个大混乱。无论如何,这就是我在Ubuntu 12.10上为Python 2.7安装Django的目的:

$ sudo easy_install-2.7 pip
Searching for pip
Best match: pip 1.1
Adding pip 1.1 to easy-install.pth file
Installing pip-2.7 script to /usr/local/bin

Using /usr/lib/python2.7/dist-packages
Processing dependencies for pip
Finished processing dependencies for pip

$ sudo pip-2.7 install django
Downloading/unpacking django
  Downloading Django-1.5.1.tar.gz (8.0Mb): 8.0Mb downloaded
  Running setup.py egg_info for package django

    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
Installing collected packages: django
  Running setup.py install for django
    changing mode of build/scripts-2.7/django-admin.py from 644 to 755

    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
    changing mode of /usr/local/bin/django-admin.py to 755
Successfully installed django
Cleaning up...

$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> 

So apparently there are multiple versions of easy_install and pip. It seems to be a big mess. Anyway, this is what I did to install Django for Python 2.7 on Ubuntu 12.10:

$ sudo easy_install-2.7 pip
Searching for pip
Best match: pip 1.1
Adding pip 1.1 to easy-install.pth file
Installing pip-2.7 script to /usr/local/bin

Using /usr/lib/python2.7/dist-packages
Processing dependencies for pip
Finished processing dependencies for pip

$ sudo pip-2.7 install django
Downloading/unpacking django
  Downloading Django-1.5.1.tar.gz (8.0Mb): 8.0Mb downloaded
  Running setup.py egg_info for package django

    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
Installing collected packages: django
  Running setup.py install for django
    changing mode of build/scripts-2.7/django-admin.py from 644 to 755

    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
    changing mode of /usr/local/bin/django-admin.py to 755
Successfully installed django
Cleaning up...

$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> 

回答 9

从这里:https : //docs.python.org/3/installing/

这是如何为同时安装linux,mac,posix的各种版本安装软件包的方法:

python2   -m pip install SomePackage  # default Python 2
python2.7 -m pip install SomePackage  # specifically Python 2.7
python3   -m pip install SomePackage  # default Python 3
python3.4 -m pip install SomePackage  # specifically Python 3.4
python3.5 -m pip install SomePackage  # specifically Python 3.5
python3.6 -m pip install SomePackage  # specifically Python 3.6

Windows上,将py Python启动器与-m开关结合使用:

py -2   -m pip install SomePackage  # default Python 2
py -2.7 -m pip install SomePackage  # specifically Python 2.7
py -3   -m pip install SomePackage  # default Python 3
py -3.4 -m pip install SomePackage  # specifically Python 3.4

From here: https://docs.python.org/3/installing/

Here is how to install packages for various versions that are installed at the same time linux, mac, posix:

python2   -m pip install SomePackage  # default Python 2
python2.7 -m pip install SomePackage  # specifically Python 2.7
python3   -m pip install SomePackage  # default Python 3
python3.4 -m pip install SomePackage  # specifically Python 3.4
python3.5 -m pip install SomePackage  # specifically Python 3.5
python3.6 -m pip install SomePackage  # specifically Python 3.6

On Windows, use the py Python launcher in combination with the -m switch:

py -2   -m pip install SomePackage  # default Python 2
py -2.7 -m pip install SomePackage  # specifically Python 2.7
py -3   -m pip install SomePackage  # default Python 3
py -3.4 -m pip install SomePackage  # specifically Python 3.4

回答 10

在Linux,Mac OS X和其他POSIX系统上,结合使用版本化的Python命令和-m开关,以运行以下命令的适当副本pip

python2.7 -m pip install SomePackage
python3.4 -m pip install SomePackage

(也可能提供适当版本的pip命令)

在Windows上,将pyPython启动器与-m开关结合使用:

py -2.7 -m pip install SomePackage  # specifically Python 2.7
py -3.4 -m pip install SomePackage  # specifically Python 3.4

如果遇到错误,请py -3.4尝试:

pip install SomePackage

On Linux, Mac OS X and other POSIX systems, use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip:

python2.7 -m pip install SomePackage
python3.4 -m pip install SomePackage

(appropriately versioned pip commands may also be available)

On Windows, use the py Python launcher in combination with the -m switch:

py -2.7 -m pip install SomePackage  # specifically Python 2.7
py -3.4 -m pip install SomePackage  # specifically Python 3.4

if you get an error for py -3.4 then try:

pip install SomePackage

回答 11

安装多个版本的Python和相应的软件包。

同一Windows机器上的Python版本:2.7,3.4和3.6

安装所有3个版本的Python

  • 使用以下路径安装了Python 2.7、3.4和3.6

所有3个版本的Python的PATH

  • 确保PATH变量(在System Variables中)包含以下路径-C:\ Python27 \; C:\ Python27 \ Scripts; C:\ Python34 \; C:\ Python34 \ Scripts; C:\ Python36 \; C:\ Python36 \ Scripts \;

重命名版本的可执行文件

  • 将C:\ Python36和C:\ Python34中的python可执行文件名称分别更改为python36和python34。

检查所有版本的命令提示符:

为每个版本分别安装软件包

Installation of multiple versions of Python and respective Packages.

Python version on the same windows machine : 2.7 , 3.4 and 3.6

Installation of all 3 versions of Python :

  • Installed the Python 2.7 , 3.4 and 3.6 with the below paths

PATH for all 3 versions of Python :

  • Made sure the PATH variable ( in System Variables ) has below paths included – C:\Python27\;C:\Python27\Scripts;C:\Python34\;C:\Python34\Scripts;C:\Python36\;C:\Python36\Scripts\;

Renaming the executables for versions :

  • Changed the python executable name in C:\Python36 and C:\Python34 to python36 and python34 respectively.

Checked for the command prompt with all versions :

Installing the packages separately for each version


回答 12

如果您有多个版本以及多个体系结构(32位,64位),则需要在版本末尾添加-32或-64。

对于Windows,请转到cmd并键入py –list,它将生成您已安装的版本。该列表将如下所示:

Installed Pythons found by py Launcher for Windows
 -3.7-64 *
 -3.7-32
 -3.6-32

以完整命令为例:

py -3.6-32 -m pip install (package)

如果您想更深入,要在特定版本的python上安装特定版本的软件包,请在该软件包之后使用==(version)。举个例子,

py -3.6-32 -m pip install opencv-python==4.1.0.25

If you have multiple versions as well as multiple architectures (32 bit, 64 bit) you will need to add a -32 or -64 at the end of your version.

For windows, go to cmd and type py –list and it will produce the versions you have installed. The list will look like the following:

Installed Pythons found by py Launcher for Windows
 -3.7-64 *
 -3.7-32
 -3.6-32

The full command as an example will be:

py -3.6-32 -m pip install (package)

If you want to get more indepth, to install a specific version of a package on a specific version of python, use ==(version) after the package. As an example,

py -3.6-32 -m pip install opencv-python==4.1.0.25

回答 13

这里的大多数答案都解决了这个问题,但是我想添加一些使我/usr/local在CentOS 7上的python替代安装中不断困惑的东西。当我安装在那里时,由于可以使用pip2.7 install和它会安装模块。但是,我不知道是为什么我新安装的python版本没有看到我要安装的内容。

事实证明,在CentOS 7中,该/usr/bin文件夹中已经有一个python2.7和pip2.7 。要为新的python发行版安装pip,您需要专门告诉sudo转到/usr/local/bin

sudo /usr/local/bin/python2.7 -m ensurepip

这应该在您的/usr/local/bin文件夹中安装了pip2.7 以及您的python版本。诀窍是,当您要安装模块时,您需要修改sudo $PATH变量以包含它,/usr/local/bin或者需要执行

sudo /usr/local/bin/pip2.7 install <module>

如果要安装新模块。我花了一辈子的时间才记住那sudo不是立即看到的/usr/local/bin

Most of the answers here address the issue but I want to add something what was continually confusing me with regard to creating an alternate installation of python in the /usr/local on CentOS 7. When I installed there, it appeared like pip was working since I could use pip2.7 install and it would install modules. However, what I couldn’t figure out was why my newly installed version of python wasn’t seeing what I was installing.

It turns out in CentOS 7 that there is already a python2.7 and a pip2.7 in the /usr/bin folder. To install pip for your new python distribution, you need to specifically tell sudo to go to /usr/local/bin

sudo /usr/local/bin/python2.7 -m ensurepip

This should get pip2.7 installed in your /usr/local/bin folder along with your version of python. The trick is that when you want to install modules, you either need to modify the sudo $PATH variable to include /usr/local/bin or you need to execute

sudo /usr/local/bin/pip2.7 install <module>

if you want to install a new module. It took me forever to remember that sudo wasn’t immediately seeing /usr/local/bin.


回答 14

这是我对这个问题的看法。适用于Python3。主要特点是:

  • 每个Python版本均从源代码编译
  • 所有版本均在本地安装
  • 不会以任何方式破坏系统的默认Python安装
  • 每个Python版本都通过virtualenv隔离

步骤如下:

  1. 如果您以其他方式安装了多个额外的python版本,请摆脱它们,例如,删除$ HOME / .local / lib / python3.x等(以及全局安装的版本)。但是不要触摸系统的默认python3版本。

  2. 在以下目录结构下的不同python版本的下载源:

    $HOME/
        python_versions/ : download Python-*.tgz packages here and "tar xvf" them.  You'll get directories like this:
          Python-3.4.8/
          Python-3.6.5/
          Python-3.x.y/
          ...
  3. 在每个“ Python-3.xy /”目录中,执行以下操作(在任何步骤中都不要使用“ sudo”!):

    mkdir root
    ./configure --prefix=$PWD/root 
    make -j 2
    make install
    virtualenv --no-site-packages -p root/bin/python3.x env
  4. 在“ python_versions /”处创建如下文件:

    env_python3x.bash:
    
    #!/bin/bash
    echo "type deactivate to exit"
    source $HOME/python_versions/Python-3.x.y/env/bin/activate
  5. 现在,无论何时您希望选择python3.x,都可以

    source $HOME/python_versions/env_python3x.bash

    进入virtualenv

  6. 在virtualenv中,使用以下命令安装您喜欢的python软件包:

    pip install --upgrade package_name
  7. 要退出virtualenv和python版本,只需键入“ deactivate”

更新

似乎--no-site-packages已弃用。有一个简单的解决方法:激活virtualenv后,只需将HOME env变量指向实际主目录之外的其他位置即可,即:

export HOME=some/where/else

通常,执行此操作的一种好方法是:

  • 创建virtualenv
  • 激活virtualenv
  • 如果要将现有库“回收”到virtualenv,请从现有安装中将它们进行软链接,即 ln -s $HOME/.local/lib/python3.6/site-packages/numpy $PWD/venv/lib/python3.6/site-packages/
  • export PYTHONPATH=export HOME=/some/other/dir

现在,您应该具有自定义隔离的virtualenv。

Here is my take on the problem. Works for Python3. The main features are:

  • Each Python version is compiled from source
  • All versions are installed locally
  • Does not mangle your system’s default Python installation in any way
  • Each Python version is isolated with virtualenv

The steps are as follows:

  1. If you have several extra python versions installed in some other way, get rid of them, e.g., remove $HOME/.local/lib/python3.x, etc. (also the globally installed ones). Don’t touch your system’s default python3 version though.

  2. Download source for different python versions under the following directory structure:

    $HOME/
        python_versions/ : download Python-*.tgz packages here and "tar xvf" them.  You'll get directories like this:
          Python-3.4.8/
          Python-3.6.5/
          Python-3.x.y/
          ...
    
  3. At each “Python-3.x.y/” directory, do the following (do NOT use “sudo” in any of the steps!):

    mkdir root
    ./configure --prefix=$PWD/root 
    make -j 2
    make install
    virtualenv --no-site-packages -p root/bin/python3.x env
    
  4. At “python_versions/” create files like this:

    env_python3x.bash:
    
    #!/bin/bash
    echo "type deactivate to exit"
    source $HOME/python_versions/Python-3.x.y/env/bin/activate
    
  5. Now, anytime you wish to opt for python3.x, do

    source $HOME/python_versions/env_python3x.bash
    

    to enter the virtualenv

  6. While in the virtualenv, install your favorite python packages with

    pip install --upgrade package_name
    
  7. To exit the virtualenv and python version just type “deactivate”

UPDATE

It seems that --no-site-packages is deprecated. There’s an easy fix for this: Once you have activated the virtualenv, just point the HOME env variable to somewhere else than your actual home directory, i.e.:

export HOME=some/where/else

A nice way to do this in general is:

  • Create virtualenv
  • Activate virtualenv
  • If you want to “recycle” existing libraries to your virtualenv, softlink them from your existing install, i.e. ln -s $HOME/.local/lib/python3.6/site-packages/numpy $PWD/venv/lib/python3.6/site-packages/
  • Do export PYTHONPATH=, export HOME=/some/other/dir

Now you should have custom-isolated virtualenv.


回答 15

上下文:Archlinux

行动:
安装python2-pip:
sudo pacman -S python2-pip

您现在有了pip2.7:
sudo pip2.7 install boto

测试(在我的情况下,我需要’boto’):
运行以下命令:

python2
import boto

成功:没有错误。

出口:Ctrl+D

Context: Archlinux

Action:
Install python2-pip:
sudo pacman -S python2-pip

You now have pip2.7:
sudo pip2.7 install boto

Test (in my case I needed ‘boto’):
Run the following commands:

python2
import boto

Success: No error.

Exit: Ctrl+D


回答 16

例如,如果您将其他版本(例如3.5)设置为默认版本,并想为python 2.7安装pip:

  1. https://pypi.python.org/pypi/pip(tar)下载pip
  2. 解压tar文件
  3. cd到文件目录
  4. sudo python2.7 setup.py安装

for example, if you set other versions (e.g. 3.5) as default and want to install pip for python 2.7:

  1. download pip at https://pypi.python.org/pypi/pip (tar)
  2. unzip tar file
  3. cd to the file’s directory
  4. sudo python2.7 setup.py install

回答 17

您可以转到例如C:\ Python2.7 \ Scripts,然后从该路径运行cmd。之后,您可以运行pip2.7安装软件包…

这将为该版本的Python安装软件包。

You can go to for example C:\Python2.7\Scripts and then run cmd from that path. After that you can run pip2.7 install yourpackage…

That will install package for that version of Python.


回答 18

这可能是完全错误的操作(我是python noob),但是我只是进去编辑了pip文件

#!/usr/bin/env python3 <-- I changed this line.

# -*- coding: utf-8 -*-
import re
import sys

from pip._internal import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

This is probably the completely wrong thing to do (I’m a python noob), but I just went in and edited the pip file

#!/usr/bin/env python3 <-- I changed this line.

# -*- coding: utf-8 -*-
import re
import sys

from pip._internal import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

回答 19

专门针对Windows: \ path \ to \ python.exe -m pip install PackageName有效。

For windows specifically: \path\to\python.exe -m pip install PackageName works.


回答 20

对于搅拌机:

/usr/bin $ python3.7 -m pip install irc

for Blender:

/usr/bin $ python3.7 -m pip install irc