标签归档:pip

为什么要在easy_install上使用pip?[关闭]

问题:为什么要在easy_install上使用pip?[关闭]

一条推文中写道:

不要使用easy_install,除非您喜欢对自己的脸部进行刺伤。使用点子。

为什么要在easy_install上使用pip?难道不是PyPI和程序包作者最主要的原因吗?如果作者将废话源tarball(例如:缺少文件,没有setup.py)上传到PyPI,则pip和easy_install都将失败。除了化妆品的差异,为什么Python的人(如上面的鸣叫)似乎强烈地倾向于在点子的easy_install?

(假设我们正在谈论由社区维护的Distribute软件包中的easy_install)

A tweet reads:

Don’t use easy_install, unless you like stabbing yourself in the face. Use pip.

Why use pip over easy_install? Doesn’t the fault lie with PyPI and package authors mostly? If an author uploads crap source tarball (eg: missing files, no setup.py) to PyPI, then both pip and easy_install will fail. Other than cosmetic differences, why do Python people (like in the above tweet) seem to strongly favor pip over easy_install?

(Let’s assume that we’re talking about easy_install from the Distribute package, that is maintained by the community)


回答 0

此处的许多答案在2015年已经过时了(尽管最初由Daniel Roseman接受的答案不是)。这是当前的状态:

  • 现在,二进制程序包以轮子(.whl文件)的形式分发-不仅在PyPI上,而且在第三方存储库中,例如Christoph Gohlke的Windows Extension Packagespip可以处理轮子;easy_install不能。
  • 虚拟环境(由3.4内置,或者可以通过2.6添加到2.6 + / 3.1 + virtualenv)已经成为一个非常重要和突出的工具(并在官方文档中推荐);它们pip是开箱即用的,但是甚至无法正常使用easy_install
  • distribute包含的软件包easy_install不再维护。它的改进已setuptools合并回setuptools。尝试安装distribute只会安装setuptools
  • easy_install 本身只是准维护的。
  • 所有的其中箱子pip用于不如easy_install从解包源树-installing,从DVCS回购等-是早已过去的; 你可以pip install .pip install git+https://
  • pip带有来自python.org的官方Python 2.7和3.4+软件包,pip如果您从源代码构建,则默认情况下会包含引导程序。
  • Python打包用户指南》已取代了有关安装,使用和构建软件包的各种文档的不完整之处。现在,Python自己的有关安装Python模块的文档符合该用户指南的要求,并明确地pip称为“首选安装程序”。
  • pip这些年来,还添加了其他新功能,这些功能将永远不会存在easy_install。例如,pip通过构建需求文件,然后在每一侧使用单个命令安装它,可以轻松克隆站点程序包。或将您的需求文件转换为本地回购以用于内部开发。等等。

我知道easy_install在2015年使用的唯一好的理由是在OS X 10.5-10.8中使用Apple预先安装的Python版本的特殊情况。从10.5开始,Apple已包含easy_install,但从10.10开始,它们仍然不包含pip。使用10.9+时,您仍然应该只使用get-pip.py,但是对于10.5-10.8,这存在一些问题,因此更容易实现sudo easy_install pip。(通常,这easy_install pip是一个坏主意;您只想在OS X 10.5-10.8上才能做到这一点。)此外,10.5-10.8包含readline以一种easy_install知道如何纠缠而pip不会纠缠的方式,因此您也想sudo easy_install readline如果要升级。

Many of the answers here are out of date for 2015 (although the initially accepted one from Daniel Roseman is not). Here’s the current state of things:

  • Binary packages are now distributed as wheels (.whl files)—not just on PyPI, but in third-party repositories like Christoph Gohlke’s Extension Packages for Windows. pip can handle wheels; easy_install cannot.
  • Virtual environments (which come built-in with 3.4, or can be added to 2.6+/3.1+ with virtualenv) have become a very important and prominent tool (and recommended in the official docs); they include pip out of the box, but don’t even work properly with easy_install.
  • The distribute package that included easy_install is no longer maintained. Its improvements over setuptools got merged back into setuptools. Trying to install distribute will just install setuptools instead.
  • easy_install itself is only quasi-maintained.
  • All of the cases where pip used to be inferior to easy_install—installing from an unpacked source tree, from a DVCS repo, etc.—are long-gone; you can pip install ., pip install git+https://.
  • pip comes with the official Python 2.7 and 3.4+ packages from python.org, and a pip bootstrap is included by default if you build from source.
  • The various incomplete bits of documentation on installing, using, and building packages have been replaced by the Python Packaging User Guide. Python’s own documentation on Installing Python Modules now defers to this user guide, and explicitly calls out pip as “the preferred installer program”.
  • Other new features have been added to pip over the years that will never be in easy_install. For example, pip makes it easy to clone your site-packages by building a requirements file and then installing it with a single command on each side. Or to convert your requirements file to a local repo to use for in-house development. And so on.

The only good reason that I know of to use easy_install in 2015 is the special case of using Apple’s pre-installed Python versions with OS X 10.5-10.8. Since 10.5, Apple has included easy_install, but as of 10.10 they still don’t include pip. With 10.9+, you should still just use get-pip.py, but for 10.5-10.8, this has some problems, so it’s easier to sudo easy_install pip. (In general, easy_install pip is a bad idea; it’s only for OS X 10.5-10.8 that you want to do this.) Also, 10.5-10.8 include readline in a way that easy_install knows how to kludge around but pip doesn’t, so you also want to sudo easy_install readline if you want to upgrade that.


回答 1

从伊恩·比金(Ian Bicking)自己对pip介绍

pip最初旨在通过以下方式对easy_install进行改进

  • 所有软件包均在安装前已下载。结果不会发生部分完成的安装。
  • 注意在控制台上显示有用的输出。
  • 采取行动的原因已被跟踪。例如,如果正在安装软件包,则pip会跟踪为什么需要该软件包。
  • 错误消息应该很有用。
  • 该代码相对简洁明了,具有内聚性,可以更轻松地以编程方式使用。
  • 软件包不必作为Egg存档安装,可以将它们平放安装(同时保留Egg元数据)。
  • 对其他版本控制系统(Git,Mercurial和Bazaar)的本地支持
  • 卸载软件包。
  • 简单定义固定的需求集并可靠地复制一组包。

From Ian Bicking’s own introduction to pip:

pip was originally written to improve on easy_install in the following ways

  • All packages are downloaded before installation. Partially-completed installation doesn’t occur as a result.
  • Care is taken to present useful output on the console.
  • The reasons for actions are kept track of. For instance, if a package is being installed, pip keeps track of why that package was required.
  • Error messages should be useful.
  • The code is relatively concise and cohesive, making it easier to use programmatically.
  • Packages don’t have to be installed as egg archives, they can be installed flat (while keeping the egg metadata).
  • Native support for other version control systems (Git, Mercurial and Bazaar)
  • Uninstallation of packages.
  • Simple to define fixed sets of requirements and reliably reproduce a set of packages.

回答 2

另一个(至今尚未提及)之所以喜欢点子,是因为它是新的热点,并将在未来继续使用。

以下信息图表(来自《The Hitchhiker’s Guide to Packaging v1.0》中的包装当前状态”部分)表明setuptools / easy_install将来会消失。

在此处输入图片说明

这是Distribution的文档中的另一个信息图,显示Setuptools和easy_install将被新的热点— distributionpip取代。虽然PIP仍然是新的辣味,分发与合并的setuptools在2013年发布的setuptools V0.7。

在此处输入图片说明

Another—as of yet unmentioned—reason for favoring pip is because it is the new hotness and will continue to be used in the future.

The infographic below—from the Current State of Packaging section in the The Hitchhiker’s Guide to Packaging v1.0—shows that setuptools/easy_install will go away in the future.

enter image description here

Here’s another infographic from distribute’s documentation showing that Setuptools and easy_install will be replaced by the new hotness—distribute and pip. While pip is still the new hotness, Distribute merged with Setuptools in 2013 with the release of Setuptools v0.7.

enter image description here


回答 3

有两个原因,可能还有更多:

  1. pip提供uninstall命令

  2. 如果中间安装失败,则pip将使您保持干净状态。

Two reasons, there may be more:

  1. pip provides an uninstall command

  2. if an installation fails in the middle, pip will leave you in a clean state.


回答 4

需求文件。

认真地说,我每天都将它与virtualenv结合使用。


快速依赖管理教程,民谣

需求文件使您可以创建已通过pip安装的所有软件包的快照。通过将这些程序包封装在虚拟环境中,可以使代码库在一组非常特定的程序包中工作,并与其他人共享该代码库。

从Heroku的文档中 https://devcenter.heroku.com/articles/python

您创建一个虚拟环境,并设置您的外壳以使用它。(bash / * nix指令)

virtualenv env
source env/bin/activate

现在,与此外壳一起运行的所有python脚本都将使用该环境的软件包和配置。现在,您可以在此环境中本地安装软件包,而无需在计算机上全局安装。

pip install flask

现在,您可以转储有关安装哪些软件包的信息

pip freeze > requirements.txt

如果您将该文件签入版本控制中,那么当其他人获取您的代码时,他们可以设置自己的虚拟环境并使用以下命令安装所有依赖项:

pip install -r requirements.txt

任何时候您都可以像这样自动执行乏味的操作。

REQUIREMENTS files.

Seriously, I use this in conjunction with virtualenv every day.


QUICK DEPENDENCY MANAGEMENT TUTORIAL, FOLKS

Requirements files allow you to create a snapshot of all packages that have been installed through pip. By encapsulating those packages in a virtualenvironment, you can have your codebase work off a very specific set of packages and share that codebase with others.

From Heroku’s documentation https://devcenter.heroku.com/articles/python

You create a virtual environment, and set your shell to use it. (bash/*nix instructions)

virtualenv env
source env/bin/activate

Now all python scripts run with this shell will use this environment’s packages and configuration. Now you can install a package locally to this environment without needing to install it globally on your machine.

pip install flask

Now you can dump the info about which packages are installed with

pip freeze > requirements.txt

If you checked that file into version control, when someone else gets your code, they can setup their own virtual environment and install all the dependencies with:

pip install -r requirements.txt

Any time you can automate tedium like this is awesome.


回答 5

pip不会安装二进制软件包,并且未在Windows上经过良好测试。

由于Windows默认没有附带编译器,因此通常无法在其中使用pip 。easy_install 可以为Windows安装二进制软件包。

pip won’t install binary packages and isn’t well tested on Windows.

As Windows doesn’t come with a compiler by default pip often can’t be used there. easy_install can install binary packages for Windows.


回答 6

更新:正如某些人所想,setuptools已经吸收distribute了相反的东西。setuptools是最新的最新distutils更改和滚轮格式。因此,easy_installpip或多或少平等现在。

来源:http : //pythonhosted.org/setuptools/merge-faq.html#why-setuptools-and-not-distribute-or-another-name

UPDATE: setuptools has absorbed distribute as opposed to the other way around, as some thought. setuptools is up-to-date with the latest distutils changes and the wheel format. Hence, easy_install and pip are more or less on equal footing now.

Source: http://pythonhosted.org/setuptools/merge-faq.html#why-setuptools-and-not-distribute-or-another-name


回答 7

除了模糊人的答复:

pip不会安装二进制软件包,并且未在Windows上经过良好测试。

由于Windows默认不带编译器,因此通常无法在其中使用pip。easy_install可以为Windows安装二进制软件包。

这是Windows上的一个技巧:

  • 您可以使用easy_install <package>安装二进制软件包来避免生成二进制文件

  • pip uninstall <package>即使您使用过easy_install,也可以使用 。

这只是在Windows上对我有效的解决方法。实际上,如果不涉及二进制文件,我总是使用pip。

请参阅当前的pip doku:http://www.pip-installer.org/en/latest/other-tools.html#pip-compared-to-easy-install

我将在邮件列表中询问为此计划的内容。

这是最新的更新:

新的受支持的安装二进制文件的方式将是wheel!它尚未在标准中,但几乎已经存在。当前版本仍为Alpha:1.0.0a1

https://pypi.python.org/pypi/wheel

http://wheel.readthedocs.org/en/latest/

我将wheel通过创建要PySide使用的OS X安装程序进行测试wheel,而不是蛋。会回来并报告此情况。

欢呼声-克里斯

快速更新:

到的过渡wheel即将结束。大多数软件包都支持wheel

我答应为制作车轮PySide,去年夏天我做了。很棒!

提示:一些开发商至今未能支撑轮格式,仅仅是因为他们忘记更换distutilssetuptools。通常,通过替换中的单个单词很容易转换此类软件包setup.py

As an addition to fuzzyman’s reply:

pip won’t install binary packages and isn’t well tested on Windows.

As Windows doesn’t come with a compiler by default pip often can’t be used there. easy_install can install binary packages for Windows.

Here is a trick on Windows:

  • you can use easy_install <package> to install binary packages to avoid building a binary

  • you can use pip uninstall <package> even if you used easy_install.

This is just a work-around that works for me on windows. Actually I always use pip if no binaries are involved.

See the current pip doku: http://www.pip-installer.org/en/latest/other-tools.html#pip-compared-to-easy-install

I will ask on the mailing list what is planned for that.

Here is the latest update:

The new supported way to install binaries is going to be wheel! It is not yet in the standard, but almost. Current version is still an alpha: 1.0.0a1

https://pypi.python.org/pypi/wheel

http://wheel.readthedocs.org/en/latest/

I will test wheel by creating an OS X installer for PySide using wheel instead of eggs. Will get back and report about this.

cheers – Chris

A quick update:

The transition to wheel is almost over. Most packages are supporting wheel.

I promised to build wheels for PySide, and I did that last summer. Works great!

HINT: A few developers failed so far to support the wheel format, simply because they forget to replace distutils by setuptools. Often, it is easy to convert such packages by replacing this single word in setup.py.


回答 8

刚遇到一个我不得不easy_install代替的特殊情况pip,否则我必须直接提取源代码。

对于该软件包GitPython,in中的版本pip太旧,即0.1.7,而from中的版本easy_install是最新的,即0.3.2.rc1

我正在使用Python 2.7.8。我不知道有关的底层机制easy_installpip,但至少有一些包的版本可能是彼此不同的,有时easy_install是一个较新的版本。

easy_install GitPython

Just met one special case that I had to use easy_install instead of pip, or I have to pull the source codes directly.

For the package GitPython, the version in pip is too old, which is 0.1.7, while the one from easy_install is the latest which is 0.3.2.rc1.

I’m using Python 2.7.8. I’m not sure about the underlay mechanism of easy_install and pip, but at least the versions of some packages may be different from each other, and sometimes easy_install is the one with newer version.

easy_install GitPython

如何安装带有.whl文件的Python软件包?

问题:如何安装带有.whl文件的Python软件包?

我在Windows机器上安装Python软件包时遇到问题,想与Christoph Gohlke的Window二进制文件一起安装。(根据我的经验,这减轻了许多其他软件包安装的麻烦)。但是,仅.whl文件可用。

http://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype

但是,如何安装.whl文件?

笔记

  • 我已经找到了车轮上的文档,但是它们在解释如何安装.whl文件时似乎并不那么简单。
  • 该问题与该问题重复,但未直接回答。

I’m having trouble installing a Python package on my Windows machine, and would like to install it with Christoph Gohlke’s Window binaries. (Which, to my experience, alleviated much of the fuss for many other package installations). However, only .whl files are available.

http://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype

But how do I install .whl files?

Notes

  • I’ve found documents on wheel, but they don’t seem so staightforward in explaining how to install .whl files.
  • This question is a duplicate with this question, which wasn’t directly answered.

回答 0

我只是使用了以下非常简单的内容。首先打开一个控制台,然后打开cd到您下载文件的位置,例如some-package.whl并使用

pip install some-package.whl

注意:如果无法识别pip.exe,则可以在安装python的“脚本”目录中找到它。如果未安装pip,则此页面可以提供帮助: 如何在Windows上安装pip?

注意:为澄清起见,
如果将*.whl文件复制到本地驱动器(例如C:\ some-dir \ some-file.whl),请使用以下命令行参数-

pip install C:/some-dir/some-file.whl

I just used the following which was quite simple. First open a console then cd to where you’ve downloaded your file like some-package.whl and use

pip install some-package.whl

Note: if pip.exe is not recognized, you may find it in the “Scripts” directory from where python has been installed. If pip is not installed, this page can help: How do I install pip on Windows?

Note: for clarification
If you copy the *.whl file to your local drive (ex. C:\some-dir\some-file.whl) use the following command line parameters —

pip install C:/some-dir/some-file.whl

回答 1

首先,请确保您已更新点子以启用滚轮支持:

pip install --upgrade pip

然后,要从wheel安装,请给它提供下载wheel的目录。例如,安装package_name.whl

pip install --use-wheel --no-index --find-links=/where/its/downloaded package_name

First, make sure you have updated pip to enable wheel support:

pip install --upgrade pip

Then, to install from wheel, give it the directory where the wheel is downloaded. For example, to install package_name.whl:

pip install --use-wheel --no-index --find-links=/where/its/downloaded package_name

回答 2

我和OP在同一条船上。

使用Windows命令提示符,从目录:

C:\Python34\Scripts>
pip install wheel

似乎有效。

将目录更改为whl所在的目录,它只是告诉我“无法识别点子”。回到C:\Python34\Scripts>上面,然后使用上面的完整命令提供“ where / its / downloaded”位置Requirement 'scikit_image-...-win32.whl' looks like a filename, but the filename does not exist

因此,我在Python34 / Scripts中放了一个.whl副本,再次运行了完全相同的命令(--find-links=仍然转到另一个文件夹),这一次它起作用了。

I am in the same boat as the OP.

Using a Windows command prompt, from directory:

C:\Python34\Scripts>
pip install wheel

seemed to work.

Changing directory to where the whl was located, it just tells me ‘pip is not recognized’. Going back to C:\Python34\Scripts>, then using the full command above to provide the ‘where/its/downloaded’ location, it says Requirement 'scikit_image-...-win32.whl' looks like a filename, but the filename does not exist.

So I dropped a copy of the .whl in Python34/Scripts, ran the exact same command over again (with the --find-links= still going to the other folder), and this time it worked.


回答 3

Christoph Gohlke的站点上有多个文件版本。

从该站点安装车轮时,我发现重要的一点是首先从Python控制台运行此车轮:

import pip
print(pip.pep425tags.get_supported())

这样您就知道应该为计算机安装哪个版本。选择错误的版本可能会导致软件包安装失败(尤其是如果您没有使用正确的CPython标记,例如cp27)。

There are several file versions on the great Christoph Gohlke’s site.

Something I have found important when installing wheels from this site is to first run this from the Python console:

import pip
print(pip.pep425tags.get_supported())

so that you know which version you should install for your computer. Picking the wrong version may fail the installing of the package (especially if you don’t use the right CPython tag, for example, cp27).


回答 4

您必须从我的计算机上的命令提示符处运行pip.exe。我输入C:/Python27/Scripts/pip2.exe install numpy

You have to run pip.exe from the command prompt on my computer. I type C:/Python27/Scripts/pip2.exe install numpy


回答 5

在Windows上,您不能仅使用进行升级pip install --upgrade pip,因为pip.exe正在使用,替换它会出错。相反,您应该pip像这样升级:

easy_install --upgrade pip

然后检查pip版本:

pip --version

如果显示 6.x系列,则有车轮支撑。

只有这样,您才能安装以下车轮套件:

pip install your-package.whl

On Windows you can’t just upgrade using pip install --upgrade pip, because the pip.exe is in use and there would be an error replacing it. Instead, you should upgrade pip like this:

easy_install --upgrade pip

Then check the pip version:

pip --version

If it shows 6.x series, there is wheel support.

Only then, you can install a wheel package like this:

pip install your-package.whl

回答 6

为了能够通过简单的双击安装wheel文件,您可以执行以下操作之一:

1)在命令行下以管理员权限运行两个命令:

assoc .whl=pythonwheel
ftype pythonwheel=cmd /c pip.exe install "%1" ^& pause

2)或者,可以将它们复制到wheel.bat文件中,并通过属性中的“以管理员身份运行”复选框来执行。

PS pip.exe假定位于PATH中。

更新:

(1)可以合并为一行:

assoc .whl=pythonwheel& ftype pythonwheel=cmd /c pip.exe install -U "%1" ^& pause

(2).bat文件的语法略有不同:

assoc .whl=pythonwheel& ftype pythonwheel=cmd /c pip.exe install -U "%%1" ^& pause

还可以使其输出更加详细:

@assoc .whl=pythonwheel|| echo Run me with administrator rights! && pause && exit 1
@ftype pythonwheel=cmd /c pip.exe install -U "%%1" ^& pause || echo Installation error && pause && exit 1
@echo Installation successfull & pause

有关详细信息,请参见我的博客文章

To be able to install wheel files with a simple doubleclick on them you can do one the following:

1) Run two commands in command line under administrator privileges:

assoc .whl=pythonwheel
ftype pythonwheel=cmd /c pip.exe install "%1" ^& pause

2) Alternatively, they can be copied into a wheel.bat file and executed with ‘Run as administrator’ checkbox in the properties.

PS pip.exe is assumed to be in the PATH.

Update:

(1) Those can be combined in one line:

assoc .whl=pythonwheel& ftype pythonwheel=cmd /c pip.exe install -U "%1" ^& pause

(2) Syntax for .bat files is slightly different:

assoc .whl=pythonwheel& ftype pythonwheel=cmd /c pip.exe install -U "%%1" ^& pause

Also its output can be made more verbose:

@assoc .whl=pythonwheel|| echo Run me with administrator rights! && pause && exit 1
@ftype pythonwheel=cmd /c pip.exe install -U "%%1" ^& pause || echo Installation error && pause && exit 1
@echo Installation successfull & pause

see my blog post for details.


回答 7

编辑:这不再是画中画的一部分

为避免下载此类文件,您可以尝试:

pip install --use-wheel pillow

有关更多信息,请参见this

EDIT: THIS NO LONGER IS A PART OF PIP

To avoid having to download such files, you can try:

pip install --use-wheel pillow

For more information, see this.


回答 8

如果您无法直接使用PIP安装特定的软件包。

您可以.whl-https://www.lfd.uci.edu/~gohlke/pythonlibs/下载特定的(wheel)软件包

CD(更改目录)到下载的软件包,并通过
pip install PACKAGENAME.whl
-ex 手动安装:
pip install ad3‑2.1‑cp27‑cp27m‑win32.whl

In-case if you unable to install specific package directly using PIP.

You can download a specific .whl (wheel) package from – https://www.lfd.uci.edu/~gohlke/pythonlibs/

CD (Change directory) to that downloaded package and install it manually by –
pip install PACKAGENAME.whl
ex:
pip install ad3‑2.1‑cp27‑cp27m‑win32.whl


回答 9

我设法安装NumPy的唯一方法如下:

我从这里下载了NumPy https://pypi.python.org/pypi/numpy

这个模块

https://pypi.python.org/packages/d7/3c/d8b473b517062cc700575889d79e7444c9b54c6072a22189d1831d2fbbce/numpy-1.11.2-cp35-none-win32.whl#md5=e485e06907826af5e1fc88608d0629a2

PowerShell中从Python的安装路径执行命令

PS C:\Program Files (x86)\Python35-32> .\python -m pip install C:/Users/MyUsername/Documents/Programs/Python/numpy-1.11.2-cp35-none-win32.whl
Processing c:\users\MyUsername\documents\programs\numpy-1.11.2-cp35-none-win32.whl
Installing collected packages: numpy
Successfully installed numpy-1.11.2
PS C:\Program Files (x86)\Python35-32>

PS .:我在Windows 10上安装了它。

The only way I managed to install NumPy was as follows:

I downloaded NumPy from here https://pypi.python.org/pypi/numpy

This Module

https://pypi.python.org/packages/d7/3c/d8b473b517062cc700575889d79e7444c9b54c6072a22189d1831d2fbbce/numpy-1.11.2-cp35-none-win32.whl#md5=e485e06907826af5e1fc88608d0629a2

Command execution from Python’s installation path in PowerShell

PS C:\Program Files (x86)\Python35-32> .\python -m pip install C:/Users/MyUsername/Documents/Programs/Python/numpy-1.11.2-cp35-none-win32.whl
Processing c:\users\MyUsername\documents\programs\numpy-1.11.2-cp35-none-win32.whl
Installing collected packages: numpy
Successfully installed numpy-1.11.2
PS C:\Program Files (x86)\Python35-32>

PS.: I installed it on Windows 10.


回答 10

您可以使用来安装.whl文件pip install filename。尽管要以这种形式使用它,但它应该与命令行位于同一目录中,否则请指定完整的文件名以及其地址(例如)pip install C:\Some\PAth\filename

另外,请确保.whl文件与您使用的平台处于同一平台,执行a python -V找出您正在运行的Python版本,如果它是win32或64,则根据其安装正确的版本。

You can install the .whl file, using pip install filename. Though to use it in this form, it should be in the same directory as your command line, otherwise specify the complete filename, along with its address like pip install C:\Some\PAth\filename.

Also make sure the .whl file is of the same platform as you are using, do a python -V to find out which version of Python you are running and if it is win32 or 64, install the correct version according to it.


回答 11

我要做的是先使用命令更新点子: pip install --upgrade pip然后使用命令安装轮pip install wheel,然后完美地工作了。

希望它对您有用。

What I did was first updating the pip by using the command: pip install --upgrade pip and then I also installed wheel by using command: pip install wheel and then it worked perfectly Fine.

Hope it works for you I guess.


回答 12

Windows上的新Python用户通常会在安装过程中忘记将Python的\ Scripts目录添加到PATH变量中。我建议使用Python启动器,并通过-m开关将pip作为脚本执行。然后,您可以安装特定Python版本的轮子(如果已安装多个版本),并且Scripts目录不必位于PATH中。因此,打开命令行,(使用cd命令)导航到.whl文件所在的文件夹,然后输入:

py -3.6 -m pip install your_whl_file.whl

3.6您的Python版本替换,或者输入-3所需的Python版本是否首先出现在PATH中。并在活跃的虚拟环境中:py -m pip install your_whl_file.whl

当然,您也可以通过这种方式从PyPI安装软件包,例如

py -3.6 -m pip install pygame

New Python users on Windows often forget to add Python’s \Scripts directory to the PATH variable during the installation. I recommend to use the Python launcher and execute pip as a script with the -m switch. Then you can install the wheels for a specific Python version (if more than one are installed) and the Scripts directory doesn’t have to be in the PATH. So open the command line, navigate (with the cd command) to the folder where the .whl file is located and enter:

py -3.6 -m pip install your_whl_file.whl

Replace 3.6 by your Python version or just enter -3 if the desired Python version appears first in the PATH. And with an active virtual environment: py -m pip install your_whl_file.whl.

Of course you can also install packages from PyPI in this way, e.g.

py -3.6 -m pip install pygame

回答 13

我会建议您如何安装.whl文件的确切方法。最初我遇到很多问题,但是后来我解决了,这是安装.whl文件的技巧。

正确地遵循步骤以获取模块导入

  1. 确保.whl文件保存在python 2.7 / 3.6 / 3.7 / ..文件夹中。最初,当您下载.whl文件时,该文件保留在下载文件夹中,我的建议是更改文件夹。它使安装文件更加容易。
  2. 打开命令提示符,然后输入以下内容,打开保存文件的文件夹:

cd c:\ python 3.7

3.现在,输入下面写的命令

>py -3.7(version name) -m pip install (file name).whl
  1. 单击输入,并确保以正确的文件名输入当前正在使用的版本。

  2. 按下Enter键后,等待几分钟,文件将被安装,您将能够导入特定的模块。

  3. 为了检查模块是否成功安装,请以空闲状态导入模块并进行检查。

谢谢:)

I would be suggesting you the exact way how to install .whl file. Initially I faced many issues but then I solved it, Here is my trick to install .whl files.

Follow The Steps properly in order to get a module imported

  1. Make sure your .whl file is kept in the python 2.7/3.6/3.7/.. folder. Initially when you download the .whl file the file is kept in downloaded folder, my suggestion is to change the folder. It makes it easier to install the file.
  2. Open command prompt and open the folder where you have kept the file by entering

cd c:\python 3.7

3.Now, enter the command written below

>py -3.7(version name) -m pip install (file name).whl
  1. Click enter and make sure you enter the version you are currently using with correct file name.

  2. Once you press enter, wait for few minutes and the file will be installed and you will be able to import the particular module.

  3. In order to check if the module is installed successfully, import the module in idle and check it.

Thank you:)


回答 14

下载包(.whl)。

将文件放在python目录的script文件夹中

C:\Python36\Scripts

使用命令提示符安装软件包。

C:\Python36\Scripts>pip install package_name.whl

Download the package (.whl).

Put the file inside the script folder of python directory

C:\Python36\Scripts

Use the command prompt to install the package.

C:\Python36\Scripts>pip install package_name.whl

回答 15

在MacOS上(pip通过MacPorts安装到MacPorts python2.7中),我不得不使用@Dunes解决方案:

sudo python -m pip install some-package.whl

python在我的情况下,在哪里被MacPorts python取代了,python2.7或者是python3.5对我对。

-m根据联机帮助页选项为“将库模块作为脚本运行”。

(我以前曾运行sudo port install py27-pip py27-wheel过安装程序,pip然后先wheel进入python 2.7安装程序。)

On the MacOS, with pip installed via MacPorts into the MacPorts python2.7, I had to use @Dunes solution:

sudo python -m pip install some-package.whl

Where python was replaced by the MacPorts python in my case, which is python2.7 or python3.5 for me.

The -m option is “Run library module as script” according to the manpage.

(I had previously run sudo port install py27-pip py27-wheel to install pip and wheel into my python 2.7 installation first.)


错误:找不到vcvarsall.bat

问题:错误:找不到vcvarsall.bat

我试图安装Python软件包dulwich

pip install dulwich

但是我收到了一个神秘的错误消息:

error: Unable to find vcvarsall.bat

如果我尝试手动安装软件包,也会发生相同的情况:

> python setup.py install
running build_ext
building 'dulwich._objects' extension
error: Unable to find vcvarsall.bat

I tried to install the Python package dulwich:

pip install dulwich

But I get a cryptic error message:

error: Unable to find vcvarsall.bat

The same happens if I try installing the package manually:

> python setup.py install
running build_ext
building 'dulwich._objects' extension
error: Unable to find vcvarsall.bat

回答 0

更新:评论指出此处的说明可能很危险。考虑使用Visual C ++ 2008 Express版或专用于Python的Microsoft Visual C ++编译器详细信息),而不要使用下面的原始答案。原始错误消息表示未安装所需的Visual C ++版本。


对于Windows安装:

在运行setup.py进行软件包安装时,Python 2.7搜索已安装的Visual Studio2008。您可以通过VS90COMNTOOLS在调用之前在环境变量中设置正确的路径来诱使Python使用更新的Visual Studio setup.py

根据安装的Visual Studio版本执行以下命令:

  • Visual Studio 2010(VS10): SET VS90COMNTOOLS=%VS100COMNTOOLS%
  • Visual Studio 2012(VS11): SET VS90COMNTOOLS=%VS110COMNTOOLS%
  • Visual Studio 2013(VS12): SET VS90COMNTOOLS=%VS120COMNTOOLS%
  • Visual Studio 2015(VS14): SET VS90COMNTOOLS=%VS140COMNTOOLS%

警告:如下所述,如果您尝试编译python模块,则此答案不太可能起作用。

有关详细信息,请参见在Windows上为Python 2.7构建lxml

Update: Comments point out that the instructions here may be dangerous. Consider using the Visual C++ 2008 Express edition or the purpose-built Microsoft Visual C++ Compiler for Python (details) and NOT using the original answer below. Original error message means the required version of Visual C++ is not installed.


For Windows installations:

While running setup.py for package installations, Python 2.7 searches for an installed Visual Studio 2008. You can trick Python to use a newer Visual Studio by setting the correct path in VS90COMNTOOLS environment variable before calling setup.py.

Execute the following command based on the version of Visual Studio installed:

  • Visual Studio 2010 (VS10): SET VS90COMNTOOLS=%VS100COMNTOOLS%
  • Visual Studio 2012 (VS11): SET VS90COMNTOOLS=%VS110COMNTOOLS%
  • Visual Studio 2013 (VS12): SET VS90COMNTOOLS=%VS120COMNTOOLS%
  • Visual Studio 2015 (VS14): SET VS90COMNTOOLS=%VS140COMNTOOLS%

WARNING: As noted below, this answer is unlikely to work if you are trying to compile python modules.

See Building lxml for Python 2.7 on Windows for details.


回答 1

我找到了解决方案。我安装了“ amara”时遇到了完全相同的问题,并且出现了错误。我安装了mingw32,但需要配置distutils。

  1. 我已经安装了Python 2.6。
  2. 我安装了mingw32 C:\programs\mingw\
  3. 将mingw32的bin目录添加到您的环境变量中:附加c:\programs\MinGW\bin;PATH
  4. 编辑位于以下位置的distutils.cfg文件(如果不存在则创建)C:\Python26\Lib\distutils\distutils.cfg

    [build]
    compiler=mingw32
  5. 现在运行easy_install.exe amara

确保通过打开新环境来设置环境cmd.exe

I found the solution. I had the exact same problem, and error, installing ‘amara’. I had mingw32 installed, but distutils needed to be configured.

  1. I have Python 2.6 that was already installed.
  2. I installed mingw32 to C:\programs\mingw\
  3. Add mingw32’s bin directory to your environment variable: append c:\programs\MinGW\bin; to the PATH
  4. Edit (create if not existing) distutils.cfg file located at C:\Python26\Lib\distutils\distutils.cfg to be:

    [build]
    compiler=mingw32
    
  5. Now run easy_install.exe amara.

Make sure environment is set by opening a new cmd.exe.


回答 2

您可以从http://www.lfd.uci.edu/~gohlke/pythonlibs/安装编译版本


回答 3

如果要使用Visual Studio C ++而不是mingw进行编译…

  1. 运行python.exe以显示使用哪个版本的VC ++(如下所示的示例)。

    它是重要的使用Visual C ++编译器的相应版本的Python用,因为编译distilutilsget_build_version防止混合版本(每彼得的警告)。

    • 黄色(顶部)是使用MSC v.1500(Visual Studio C ++ 2008)编译的Python 2.7。
    • 红色(底部)是使用MSC v.1600(Visual Studio C ++ 2010)编译的Python 3.4.1。

    命令行示例显示了用MSC v.1500编译的Python 2.7和用MSC v.1600编译的Python 3.4.1

  2. 使用下表[1]将内部VC ++版本与相应的Visual Studio版本进行匹配:

    MSC v.1000 -> Visual C++ 4.x        
    MSC v.1100 -> Visual C++ 5          
    MSC v.1200 -> Visual C++ 6          
    MSC v.1300 -> Visual C++ .NET       
    MSC v.1310 -> Visual C++ .NET 2003  
    MSC v.1400 -> Visual C++ 2005  (8.0)
    MSC v.1500 -> Visual C++ 2008  (9.0)
    MSC v.1600 -> Visual C++ 2010 (10.0)
    MSC v.1700 -> Visual C++ 2012 (11.0)
    MSC v.1800 -> Visual C++ 2013 (12.0)
    MSC v.1900 -> Visual C++ 2015 (14.0)
    MSC v.1910 -> Visual C++ 2017 (15.0)
    MSC v.1911 -> Visual C++ 2017 (15.3)
    MSC v.1912 -> Visual C++ 2017 (15.5)
    MSC v.1913 -> Visual C++ 2017 (15.6)
    MSC v.1914 -> Visual C++ 2017 (15.7)
    MSC v.1915 -> Visual C++ 2017 (15.8)
    MSC v.1916 -> Visual C++ 2017 (15.9)   
  3. 从上一步下载并安装相应版本的Visual Studio C ++。
    下面列出了特定版本VC ++的其他说明。

    Visual Studio C ++ 2008的注意事项

    对于只有 32位编译器,下载的Visual Studio C ++ 2008 Express版本

    对于64位编译器[2] [3],请下载Windows 7的Windows SDK和.NET Framework 3.5 SP1

    • 取消选中所有选项,Developer Tools >> Visual C++ Compilers以节省安装SDK工具所需的时间和磁盘空间,否则就不需要使用SDK工具。

    Visual Studio C ++ 2010的注意事项

    根据Microsoft的说法,如果安装了Visual Studio 2010 SP1,则可能已删除VC ++的编译器和库。
    如果是这种情况,请下载Visual C ++ 2010 SP1编译器更新

    Visual Studio C ++ 2015的注意事项

    如果不需要Visual Studio IDE,请下载Visual Studio C ++ 2015构建工具

    Visual Studio C ++ 2017的注意事项

    如果您不需要Visual Studio IDE,请下载Visual Studio 2017的构建工具

    建议:如果您同时安装了32位和64位Python,则可能还希望使用virtualenv创建单独的Python环境,以便一次可以使用一个或另一个,而无需弄乱选择要使用哪个Python版本的路径。采用。

根据@srodriguex的说法,您可以通过遵循以下答案,而不是将一些批处理文件复制到Python正在搜索的位置,从而跳过手动加载批处理文件的步骤(步骤4-6)。如果这不起作用,请执行以下最初对我有用的步骤。

  1. 开一个 cmd.exe

  2. 尝试安装需要C扩展的东西之前,请运行以下批处理文件以将VC ++编译器的环境加载到会话中(即环境变量,编译器的路径等)。

    执行:

    • 32位编译器:

      注意:32位Windows安装将仅C:\Program Files\符合预期

      "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"

    • 64位编译器:

      "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars64.bat"

      注意:是的,本机64位编译器位于中Program Files (x86)。不要问我为什么。
      此外,如果您想知道vcvars64.bat和之间的区别,vcvarsx86_amd64.bat或者更重要的是amd64和之间的区别x86_amd64,则前者用于本机64位编译器工具,而后者是可以在32位Windows安装上运行的64位交叉编译器。 。

    更新:
    如果由于某种原因你得到error: ... was unexpected at this time.其中的...一些一系列字符,那么你需要检查你的路径变量没有任何多余的字符,如额外的报价或杂散字符。如果批处理文件最初没有意义,则将无法更新您的会话路径。

  3. 如果一切顺利,则应根据以下版本的VC ++和运行的命令获得以下消息之一:

    对于32位编译器工具:
    Setting environment for using Microsoft Visual Studio 20xx x86 tools.

    对于64位编译器工具:
    Setting environment for using Microsoft Visual Studio 20xx x64 tools.

  4. 现在,通过python setup.py install或运行设置pip install pkg-name

  5. 希望并用手指指望行星正确对齐,以使VC ++能够合作。

If you want to compile with Visual Studio C++ instead of mingw…

  1. Run python.exe to display which version of VC++ it was compiled with (example shown below).

    It is important to use the corresponding version of the Visual C++ compiler that Python was compiled with since distilutils‘s get_build_version prevents mixing versions (per Piotr’s warning).

    • Yellow (top) is Python 2.7, compiled with MSC v.1500 (Visual Studio C++ 2008)
    • Red (bottom) is Python 3.4.1, compiled with MSC v.1600 (Visual Studio C++ 2010)

    Example from the command line showing Python 2.7 compiled with MSC v.1500 and Python 3.4.1 compiled with MSC v.1600

  2. Use the table below[1] to match the internal VC++ version with the corresponding Visual Studio release:

    MSC v.1000 -> Visual C++ 4.x        
    MSC v.1100 -> Visual C++ 5          
    MSC v.1200 -> Visual C++ 6          
    MSC v.1300 -> Visual C++ .NET       
    MSC v.1310 -> Visual C++ .NET 2003  
    MSC v.1400 -> Visual C++ 2005  (8.0)
    MSC v.1500 -> Visual C++ 2008  (9.0)
    MSC v.1600 -> Visual C++ 2010 (10.0)
    MSC v.1700 -> Visual C++ 2012 (11.0)
    MSC v.1800 -> Visual C++ 2013 (12.0)
    MSC v.1900 -> Visual C++ 2015 (14.0)
    MSC v.1910 -> Visual C++ 2017 (15.0)
    MSC v.1911 -> Visual C++ 2017 (15.3)
    MSC v.1912 -> Visual C++ 2017 (15.5)
    MSC v.1913 -> Visual C++ 2017 (15.6)
    MSC v.1914 -> Visual C++ 2017 (15.7)
    MSC v.1915 -> Visual C++ 2017 (15.8)
    MSC v.1916 -> Visual C++ 2017 (15.9)   
    
  3. Download and install the corresponding version of Visual Studio C++ from the previous step.
    Additional notes for specific versions of VC++ are listed below.

    Notes for Visual Studio C++ 2008

    For only the 32-bit compilers, download Visual Studio C++ 2008 Express Edition.

    For the 64-bit compilers[2][3], download Windows SDK for Windows 7 and .NET Framework 3.5 SP1.

    • Uncheck everything except Developer Tools >> Visual C++ Compilers to save time and disk space from installing SDK tools you otherwise don’t need.

    Notes for Visual Studio C++ 2010

    According to Microsoft, if you installed Visual Studio 2010 SP1, it may have removed the compilers and libraries for VC++.
    If that is the case, download Visual C++ 2010 SP1 Compiler Update.

    Notes for Visual Studio C++ 2015

    If you don’t need the Visual Studio IDE, download Visual Studio C++ 2015 Build Tools.

    Notes for Visual Studio C++ 2017

    If you don’t need the Visual Studio IDE, download Build Tools for Visual Studio 2017.

    Suggestion: If you have both a 32- and 64-bit Python installation, you may also want to use virtualenv to create separate Python environments so you can use one or the other at a time without messing with your path to choose which Python version to use.

According to @srodriguex, you may be able to skip manually loading the batch file (Steps 4-6) by instead copying a few batch files to where Python is searching by following this answer. If that doesn’t work, here are the following steps that originally worked for me.

  1. Open up a cmd.exe

  2. Before you try installing something which requires C extensions, run the following batch file to load the VC++ compiler’s environment into the session (i.e. environment variables, the path to the compiler, etc).

    Execute:

    • 32-bit Compilers:

      Note: 32-bit Windows installs will only have C:\Program Files\ as expected

      "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"

    • 64-bit Compilers:

      "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars64.bat"

      Note: Yes, the native 64-bit compilers are in Program Files (x86). Don’t ask me why.
      Additionally, if you are wondering what the difference between vcvars64.bat and vcvarsx86_amd64.bat or more importantly the difference between amd64 and x86_amd64, the former are for the native 64-bit compiler tools and the latter are the 64-bit cross compilers that can run on a 32-bit Windows installation.

    Update:
    If for some reason you are getting error: ... was unexpected at this time. where the ... is some series of characters, then you need to check that you path variable does not have any extraneous characters like extra quotations or stray characters. The batch file is not going to be able to update your session path if it can’t make sense of it in the first place.

  3. If that went well, you should get one of the following messages depending on which version of VC++ and which command you ran:

    For the 32-bit compiler tools:
    Setting environment for using Microsoft Visual Studio 20xx x86 tools.

    For the 64-bit compiler tools:
    Setting environment for using Microsoft Visual Studio 20xx x64 tools.

  4. Now, run the setup via python setup.py install or pip install pkg-name

  5. Hope and cross your fingers that the planets are aligned correctly for VC++ to cooperate.


回答 4

这是怎么回事?Python模块可以用C或C ++编写(通常是为了提高速度)。如果尝试使用Pip(或setup.py)安装这样的软件包,则必须从源代码编译该C / C ++。开箱即用,Pip会大胆假设您已安装了Microsoft Visual C ++编译器。如果没有它,您将看到此错误消息“错误:无法找到vcvarsall.bat”。

规定的解决方案是安装C / C ++编译器,Microsoft Visual C ++或MinGW(一个开源项目)。但是,安装和配置任何一个都非常困难。(编辑2014:Microsoft已发布了用于Python 2.7 的特殊C ++编译器

最简单的解决方案是将Christoph Gohlke的Windows安装程序(.msi)用于流行的Python软件包。他为Python 2.x和3.x,32位和64位构建安装程序。您可以从http://www.lfd.uci.edu/~gohlke/pythonlibs/下载它们


如果您也认为“错误:无法找到vcvarsall.bat”是一个含糊不清和无用的消息,请在http://bugs.python.org/issue2943上对该错误进行评论,以更有用和更用户化的方式替换它。友好的消息。

为了进行比较,Ruby附带了软件包管理器Gem,并提供了一个准官方的C / C ++编译器DevKit。如果您尝试安装不带该软件包的软件包,则会看到此有用的友好有用消息:

请更新您的PATH以包含构建工具,或从http://rubyinstaller.org/downloads下载DevKit 并按照http://github.com/oneclick/rubyinstaller/wiki/Development-Kit上的说明进行操作

您可以在https://stackoverflow.com/a/13445719/284795上阅读有关Python打包的更长篇文章

What’s going on? Python modules can be part written in C or C++ (typically for speed). If you try to install such a package with Pip (or setup.py), it has to compile that C/C++ from source. Out the box, Pip will brazenly assume you the compiler Microsoft Visual C++ installed. If you don’t have it, you’ll see this cryptic error message “Error: Unable to find vcvarsall.bat”.

The prescribed solution is to install a C/C++ compiler, either Microsoft Visual C++, or MinGW (an open-source project). However, installing and configuring either is prohibitively difficult. (Edit 2014: Microsoft have published a special C++ compiler for Python 2.7)

The easiest solution is to use Christoph Gohlke’s Windows installers (.msi) for popular Python packages. He builds installers for Python 2.x and 3.x, 32 bit and 64 bit. You can download them from http://www.lfd.uci.edu/~gohlke/pythonlibs/


If you too think “Error: Unable to find vcvarsall.bat” is a ludicrously cryptic and unhelpful message, then please comment on the bug at http://bugs.python.org/issue2943 to replace it with a more helpful and user-friendly message.

For comparison, Ruby ships with a package manager Gem and offers a quasi-official C/C++ compiler, DevKit. If you try to install a package without it, you see this helpful friendly useful message:

Please update your PATH to include build tools or download the DevKit from http://rubyinstaller.org/downloads and follow the instructions at http://github.com/oneclick/rubyinstaller/wiki/Development-Kit

You can read a longer rant about Python packaging at https://stackoverflow.com/a/13445719/284795


回答 5

您需要安装与用于构建Python的编译器兼容的Microsoft编译器。这意味着您需要Visual C ++ 2008(或更高版本,需要进行一些调整)。

微软现在提供一个捆绑的编译器和头能够编译Python扩展,在好记的网址:

适用于Python 2.7的Microsoft Visual C ++编译器

http://aka.ms/vcpython27

这是一个相对较小的包装;下载85MB,无需管理员权限即可安装,无需重新启动。名称有点误导,该编译器适用于最初使用Visual C ++ 2008编译的任何Python版本,而不仅仅是Python 2.7。

如果您启动Python交互式提示或print sys.version,请查找MSC版本字符串;否则,请执行以下操作:如果是这样,MSC v.1500您可以使用此工具。

原始公告到distutils列表

微软已经发布了适用于Python 2.7的编译器软件包,以使人们可以更轻松地在Windows上构建和分发C扩展模块。可从以下网站获得用于Python 2.7的Microsoft Visual C ++编译器(aka VC9):http : //aka.ms/vcpython27

该软件包包含为32位和64位Python 2.7构建C扩展模块所需的所有工具和头文件(请注意,某些扩展模块需要第三方的依赖项,例如OpenSSL或libxml2,但不包括在内)。还支持使用Visual C ++ 2008构建的其他Python版本,因此“ Python 2.7”仅是广告-可以在2.6和3.2上正常工作。

请注意,您需要安装setuptools6.0或更高版本(在下载页面的系统要求中列出)。您正在安装的项目必须使用setuptools.setup(),而不是,distutils否则自动检测将不起作用。

Microsoft已声明他们希望保持URL稳定,以便自动脚本可以轻松引用它。

You’ll need to install a Microsoft compiler, compatible with the compiler used to build Python. This means you need Visual C++ 2008 (or newer, with some tweaking).

Microsoft now supplies a bundled compiler and headers just to be able to compile Python extensions, at the memorable URL:

Microsoft Visual C++ Compiler for Python 2.7

http://aka.ms/vcpython27

This is a relatively small package; 85MB to download, installable without admin privileges, no reboot required. The name is a little misleading, the compiler will work for any Python version originally compiled with Visual C++ 2008, not just Python 2.7.

If you start a Python interactive prompt or print sys.version, look for the MSC version string; if it is MSC v.1500 you can use this tool.

From the original announcement to the distutils list:

Microsoft has released a compiler package for Python 2.7 to make it easier for people to build and distribute their C extension modules on Windows. The Microsoft Visual C++ Compiler for Python 2.7 (a.k.a. VC9) is available from: http://aka.ms/vcpython27

This package contains all the tools and headers required to build C extension modules for Python 2.7 32-bit and 64-bit (note that some extension modules require 3rd party dependencies such as OpenSSL or libxml2 that are not included). Other versions of Python built with Visual C++ 2008 are also supported, so “Python 2.7” is just advertising – it’ll work fine with 2.6 and 3.2.

Note that you need to have setuptools 6.0 or newer installed (listed in the system requirements on the download page). The project you are installing must use setuptools.setup(), not distutils or the auto-detection won’t work.

Microsoft has stated that they want to keep the URL stable, so that automated scripts can reference it easily.


回答 6

我只是遇到了同样的问题,所以我在这里讲述我的故事,希望它可以帮助遇到同样问题的其他人,并为他们节省几个小时的时间:

我在Windows 7盒子中有mingw(g ++(GCC)4.6.1)和python 2.7.3,我正在尝试安装PyCrypto。

运行setup.py install时,所有错误均始于此错误:

error: Unable to find vcvarsall.bat

通过将mingw指定为选择的编译器,可以轻松地在搜索错误之后解决此问题:

setup.py install build --compiler=mingw32

问题是然后我得到了另一个错误:

configure: error: cannot run C compiled programs.

事实证明,我的防病毒软件阻止了新编译的.exe的执行。我只是禁用了防病毒“居民防护罩”,然后转到下一个错误:

cc1.exe: error: unrecognized command line option '-mno-cygwin' 
error: command 'gcc' failed with exit status 1

解决了它:“要么安装稍旧版本的MinGW,要么在您的Python目录中编辑distutils \ cygwinccompiler.py以删除-mno-cygwin的所有实例。” (从这里开始

现在,我终于可以开始工作了。

I just had this same problem, so I’ll tell my story here hoping it helps someone else with the same issues and save them the couple of hours I just spent:

I have mingw (g++ (GCC) 4.6.1) and python 2.7.3 in a windows 7 box and I’m trying to install PyCrypto.

It all started with this error when running setup.py install:

error: Unable to find vcvarsall.bat

Easily solved after googling the error by specifying mingw as the compiler of choice:

setup.py install build --compiler=mingw32

The problem is that then I got a different error:

configure: error: cannot run C compiled programs.

It turns out that my anti-virus was blocking the execution of a freshly compiled .exe. I just disabled the anti-virus “resident shield” and went to the next error:

cc1.exe: error: unrecognized command line option '-mno-cygwin' 
error: command 'gcc' failed with exit status 1

This solved it: “Either install a slightly older version of MinGW, or edit distutils\cygwinccompiler.py in your Python directory to remove all instances of -mno-cygwin.” (from here)

Now, I can finally start working.


回答 7

看起来它正在寻找VC编译器,因此您可以尝试使用来提及编译器类型-c mingw32,因为您拥有msys

python setup.py install -c mingw32

Looks like its looking for VC compilers, so you could try to mention compiler type with -c mingw32, since you have msys

python setup.py install -c mingw32

回答 8

我有python 2.73和Windows 7。对我有用的解决方案是:

  1. 新增的mingw32的bin目录到环境变量:追加PATHC:\programs\mingw\bin;
  2. 创建的distutils.cfg位于C:\Python27\Lib\distutils\distutils.cfg

    [build]
    compiler=mingw32

要处理MinGW不再识别-mno-cygwin标志的情况,请删除C:\ Python27 \ Lib \ distutils \ cygwincompiler.py第322行至326行中的标志,因此如下所示:

  self.set_executables(compiler='gcc -O -Wall',
                         compiler_so='gcc -mdll -O -Wall',
                         compiler_cxx='g++ -O -Wall',
                         linker_exe='gcc',
                         linker_so='%s %s %s'
                                    % (self.linker_dll, shared_option,
                                       entry_point))

I have python 2.73 and windows 7 .The solution that worked for me was:

  1. Added mingw32’s bin directory to environment variable: append PATH with C:\programs\mingw\bin;
  2. Created distutils.cfg located at C:\Python27\Lib\distutils\distutils.cfg containing:

    [build]
    compiler=mingw32
    

To deal with MinGW not recognizing the -mno-cygwin flag anymore, remove the flag in C:\Python27\Lib\distutils\cygwincompiler.py line 322 to 326, so it looks like this:

  self.set_executables(compiler='gcc -O -Wall',
                         compiler_so='gcc -mdll -O -Wall',
                         compiler_cxx='g++ -O -Wall',
                         linker_exe='gcc',
                         linker_so='%s %s %s'
                                    % (self.linker_dll, shared_option,
                                       entry_point))

回答 9

查看setup.py您要安装的软件包的文件。如果是较旧的软件包,则可能是导入distutils.core.setup()而不是setuptools.setup()

我在2015年遇到了以下这些因素:

  1. 来自http://aka.ms/vcpython27的适用于Python 2.7的Microsoft Visual C ++编译器

  2. 使用较旧的软件包 distutils.core.setup()

  3. 尝试做python setup.py build而不是使用pip

如果您使用的是最新版本的pip,则它将强制(monkeypatch)软件包使用setuptools,即使其setup.py对distutils的调用也是如此。但是,如果您不使用pip而是在做python setup.py build,则构建过程将使用distutils.core.setup(),而后者不知道编译器的安装位置。


步骤1:打开适当的Visual C ++ 2008命令提示符

打开“开始”菜单或“开始”屏幕,然后搜索“ Visual C ++ 2008 32位命令提示符”(如果您的Python是32位)或“ Visual C ++ 2008 64位命令提示符”(如果您的Python是64位) 。运行。命令提示符在标题栏中应显示Visual C ++ 2008…。

步骤2:设定环境变数

在刚打开的命令提示符中设置这些环境变量。

SET DISTUTILS_USE_SDK=1
SET MSSdk=1

参考http://bugs.python.org/issue23246

步骤3:建立并安装

cd到要构建并运行的包python setup.py build,然后python setup.py install。如果要安装到virtualenv,请在构建之前将其激活。

Look in the setup.py file of the package you are trying to install. If it is an older package it may be importing distutils.core.setup() rather than setuptools.setup().

I ran in to this (in 2015) with a combination of these factors:

  1. The Microsoft Visual C++ Compiler for Python 2.7 from http://aka.ms/vcpython27

  2. An older package that uses distutils.core.setup()

  3. Trying to do python setup.py build rather than using pip.

If you use a recent version of pip, it will force (monkeypatch) the package to use setuptools, even if its setup.py calls for distutils. However, if you are not using pip, and instead are just doing python setup.py build, the build process will use distutils.core.setup(), which does not know about the compiler install location.


Solution

Step 1: Open the appropriate Visual C++ 2008 Command Prompt

Open the Start menu or Start screen, and search for “Visual C++ 2008 32-bit Command Prompt” (if your python is 32-bit) or “Visual C++ 2008 64-bit Command Prompt” (if your python is 64-bit). Run it. The command prompt should say Visual C++ 2008 … in the title bar.

Step 2: Set environment variables

Set these environment variables in the command prompt you just opened.

SET DISTUTILS_USE_SDK=1
SET MSSdk=1

Reference http://bugs.python.org/issue23246

Step 3: Build and install

cd to the package you want to build, and run python setup.py build, then python setup.py install. If you want to install in to a virtualenv, activate it before you build.


回答 10

也许有人会感兴趣,以下对py2exe软件包有用。(我有Windows 7 64位和便携式python 2.7,带有适用于Windows 7和.NET Framework 4的Windows SDK的Visual Studio 2005 Express)

set VS90COMNTOOLS=%VS80COMNTOOLS%

然后:

python.exe setup.py install

Maybe somebody can be interested, the following worked for me for the py2exe package. (I have windows 7 64 bit and portable python 2.7, Visual Studio 2005 Express with Windows SDK for Windows 7 and .NET Framework 4)

set VS90COMNTOOLS=%VS80COMNTOOLS%

then:

python.exe setup.py install

回答 11

我花了将近2天的时间弄清楚如何在python 3.4 64位版本中解决此问题:Python 3.4.3(v3.4.3:9b73f1c3e601,Feb 24 2015,22:44:40)[MSC v.1600 64位(AMD64 )]在win32上

困难的解决方案1 ​​:(在阅读本文之前,请先阅读下面的解决方案2)最后,这对我有帮助:

  1. 安装Visual C ++ 2010 Express
  2. 为Windows 7安装Microsoft Windows SDK v7.1
  3. 手动创建文件vcvars64.batC:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64其中包含CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64或其他路径,具体取决于安装位置
  4. (这似乎是可选的)针对Windows SDK 7.1安装Microsoft Visual Studio 2010 Service Pack 1以及Microsoft Visual C ++ 2010 Service Pack 1编译器更新
  5. 之后,我尝试pip install numpy但收到以下错误:

    File "numpy\core\setup.py", line 686, in get_mathlib_info
    raise RuntimeError("Broken toolchain: cannot link a simple C program")
    RuntimeError: Broken toolchain: cannot link a simple C program

    我改mfinfoNoneC:\Python34\Lib\distutils\msvc9compiler.py每本https://stackoverflow.com/a/23099820/4383472

  6. 最终在pip install numpy命令后,我的avast防病毒软件试图干扰安装过程,但我很快将其禁用

花费了很长时间-numpy编译了几分钟,我什至以为出现了错误,但最终一切都OK。

解决方案2,简单:( 我知道这种方法已经在高度投票的答案中提到过,但是由于它确实更容易,所以让我重复一下)经过所有这些工作之后,我了解到对我来说最好的方法就是使用将来可从http://www.lfd.uci.edu/~gohlke/pythonlibs/预编译二进制文件。我极少需要此网站不包含的某些软件包(或软件包的版本)。这种方式的安装过程也更快。例如,安装numpy

  1. numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl从该站点下载(如果您具有Python 3.4 64位)
  2. 在命令提示符或Powershell中使用pip安装pip install numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl(或文件的完整路径,具体取决于打开命令提示符的方式)

I spent almost 2 days figuring out how to fix this problem in my python 3.4 64 bit version: Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32

Solution 1, hard: (before reading this, read first Solution 2 below) Finally, this is what helped me:

  1. install Visual C++ 2010 Express
  2. install Microsoft Windows SDK v7.1 for Windows 7
  3. create manually file vcvars64.bat in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 which contains CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 or other path depending on where you have yours installed
  4. (this seems to be optional) install Microsoft Visual Studio 2010 Service Pack 1 together with Microsoft Visual C++ 2010 Service Pack 1 Compiler Update for the Windows SDK 7.1
  5. after that I tried to pip install numpy but received the following error:

    File "numpy\core\setup.py", line 686, in get_mathlib_info
    raise RuntimeError("Broken toolchain: cannot link a simple C program")
    RuntimeError: Broken toolchain: cannot link a simple C program
    

    I changed mfinfo to None in C:\Python34\Lib\distutils\msvc9compiler.py per this https://stackoverflow.com/a/23099820/4383472

  6. finally after pip install numpy command my avast antivirus tried to interfere into the installation process, but i quickly disabled it

It took very long – several minutes for numpy to compile, I even thought that there was an error, but finally everything was ok.

Solution 2, easy: (I know this approach has already been mentioned in a highly voted answer, but let me repeat since it really is easier) After going through all of this work I understood that the best way for me is just to use already precompiled binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/ in future. There is very small chance that I will ever need some package (or a version of a package) which this site doesn’t contain. The installation process is also much quicker this way. For example, to install numpy:

  1. donwload numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl (if you have Python 3.4 64-bit) from that site
  2. in command prompt or powershell install it with pip pip install numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl (or full path to the file depending how command prompt is opened)

回答 12

我想在Windows 10上的python 2.7下运行pysph并找不到vcvarsall.bat(来自distutils)

我的解决方案如下:

为Python 2.7安装Microsoft Visual C ++(建议@Michael)

在Windows 10上,它已安装到(我的用户名是Andreas):

C:\Users\Andreas\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

设置环境变量VS90COMNTOOLS为Visual C ++ for Python 2.7的安装路径(请参见上面的路径)。

如果仍然无法使用,请在模块中进行修改

C:/Python27/lib/distutils

文件msvc9compiler.py。在其中找到功能find_vcvarsall并进行以下修改。

替换行:

productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")

productdir = os.path.join(toolsdir)

在我的情况下,这就是vcvarsall.bat所在的位置(请检查vcvarsall.bat在您的安装位置中)。

I wanted to run pysph on Windows 10 under Python 2.7 and got vcvarsall.bat was not found (from distutils)

My solution was the following:

Install Microsoft Visual C++ for Python 2.7 (like @Michael suggested)

On Windows 10 it was installed into (my username is Andreas):

C:\Users\Andreas\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

Set environment variable VS90COMNTOOLS to the installation path of Visual C++ for Python 2.7 (see above path).

If it still doesn’t work, then modifiy in the module

C:/Python27/lib/distutils

the file msvc9compiler.py. Find in it the function find_vcvarsall and do following modification.

Replace the line:

productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")

with

productdir = os.path.join(toolsdir)

This is where vcvarsall.bat resides in my case (check, where vcvarsall.bat is in your installation).


回答 13

当我尝试在python 3.5上安装numpy库时遇到此问题。解决的办法是安装VS2015。我有VS2008、2012、2013,其中没有一个与python 3.5兼容。显然,较新版本的python依赖于较新版本的VS。

还要确保Visual Studio已安装C ++通用工具。

在此处输入图片说明

I encountered this issue when I tried to install numpy library on my python 3.5. The solution is to install VS2015. I had VS2008, 2012, 2013, none of which is compatible with python 3.5. Apparently newer version of python has dependency on newer versions of VS.

Also make sure C++ Common Tools are installed with Visual Studio.

enter image description here


回答 14

我尝试了上述所有答案,但发现它们都不起作用,这可能是我使用Windows 8并安装了Visual Studio2012。在这种情况下,这就是您要做的。

vcvarsall.bat文件位于此处: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC

只需选择文件,然后将其复制。

然后转到此目录: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools

并粘贴文件。然后,一切都会好起来。

I tried all the above answers, and found all of them not to work, this was perhaps I was using Windows 8 and had installed Visual Studio 2012. In this case, this is what you do.

The vcvarsall.bat file is located here: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC

Simply select the file, and copy it.

Then go to this directory: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools

and paste the file. And then, all should be well.


回答 15

您可以从http://go.microsoft.com/?linkid=7729279下载免费的Visual C ++ 2008 Express Edition ,它将在安装过程中设置VS90COMNTOOLS环境变量,并因此使用兼容的编译器进行构建。

正如@PiotrDobrogost在评论中提到的那样,他对另一个问题的回答详细介绍了为什么要使用Visual C ++ 2008构建正确的东西,但是随着Windows的Python构建转移到更新版本的Visual Studio,这种情况可能会改变:构建lxml适用于Windows上的Python 2.7

You can download the free Visual C++ 2008 Express Edition from http://go.microsoft.com/?linkid=7729279, which will set the VS90COMNTOOLS environment variable during installation and therefore build with a compatible compiler.

As @PiotrDobrogost mentioned in a comment, his answer to this other question goes into details about why Visual C++ 2008 is the right thing to build with, but this can change as the Windows build of Python moves to newer versions of Visual Studio: Building lxml for Python 2.7 on Windows


回答 16

在Windows 7 x64上使用Python 3.4.1遇到了这个问题,不幸的是,我需要的软件包没有合适的exe或wheel可供使用。该系统需要一些“解决方法”,下面对此进行了详细说明(底部是TLDR)。

使用上面Jaxrtech的答案中的信息,我确定我需要Visual Studio C ++ 2010(sys.version返回MSC v.1600),因此我从他的答案中的链接http://go.microsoft安装了Visual C ++ 2010 Express。.com /?linkid = 9709949。我安装了所有带有更新的内容,但是正如您在下面看到的那样,这是一个错误。此时仅应安装Express的原始版本(不更新任何内容)。

vcvarsall.bat现在存在,但是在安装软件包时出现了新错误query_vcvarsall raise ValueError(str(list(result.keys())))ValueError: [u'path']。还有其他与此错误有关的stackoverflow问题,例如为Python 2.7构建/安装C模块时出现的错误

根据该答案,我确定2010 Express仅安装32位编译器。要获取64位(和其他)编译器,您需要安装Windows 7.1 SDK。请参阅http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx

但是,这不会为我安装,安装程序返回了错误installation failed with return code 5100。我在以下链接中找到了解决方案:http : //support.microsoft.com/kb/2717426。简而言之,如果安装了x86和x64 Microsoft Visual C ++ 2010 Redistributable的较新版本,它们将与SDK安装程序中的版本冲突,因此需要先进行卸载。

然后安装了SDK,但是我注意到vcvars64.bat仍然不存在C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin,也没有其子文件夹。vcvarsall.bat运行vcvars64批处理文件,因此如果没有该文件,python软件包仍将无法安装(我忘记了此时显示的错误)。

然后 ,我在这里找到了一些说明:http : //www.cryptohaze.com/wiki/index.php/Windows_7_Build_Setup#Download_VS_2010_and_Windows_SDK_7.1按照说明,我已经安装了Express和7.1 SDK,因此安装了SDK 7.1 SP1,并做了缺少头文件修复。然后,我使用content手动创建vcvars64.bat CALL setenv /x64。我将所有这些说明粘贴在这里,以免丢失。

步骤1是下载Visual Studio Express 2010。

http://www.microsoft.com/visualstudio/zh-cn/products/2010-editions/express 是一个不错的起点。下载安装程序,然后运行它(vc_web.exe)。您不需要SQL 2008的其他下载。

对于64位编译器,您还需要Windows SDK(当前为7.1)-除非您只想进行32位构建,否则将不完全支持…

http://www.microsoft.com/zh-cn/download/details.aspx?id=8279是下载此文件的好起点-下载后,您将要运行winsdk_web.exe!

这里的默认安装就可以了。

最后,下载并安装Windows SDK 7.1 SP1更新:http : //www.microsoft.com/zh-cn/download/details.aspx?id=4422

并且,要修复缺少的头文件,VS2010 SP1。 http://www.microsoft.com/downloads/zh-CN/confirmation.aspx?FamilyID=75568aa6-8107-475d-948a-ef22627e57a5

而且,该死的,为VS2010 Express修复丢失的批处理文件。这真是荒唐可笑。

在C:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ VC \ bin \ amd64中,使用以下命令创建“ vcvars64.bat”(您将需要以管理员身份运行):

呼叫setenv / x64

我的python软件包仍然没有安装(无法回忆起错误)。然后,我找到了一些使用特殊的SDK 7.1命令提示符的说明(在下面复制),请参阅:https : //mail.python.org/pipermail/distutils-sig/2012-February/018300.html

没关系,这个问题。此处有人在菜单上注意到此项目:开始->所有程序-> Microsoft Windows SDK v7.1-> Windows SDK 7.1命令提示符

这将运行一个批处理作业,该作业似乎为编译器设置了工作环境。在该提示下,您可以键入“ setup.py build”或“ setup.py install”。

我按照指示打开了Windows SDK 7.1命令提示符,并使用它在python软件包上运行easy_install。最后,成功!


TLDR ;

  1. 安装Visual Studio Express 2010(最好没有更新的可再发行文件或SQL Server)。
  2. 安装Windows 7.1 SDK
  3. Instal SDK 7.1 SP1更新和VS2010 SP1标头文件修复(可能不需要此步骤)。
  4. 手动创建C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\vcvars64.bat内容CALL setenv /x64
  5. 开始->所有程序-> Microsoft Windows SDK v7.1-> Windows SDK 7.1命令提示符以打开特殊的x64命令提示符,然后可以将其与python / easy_install / pip / etc(包括virtual_envs中的命令)一起使用。

I had this problem using Python 3.4.1 on Windows 7 x64, and unfortunately the packages I needed didn’t have suitable exe or wheels that I could use. This system requires a few ‘workarounds’, which are detailed below (and TLDR at bottom).

Using the info in Jaxrtech’s answer above, I determined I needed Visual Studio C++ 2010 (sys.version return MSC v.1600), so I installed Visual C++ 2010 Express from the link in his answer, which is http://go.microsoft.com/?linkid=9709949. I installed everything with updates, but as you can read below, this was a mistake. Only the original version of Express should be installed at this time (no updated anything).

vcvarsall.bat was now present, but there was a new error when installing the package, query_vcvarsall raise ValueError(str(list(result.keys())))ValueError: [u'path']. There are other stackoverflow questions with this error, such as Errors while building/installing C module for Python 2.7

I determined from that answer that 2010 Express only installs 32-bit compilers. To get 64-bit (and other) compilers, you need to install Windows 7.1 SDK. See http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx

This would not install for me though, and the installer returned the error installation failed with return code 5100. I found the solution at the following link: http://support.microsoft.com/kb/2717426. In short, if newer versions of x86 and x64 Microsoft Visual C++ 2010 Redistributable’s are installed, they conflict with the ones in SDK installer, and need uninstalling first.

The SDK then installed, but I noticed vcvars64.bat still did not exist in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin, nor its subfolders. vcvarsall.bat runs the vcvars64 batch file, so without it, the python package still wouldn’t install (I forgot the error that was shown at this time).

I then found some instructions here: http://www.cryptohaze.com/wiki/index.php/Windows_7_Build_Setup#Download_VS_2010_and_Windows_SDK_7.1 Following the instructions, I had already installed Express and 7.1 SDK, so installed SDK 7.1 SP1, and did the missing header file fix. I then manually created vcvars64.bat with the content CALL setenv /x64. I will paste all those instructions here, so they don’t get lost.

Step 1 is to download Visual Studio Express 2010.

http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express is a good place to start. Download the installer, and run it (vc_web.exe). You don’t need the SQL 2008 additional download.

You’ll also need the Windows SDK (currently 7.1) for the 64-bit compilers – unless you want to do 32-bit only builds, which are not fully supported…

http://www.microsoft.com/en-us/download/details.aspx?id=8279 is a good starting point to download this – you’ll want to run winsdk_web.exe when downloaded!

The default install here is just fine.

Finally, download and install the Windows SDK 7.1 SP1 update: http://www.microsoft.com/en-us/download/details.aspx?id=4422

And, to fix missing header file, VS2010 SP1. http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyID=75568aa6-8107-475d-948a-ef22627e57a5

And, bloody hell, fix the missing batch file for VS2010 Express. This is getting downright absurd.

In C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64, create “vcvars64.bat” with the following (you will need to be running as administrator):

CALL setenv /x64

My python package still did not install (can’t recall error). I then found some instructions (copied below) to use the special SDK 7.1 Command Prompt, see: https://mail.python.org/pipermail/distutils-sig/2012-February/018300.html

Never mind this question. Somebody here noticed this item on the menu: Start->All Programs->Microsoft Windows SDK v7.1 ->Windows SDK 7.1 Command Prompt

This runs a batch job that appears to set up a working environment for the compiler. From that prompt, you can type “setup.py build” or “setup.py install”.

I opened the Windows SDK 7.1 Command Prompt as instructed, and used it to run easy_install on the python package. And at last, success!


TLDR;

  1. Install Visual Studio Express 2010 (preferably without updated redistributables or SQL server).
  2. Install Windows 7.1 SDK
  3. Instal SDK 7.1 SP1 update, and VS2010 SP1 header file fix (this step may not be required).
  4. Manually create C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\vcvars64.bat with content CALL setenv /x64
  5. Start->All Programs->Microsoft Windows SDK v7.1 ->Windows SDK 7.1 Command Prompt to open special x64 command prompt, which can then be used with python/easy_install/pip/etc (including those in virtual_envs).

回答 17

下面的步骤为我解决了这个问题,我试图用cython扩展创建安装程序。

  1. 安装适用于Python 2.7的Microsoft Visual C ++编译器
  2. 默认安装位置为@ C:\ Users \ PC-user \ AppData \ Local \ Programs \ Common \ Microsoft \ Visual C ++ for Python。这实际上可以解决此问题,请在继续操作之前进行一次测试。
  3. 如果失败,请检查VC ++中python vcvarsall.bat文件的位置。
  4. 在记事本中打开distutils软件包的msvc9compiler.py文件。
  5. 在我的框中,这是该文件中的@ C:\ Anaconda2 \ Lib \ distutils \ msvc9compiler.py find_vcvarsall函数,通过打印出版本参数来确定VC的版本。对于Python 2.7,可能是9.0
  6. 现在创建一个环境变量VS90COMNTOOLS,指向C:\ Users \ PC-user \ AppData \ Local \ Programs \ Common \ Microsoft \ Visual C ++ for Python \ 9.0 \ VC \ bin
  7. 由于某种原因,distutils期望vcvarsall.bat文件位于VC目录中,但是python工具的VC ++在9.0的根目录中有此文件。要解决此问题,请从path.join中删除“ VC”(大约在247行附近)

    #productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC") productdir = os.path.join(toolsdir, os.pardir, os.pardir)

上面的步骤为我解决了这个问题。

Below steps fixed this issue for me, I was trying to create setup with cython extension.

  1. Install Microsoft Visual C++ Compiler for Python 2.7
  2. The default install location would be @ C:\Users\PC-user\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python This might actually fix the issue, test once before proceeding.
  3. If it fails, Check where in VC++ for python vcvarsall.bat file is located
  4. Open the msvc9compiler.py file of distutils package in notepad.
  5. In my box this was @ C:\Anaconda2\Lib\distutils\msvc9compiler.py find_vcvarsall function in this file, determine the version of VC by printing out version argument. For Python 2.7 it’s likely to be 9.0
  6. Now create an environment variable VS90COMNTOOLS, Pointing to C:\Users\PC-user\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\bin
  7. For some reason distutils expects the vcvarsall.bat file to be within VC dir, but VC++ for python tools has it in the root of 9.0 To fix this, remove “VC” from the path.join (roughly around line 247)

    #productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC") productdir = os.path.join(toolsdir, os.pardir, os.pardir)

The above steps fixed the issue for me.


回答 18

我尝试了许多解决方案,但只有一种对我有用,即安装Microsoft Visual Studio 2008 Express C ++。

我用用C编写的Python 2.7模块(yEnc,MS VS还有其他问题)遇到了这个问题。请注意,Python 2.7是使用MS VS 2008版本而非2010构建的!

尽管它是免费的,但由于MS正在推广VS 2010,因此很难找到它。但是,MSDN官方非常直接的链接仍在起作用:请访问https://stackoverflow.com/a/15319069/2227298以获取下载链接。

I tried many solutions but only one worked for me, the install of Microsoft Visual Studio 2008 Express C++.

I got this issue with a Python 2.7 module written in C (yEnc, which has other issues with MS VS). Note that Python 2.7 is built with MS VS 2008 version, not 2010!

Despite the fact it’s free, it is quite hard to find since MS is promoting VS 2010. Still, the MSDN official very direct links are still working: check https://stackoverflow.com/a/15319069/2227298 for download links.


回答 19

如果您已安装mingw

pip install --global-option build_ext --global-option --compiler=mingw32 packagename

起作用,迫使pip使用mingw编译器而不是Microsoft的编译器进行构建。有关详细信息,请参见https://github.com/pypa/pip/issues/18(最新文章)。

If you have mingw installed

pip install --global-option build_ext --global-option --compiler=mingw32 packagename

works, forcing pip to build using the mingw compiler instead of Microsoft’s. See here https://github.com/pypa/pip/issues/18 for details (last post).


回答 20

http://www.microsoft.com/zh-cn/download/details.aspx?id=44266上的 Python 2.7版Microsoft Visual C ++编译器不是解决方案吗?

Is Microsoft Visual C++ Compiler for Python 2.7 at http://www.microsoft.com/en-us/download/details.aspx?id=44266 not a solution?


回答 21

在2016年解决此问题的最简单方法是先安装Chocolatey,然后再安装该 vcpython27软件包。打开Powershell:

> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
> choco install python2 -y
> choco install vcpython27 -y

The easiest way to solve this in 2016 is to install Chocolatey and then the vcpython27 package. Open Powershell:

> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
> choco install python2 -y
> choco install vcpython27 -y

回答 22

我不知道这是否是为时已晚,但我发现微软的Visual C ++编译器为Python 2.7读取

如果需要此编译器包,您将收到的典型错误消息是找不到vcvarsall.bat

希望这可以帮助!

I don’t know if it is too late, but I found Microsoft Visual C++ Compiler for Python 2.7 which reads

The typical error message you will receive if you need this compiler package is Unable to find vcvarsall.bat

Hope this helps!


回答 23

我遇到了同样的问题,目前已经解决了。

“ Google”告诉我,我需要安装“ Python 2.7的Microsoft Visual C ++编译器”。我不仅安装了该工具,还安装了Visual C ++ 2008 Reditributable,但这并没有帮助。然后,我尝试安装Visual C ++ 2008 Express Edition。问题已经解决了!

只需尝试安装Visual C ++ 2008 Express Edition!

I got the same problem and have solved it at the moment.

“Google” told me that I need to install “Microsoft Visual C++ Compiler for Python 2.7”. I install not only the tool, but also Visual C++ 2008 Reditributable, but it didn’t help. I then tried to install Visual C++ 2008 Express Edition. And the problem has gone!

Just try to install Visual C++ 2008 Express Edition!


回答 24

调用import setuptools将Monkey补丁distutils强制与Visual Studio兼容。vcvars32.bat手动调用将设置虚拟环境,并防止编译器引发其他常见错误。对于VS 2017,文件位于

“ C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Community \ VC \ Auxiliary \ Build \ vcvars32.bat”

这是我用来快速将.pyx文件编译为.pyd的安装脚本:(注意:它使用第三方模块 send2trash

# cython_setup.py
import sys, os, time, platform, subprocess
from setuptools import setup, find_packages
from Cython.Build import cythonize
from traceback import format_exc

# USAGE:
#
#   from cython_setup import run
#   run(pyx_path)

# vcvars = r"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"

# NOTE: to use visual studio 2017 you must have setuptools version 34+
vcvars = r"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars32.bat"


def _build_ext():
    try:
        pyx_path = sys.argv.pop(-1)
        pyx_path = os.path.abspath(pyx_path)
        if not os.path.exists(pyx_path):
            raise FileNotFoundError(f"{pyx_path} does not exist")
        project_name = sys.argv.pop(-1)
        os.chdir(os.path.abspath(os.path.dirname(pyx_path)))

        print("cwd: %s" % os.getcwd())
        print(os.path.abspath("build"))
        setup(
            name=project_name,
            # cmdclass = {'build_ext': build_ext},
            packages=find_packages(),
            # ext_modules=cythonize(extensions)
            ext_modules=cythonize(pyx_path,
                                  compiler_directives={'language_level': 3, 'infer_types': True, 'binding': False},
                                  annotate=True),
            # include_dirs = [numpy.get_include()]
            build_dir=os.path.abspath("build")
        )
    except:
        input(format_exc())


def retry(func):
    def wrapper(*args, **kw):
        tries = 0
        while True:
            try:
                return func(*args, **kw)
            except Exception:
                tries += 1
                if tries > 4:
                    raise
                time.sleep(0.4)

    return wrapper


@retry
def cleanup(pyx_path):
    from send2trash import send2trash
    c_file = os.path.splitext(pyx_path)[0] + ".c"
    if os.path.exists(c_file):
        os.remove(c_file)

    if os.path.exists("build"):
        send2trash("build")


def move_pyd_files(pyx_path):
    pyx_dir = os.path.dirname(pyx_path)
    build_dir = os.path.join(pyx_dir, "build")
    if not os.path.exists(build_dir):
        raise RuntimeError(f"build_dir {build_dir} did not exist....")
    found_pyd = False
    for top, dirs, nondirs in os.walk(build_dir):
        for name in nondirs:
            if name.lower().endswith(".pyd") or name.lower().endswith(".so"):
                found_pyd = True
                old_path = os.path.join(top, name)
                new_path = os.path.join(pyx_dir, name)
                if os.path.exists(new_path):
                    print(f"removing {new_path}")
                    os.remove(new_path)
                print(f"file created at {new_path}")
                os.rename(old_path, new_path)
    if not found_pyd:
        raise RuntimeError("Never found .pyd file to move")

def run(pyx_path):
    """
    :param pyx_path:
    :type pyx_path:
    :return: this function creates the batch file, which in turn calls this module, which calls cythonize, once done
    the batch script deletes itself... I'm sure theres a less convoluted way of doing this, but it works
    :rtype:
    """
    try:
        project_name = os.path.splitext(os.path.basename(pyx_path))[0]
        run_script(project_name, os.path.abspath(pyx_path))
    except:
        input(format_exc())


def run_script(project_name, pyx_path):
    dirname = os.path.dirname(pyx_path)
    # ------------------------------
    os.chdir(dirname)
    if os.path.exists(vcvars):
        #  raise RuntimeError(
        # f"Could not find vcvars32.bat at {vcvars}\nis Visual Studio Installed?\nIs setuptools version > 34?")
        subprocess.check_call(f'call "{vcvars}"', shell=True)

    cmd = "python" if platform.system() == "Windows" else "python3"
    subprocess.check_call(f'{cmd} "{__file__}" build_ext "{project_name}" "{pyx_path}"', shell=True)
    move_pyd_files(pyx_path)
    cleanup(pyx_path)


if len(sys.argv) > 2:
    _build_ext()

calling import setuptools will monkey patch distutils to force compatibility with Visual Studio. Calling vcvars32.bat manually will setup the virtual environment and prevent other common errors the compiler will throw. For VS 2017 the file is located at

“C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat”

Here is the setup script I use to quickly compile .pyx files to .pyd: (Note: it uses the 3rd party module send2trash

# cython_setup.py
import sys, os, time, platform, subprocess
from setuptools import setup, find_packages
from Cython.Build import cythonize
from traceback import format_exc

# USAGE:
#
#   from cython_setup import run
#   run(pyx_path)

# vcvars = r"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"

# NOTE: to use visual studio 2017 you must have setuptools version 34+
vcvars = r"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars32.bat"


def _build_ext():
    try:
        pyx_path = sys.argv.pop(-1)
        pyx_path = os.path.abspath(pyx_path)
        if not os.path.exists(pyx_path):
            raise FileNotFoundError(f"{pyx_path} does not exist")
        project_name = sys.argv.pop(-1)
        os.chdir(os.path.abspath(os.path.dirname(pyx_path)))

        print("cwd: %s" % os.getcwd())
        print(os.path.abspath("build"))
        setup(
            name=project_name,
            # cmdclass = {'build_ext': build_ext},
            packages=find_packages(),
            # ext_modules=cythonize(extensions)
            ext_modules=cythonize(pyx_path,
                                  compiler_directives={'language_level': 3, 'infer_types': True, 'binding': False},
                                  annotate=True),
            # include_dirs = [numpy.get_include()]
            build_dir=os.path.abspath("build")
        )
    except:
        input(format_exc())


def retry(func):
    def wrapper(*args, **kw):
        tries = 0
        while True:
            try:
                return func(*args, **kw)
            except Exception:
                tries += 1
                if tries > 4:
                    raise
                time.sleep(0.4)

    return wrapper


@retry
def cleanup(pyx_path):
    from send2trash import send2trash
    c_file = os.path.splitext(pyx_path)[0] + ".c"
    if os.path.exists(c_file):
        os.remove(c_file)

    if os.path.exists("build"):
        send2trash("build")


def move_pyd_files(pyx_path):
    pyx_dir = os.path.dirname(pyx_path)
    build_dir = os.path.join(pyx_dir, "build")
    if not os.path.exists(build_dir):
        raise RuntimeError(f"build_dir {build_dir} did not exist....")
    found_pyd = False
    for top, dirs, nondirs in os.walk(build_dir):
        for name in nondirs:
            if name.lower().endswith(".pyd") or name.lower().endswith(".so"):
                found_pyd = True
                old_path = os.path.join(top, name)
                new_path = os.path.join(pyx_dir, name)
                if os.path.exists(new_path):
                    print(f"removing {new_path}")
                    os.remove(new_path)
                print(f"file created at {new_path}")
                os.rename(old_path, new_path)
    if not found_pyd:
        raise RuntimeError("Never found .pyd file to move")

def run(pyx_path):
    """
    :param pyx_path:
    :type pyx_path:
    :return: this function creates the batch file, which in turn calls this module, which calls cythonize, once done
    the batch script deletes itself... I'm sure theres a less convoluted way of doing this, but it works
    :rtype:
    """
    try:
        project_name = os.path.splitext(os.path.basename(pyx_path))[0]
        run_script(project_name, os.path.abspath(pyx_path))
    except:
        input(format_exc())


def run_script(project_name, pyx_path):
    dirname = os.path.dirname(pyx_path)
    # ------------------------------
    os.chdir(dirname)
    if os.path.exists(vcvars):
        #  raise RuntimeError(
        # f"Could not find vcvars32.bat at {vcvars}\nis Visual Studio Installed?\nIs setuptools version > 34?")
        subprocess.check_call(f'call "{vcvars}"', shell=True)

    cmd = "python" if platform.system() == "Windows" else "python3"
    subprocess.check_call(f'{cmd} "{__file__}" build_ext "{project_name}" "{pyx_path}"', shell=True)
    move_pyd_files(pyx_path)
    cleanup(pyx_path)


if len(sys.argv) > 2:
    _build_ext()

回答 25

使用此链接下载和安装Visual C ++ 2015生成工具。它会自动下载visualcppbuildtools_full.exe并安装Visual C ++ 14.0,而无需实际安装Visual Studio。安装完成后,重试pip安装,您将不会再次收到错误。

我已经在以下平台和版本上对其进行了测试:

Python 3.6 on Windows 7 64-bit
Python 3.7 on Windows Server 2016 (64-bit system)
Python 3.8 on Windows 10 64-bit

Use this link to download and install Visual C++ 2015 Build Tools. It will automatically download visualcppbuildtools_full.exe and install Visual C++ 14.0 without actually installing Visual Studio. After the installation completes, retry pip install and you won’t get the error again.

I have tested it on following platform and versions:

Python 3.6 on Windows 7 64-bit
Python 3.7 on Windows Server 2016 (64-bit system)
Python 3.8 on Windows 10 64-bit

回答 26

如果要在安装Visual Studio 的Windows机器上安装pyodbc,另一个选择是使用二进制发行版手动安装pyodbc。

如果您在使用的计算机上没有管理员特权并尝试设置virtualenv,则此功能特别有用

脚步:

  1. 此处下载最新的Windows安装程序(pyodbc-XXXwin-Y-py2.7.exe)
  2. 使用7-Zip(或WinRAR或其他工具)打开安装程序可执行文件
  3. 提取pyodbc.pyd和pyodbc-XXX-py2.7.egg-info并将它们放在 [python installation directory or virtualenv]\Lib\site-packages
  4. 没有步骤4 :)

If you’re looking to install pyodbc on a Windows box that doesn’t have Visual Studio installed another option is to manually install pyodbc using the binary distribution.

This is particularly useful if you do not have administrator privileges on the machine you’re working with and are trying to set up a virtualenv.

Steps:

  1. Download the latest Windows installer from here (pyodbc-X.X.X.win-Y-py2.7.exe)
  2. Open the installer executable using 7-Zip (or WinRAR or whatever)
  3. Extract pyodbc.pyd and pyodbc-X.X.X-py2.7.egg-info and place them in [python installation directory or virtualenv]\Lib\site-packages
  4. There is no step 4 :)

回答 27

使用Python 3.4,依赖关系依赖于Visual Studio2010。安装Visual C ++ 2010 Express对我来说解决了这个问题。

欺骗我使用我碰巧无法使用的VS 2008或2013安装。

With Python 3.4, the dependency is on Visual Studio 2010. Installing Visual C++ 2010 Express fixed the problem for me.

Tricking it into using the VS 2008 or 2013 installs that I happened to have didn’t work.


回答 28

您可以使用easy_install代替pip,它对我有用。

You can use easy_install instead of pip it works for me.


回答 29

@monkey给出的答案是正确的答案之一,但不完整。

如果您想使用MinGW,则应该选择C,C ++以及在MinGW安装过程中建议的其他开发工具,以获取“ make.exe”。

您还必须在环境中将路径设置为make.exe。

要完成他的回答,请按以下步骤操作:

  1. 将mingw32的bin目录添加到您的环境变量中
  2. 附加 C:\Programs\MinGW\bin;C:\Programs\MinGW\msys\1.0\bin;到PATH
  3. 编辑distutils.cfg位于以下位置的文件(如果不存在则创建)C:\Python26\Lib\distutils\distutils.cfg

    [build]
    compiler=mingw32

通过打开新的cmd.exe确保设置了环境变量。

The answer given by @monkey is one of the correct ones, but it is incomplete.

In case you’d like to use MinGW, you should select the C, C++ and also other development tools suggested during the MinGW installation process to also get “make.exe.”

You must also have the path set to make.exe in the env.

To complete his answer, here are the steps:

  1. Add mingw32’s bin directory to your environment variables
  2. Append C:\Programs\MinGW\bin;C:\Programs\MinGW\msys\1.0\bin; to the PATH
  3. Edit (create if it doesn’t exist) the distutils.cfg file located at C:\Python26\Lib\distutils\distutils.cfg to be:

    [build]
    compiler=mingw32
    

Make sure the environment variables is set by opening a new cmd.exe.


pip安装mysql-python失败,并显示EnvironmentError:找不到mysql_config

问题:pip安装mysql-python失败,并显示EnvironmentError:找不到mysql_config

这是我得到的错误

(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python
Downloading/unpacking mysql-python
  Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
  Running setup.py egg_info for package mysql-python
    sh: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 24, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    Complete output from command python setup.py egg_info:
    sh: mysql_config: not found

Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>

    metadata, options = get_config()

  File "setup_posix.py", line 43, in get_config

    libs = mysql_config("libs_r")

  File "setup_posix.py", line 24, in mysql_config

    raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log
(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python
Downloading/unpacking mysql-python
  Running setup.py egg_info for package mysql-python
    sh: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 24, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    Complete output from command python setup.py egg_info:
    sh: mysql_config: not found

Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>

    metadata, options = get_config()

  File "setup_posix.py", line 43, in get_config

    libs = mysql_config("libs_r")

  File "setup_posix.py", line 24, in mysql_config

    raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log

我该怎么解决?

This is the error I get

(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python
Downloading/unpacking mysql-python
  Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
  Running setup.py egg_info for package mysql-python
    sh: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 24, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    Complete output from command python setup.py egg_info:
    sh: mysql_config: not found

Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>

    metadata, options = get_config()

  File "setup_posix.py", line 43, in get_config

    libs = mysql_config("libs_r")

  File "setup_posix.py", line 24, in mysql_config

    raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log
(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python
Downloading/unpacking mysql-python
  Running setup.py egg_info for package mysql-python
    sh: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 24, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    Complete output from command python setup.py egg_info:
    sh: mysql_config: not found

Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>

    metadata, options = get_config()

  File "setup_posix.py", line 43, in get_config

    libs = mysql_config("libs_r")

  File "setup_posix.py", line 24, in mysql_config

    raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log

What can I do to resolve this?


回答 0

看来您的系统上缺少mysql_config或安装程序找不到它。确保确实安装了mysql_config。

例如,在Debian / Ubuntu上,您必须安装软件包:

sudo apt-get install libmysqlclient-dev

也许mysql_config不在您的路径中,当您自己编译mysql套件时就是这种情况。

更新:对于最新版本的debian / ubuntu(截至2018年),它是

sudo apt install default-libmysqlclient-dev

It seems mysql_config is missing on your system or the installer could not find it. Be sure mysql_config is really installed.

For example on Debian/Ubuntu you must install the package:

sudo apt-get install libmysqlclient-dev

Maybe the mysql_config is not in your path, it will be the case when you compile by yourself the mysql suite.

Update: For recent versions of debian/ubuntu (as of 2018) it is

sudo apt install default-libmysqlclient-dev

回答 1

在Mac OS中,我只是在终端中运行此程序来修复:

export PATH=$PATH:/usr/local/mysql/bin

这是我找到的最快的修复程序-将其添加到路径中,但是/etc/paths如果您打算在其他环境中安装MySQL-python,最好永久添加(即将其添加到)。

(在OSX Mountain Lion中测试)

In Mac OS, I simply ran this in terminal to fix:

export PATH=$PATH:/usr/local/mysql/bin

This is the quickest fix I found – it adds it to the path, but I think you’re better off adding it permanently (ie add it to /etc/paths) if you plan to install MySQL-python in another environment.

(tested in OSX Mountain Lion)


回答 2

apt-get install libmysqlclient-dev python-dev

似乎做到了。

apt-get install libmysqlclient-dev python-dev

Seemed to do the trick.


回答 3

上面的问题可能有各种答案,下面是一个汇总的解决方案。

对于Ubuntu:

$ sudo apt update
$ sudo apt install python-dev
$ sudo apt install python-MySQLdb

对于CentOS:

$ yum install python-devel mysql-devel

There maybe various answers for the above issue, below is a aggregated solution.

For Ubuntu:

$ sudo apt update
$ sudo apt install python-dev
$ sudo apt install python-MySQLdb

For CentOS:

$ yum install python-devel mysql-devel

回答 4

如果您使用的是MAC,请全局安装

brew install mysql

然后像这样导出路径

export PATH=$PATH:/usr/local/mysql/bin

比全球或您喜欢的任何方式

pip install MySQL-Python

注意:全局适用于python3,因为Mac可以同时拥有python2和3

pip3 install MySQL-Python

If you are on MAC Install this globally

brew install mysql

then export path like this

export PATH=$PATH:/usr/local/mysql/bin

Than globally or in your venv whatever you like

pip install MySQL-Python

Note: globally for python3 as Mac can have both python2 & 3

pip3 install MySQL-Python

回答 5

您可以使用MySQL Connector / Python

通过PyPip安装

pip install mysql-connector-python

可以在MySQL Connector / Python 1.0.5 beta公告博客上找到更多信息。

在Launchpad上,有一个很好的示例,说明如何使用该库添加,编辑或删除数据

You can use the MySQL Connector/Python

Installation via PyPip

pip install mysql-connector-python

Further information can be found on the MySQL Connector/Python 1.0.5 beta announcement blog.

On Launchpad there’s a good example of how to add-, edit- or remove data with the library.


回答 6

对于centos用户:

yum install -y mysql-devel python-devel python-setuptools

然后

pip install MySQL-python


如果此解决方案不起作用,请打印gcc编译错误,例如:
_mysql.c:29:20: error: Python.h: No such file or directory

您需要指定的路径Python.h,如下所示:
pip install --global-option=build_ext --global-option="-I/usr/include/python2.6" MySQL-python

For centos users:

yum install -y mysql-devel python-devel python-setuptools

then

pip install MySQL-python


If this solution doesn’t work, and print gcc compile error like:
_mysql.c:29:20: error: Python.h: No such file or directory

You need to specify the path of Python.h, like this:
pip install --global-option=build_ext --global-option="-I/usr/include/python2.6" MySQL-python


回答 7

我试图mysql-python在Amazon EC2 Linux实例上安装,但我必须安装这些:

yum install mysql mysql-devel mysql-common mysql-libs gcc

但是后来我得到了这个错误:

_mysql.c:29:20: fatal error: Python.h: No such file or directory

所以我安装了:

yum install python-devel

那就成功了。

I was trying to install mysql-python on an Amazon EC2 Linux instance and I had to install these :

yum install mysql mysql-devel mysql-common mysql-libs gcc

But then I got this error :

_mysql.c:29:20: fatal error: Python.h: No such file or directory

So I installed :

yum install python-devel

And that did the trick.


回答 8

对于任何使用MariaDB而不是MySQL的用户,解决方案是安装libmariadbclient-dev软件包并创建指向具有正确名称的配置文件的符号链接。

例如,这对我有用:

ln -s /usr/bin/mariadb_config /usr/bin/mysql_config

For anyone that is using MariaDB instead of MySQL, the solution is to install the libmariadbclient-dev package and create a symbolic link to the config file with the correct name.

For example this worked for me:

ln -s /usr/bin/mariadb_config /usr/bin/mysql_config

回答 9

尝试 sudo apt-get build-dep python-mysqldb

Try sudo apt-get build-dep python-mysqldb


回答 10

OSX小牛

由于osx mavericks和xcode开发工具中的更改,您可能会在安装时得到错误

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

因此使用:

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install mysql-python

OSX Mavericks

Due to changes within osx mavericks & xcode development tools you may get the error on installation

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

therefore use :

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install mysql-python

回答 11

对于Linux

这对我有用

yum install python-devel mysql-devel

For Linux

this works for me

yum install python-devel mysql-devel

回答 12

对于mariadb,请安装lib mariadb client-dev而不是libmysqlclient-dev

sudo apt-get install libmariadbclient-dev

for mariadb install libmariadbclient-dev instead of libmysqlclient-dev

sudo apt-get install libmariadbclient-dev

回答 13

您应该安装第mysql一个:

yum install python-devel mysql-community-devel -y

然后您可以安装mysqlclient

pip install  mysqlclient

You should install the mysql first:

yum install python-devel mysql-community-devel -y

Then you can install mysqlclient:

pip install  mysqlclient

回答 14

有时,错误取决于实际原因。我们曾经遇到过通过python-mysqldb debian软件包安装mysql-python的情况。

一个不知道这一点的开发人员,无意中跑了出来,但pip uninstall mysql-python由于pip install mysql-python给出上述错误而无法恢复。

pip uninstall mysql-python已经破坏了debian软件包的内容,当然pip install mysql-python失败了,因为debian软件包不需要任何dev文件。

在这种情况下,正确的解决方案是apt-get install --reinstall python-mysqldb将mysql-python恢复到其原始状态。

sometimes the error depends on the actual cause. we had a case where mysql-python was installed through the python-mysqldb debian package.

a developer who didn’t know this, accidentally ran pip uninstall mysql-python and then failed to recover with pip install mysql-python giving the above error.

pip uninstall mysql-python had destroyed the debian package contents, and of course pip install mysql-python failed because the debian package didn’t need any dev files.

the correct solution in that case was apt-get install --reinstall python-mysqldb which restored mysql-python to its original state.


回答 15

我在Terraform:light容器中遇到了同样的问题。它基于高山。

在那里,您必须使用以下命令安装mariadb-dev:

apk add mariadb-dev

但是,这还不够,因为还遗漏了所有其他依赖项:

apk add python2 py2-pip gcc python2-dev musl-dev

I had the same problem in the Terraform:light container. It is based on Alpine.

There you have to install mariadb-dev with:

apk add mariadb-dev

But that one is not enough because also all the other dependencies are missed:

apk add python2 py2-pip gcc python2-dev musl-dev

回答 16

要遵循的顺序。

pip install mysqlclient
sudo apt-get install python3-dev libmysqlclient-dev
pip install configparser 
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py 

然后尝试再次安装MYSQL-python。对我有用

Sequence to be followed.

pip install mysqlclient
sudo apt-get install python3-dev libmysqlclient-dev
pip install configparser 
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py 

Then try to install the MYSQL-python again. That Worked for me


回答 17

尝试在OS X Server 10.6.8上安装时遇到了类似的问题。这就是我要做的。使用:

MySQL-python 1.2.4b4(源)MySQL-5.6.19(二进制安装程序)Python 2.7(二进制安装程序)注意:在virtualenv中安装…

解压缩源代码,打开’distribute_setup.py’并编辑DEFAULT_VERSION以使用最新版本的分发工具,如下所示:

DEFAULT_VERSION = "0.6.49"

救。打开“ site.cfg”文件,取消注释mysql_config的路径,使其看起来像(参考您自己的mysql_config路径):

# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = /usr/local/mysql/bin/mysql_config

现在,清理,构建和制作不会因找不到“ mysql_config”错误而失败。希望这可以帮助其他尝试利用其旧xserve的人:-)

Had a similar issue trying to install on OS X Server 10.6.8. Here’s what I had to do. Using:

MySQL-python 1.2.4b4 (source) MySQL-5.6.19 (binary installer) Python 2.7 (binary installer) NOTE: Installing in virtualenv…

Unzip source, open ‘distribute_setup.py’ and edit DEFAULT_VERSION to use the latest version of distribute tools, like so:

DEFAULT_VERSION = "0.6.49"

Save. Open ‘site.cfg’ file and uncomment the path to mysql_config so it looks something like (reference your own path to mysql_config):

# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = /usr/local/mysql/bin/mysql_config

Now clean, build and make will not fail with the ‘mysql_config’ not found error. Hope this helps someone else trying to make use of their old xserves :-)


回答 18

您的sudo路径不知道您的本地路径…进入超级用户模式,添加路径,然后从那里安装它。

sudo su
export PATH=$PATH:/usr/local/mysql/bin/
pip install mysql-python
exit

您就可以在OSX上运行了。现在,您有了一个更新的全局python。

Your sudo path does not know about your local path… go into superuser mode, add the path, and install it from there.

sudo su
export PATH=$PATH:/usr/local/mysql/bin/
pip install mysql-python
exit

And you’re up and running on OSX. Now you have an updated global python.


回答 19

如果在虚拟环境中安装MySQL-python,则应检查pip版本,如果该版本早于9.0.1,请进行更新

pip install --upgrade pip

if you install MySQL-python in your virtual env, you should check the pip version, if the version is older than 9.0.1, please update it

pip install --upgrade pip

回答 20

在MacOS Mojave上,mysql_config位于/ usr / local / bin /而不是如上所述的/ usr / local / mysql / bin,因此无需在路径中添加任何内容。

on MacOS Mojave, mysql_config is found at /usr/local/bin/ rather than /usr/local/mysql/bin as pointed above, so no need to add anything to path.


找不到pg_config可执行文件

问题:找不到pg_config可执行文件

我在安装psycopg2时遇到问题。尝试执行以下操作时出现以下错误pip install psycopg2

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 in /tmp/pip-build/psycopg2

但是问题出pg_config在我身上PATH; 它运行没有任何问题:

$ which pg_config
/usr/pgsql-9.1/bin/pg_config

我尝试将pg_config路径添加到setup.cfg文件中,并使用从其网站(http://initd.org/psycopg/)下载的源文件进行构建,然后收到以下错误消息!

Error: Unable to find 'pg_config' file in '/usr/pgsql-9.1/bin/'

但是实际上是那里!!!

这些错误使我感到困惑。有人可以帮忙吗?

顺便说一下,我sudo所有的命令。我也在使用RHEL 5.5。

I am having trouble installing psycopg2. I get the following error when I try to pip install psycopg2:

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 in /tmp/pip-build/psycopg2

But the problem is pg_config is actually in my PATH; it runs without any problem:

$ which pg_config
/usr/pgsql-9.1/bin/pg_config

I tried adding the pg_config path to the setup.cfg file and building it using the source files I downloaded from their website (http://initd.org/psycopg/) and I get the following error message!

Error: Unable to find 'pg_config' file in '/usr/pgsql-9.1/bin/'

But it is actually THERE!!!

I am baffled by these errors. Can anyone help please?

By the way, I sudo all the commands. Also I am on RHEL 5.5.


回答 0

pg_config位于postgresql-devellibpq-devlibpq-develCentos / Cygwin / Babun的Debian / Ubuntu中。)

pg_config is in postgresql-devel (libpq-dev in Debian/Ubuntu, libpq-devel on Centos/Cygwin/Babun.)


回答 1

在Mac OS X上,我使用自制软件包管理器解决了该问题

brew install postgresql

On Mac OS X, I solved it using the homebrew package manager

brew install postgresql

回答 2

你安装好了python-dev吗?如果已经拥有,请尝试安装libpq-dev

sudo apt-get install libpq-dev python-dev

从文章:如何在virtualenv下安装psycopg2

Have you installed python-dev? If you already have, try also installing libpq-dev

sudo apt-get install libpq-dev python-dev

From the article: How to install psycopg2 under virtualenv


回答 3

同样在OSX上。从http://postgresapp.com/安装了Postgress.app,但存在相同的问题。

pg_config在该应用程序的内容中找到了目录,并将目录添加到$PATH

到了/Applications/Postgres.app/Contents/Versions/latest/bin。所以这个工作:export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"

Also on OSX. Installed Postgress.app from http://postgresapp.com/ but had the same issue.

I found pg_config in that app’s contents and added the dir to $PATH.

It was at /Applications/Postgres.app/Contents/Versions/latest/bin. So this worked: export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH".


回答 4

在高山上,包含的库pg_configpostgresql-dev。要安装,请运行:

apk add postgresql-dev

On alpine, the library containing pg_config is postgresql-dev. To install, run:

apk add postgresql-dev

回答 5

这是在CentOS上首次安装对我有用的东西:

sudo yum install postgresql postgresql-devel python-devel

在Ubuntu上,只需使用等效的apt-get软件包。

sudo apt-get install postgresql postgresql-dev python-dev

现在在pip安装中包含postgresql二进制目录的路径,这对于基于Debain或RHEL的Linux应该都适用:

sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2

确保包括正确的路径。就这样 :)

This is what worked for me on CentOS, first install:

sudo yum install postgresql postgresql-devel python-devel

On Ubuntu just use the equivilent apt-get packages.

sudo apt-get install postgresql postgresql-dev python-dev

And now include the path to your postgresql binary dir with you pip install, this should work for either Debain or RHEL based Linux:

sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2

Make sure to include the correct path. Thats all :)


回答 6

apt-get build-dep python-psycopg2
apt-get build-dep python-psycopg2

回答 7

您应该添加在Ubuntu上的Postgres中使用的python要求。跑:

sudo apt-get install libpq-dev python-dev

You should add python requirements used in Postgres on Ubuntu. Run:

sudo apt-get install libpq-dev python-dev

回答 8

综上所述,我也面临着完全相同的问题。在阅读了很多stackoverflow帖子和在线博客之后,对我有用的最终解决方案是:

1)在安装psycopg2之前,应先安装PostgreSQL(开发版或任何稳定版本)。

2)在安装psycopg2之前,必须显式设置pg_config文件(该文件通常位于PostgreSQL安装文件夹的bin文件夹中)。就我而言,PostgreSQL的安装路径为:

/opt/local/lib/postgresql91/

因此,为了显式设置pg_config文件的PATH,我在终端中输入了以下命令:

PATH=$PATH:/opt/local/lib/postgresql91/bin/

此命令可确保当您尝试通过pip安装psycopg2时,它将自动找到pg_config的路径。

我还在我的博客上发布了有关trace及其解决方案的完整错误,您可能希望参考。它适用于Mac OS X,但是pg_config PATH问题是通用的,也适用于Linux。

Just to sum up, I also faced exactly same problem. After reading a lot of stackoverflow posts and online blogs, the final solution which worked for me is this:

1) PostgreSQL(development or any stable version) should be installed before installing psycopg2.

2) The pg_config file (this file normally resides in the bin folder of the PostgreSQL installation folder) PATH had to be explicitly setup before installing psycopg2. In my case, the installation PATH for PostgreSQL is:

/opt/local/lib/postgresql91/

so in order to explicitly set the PATH of pg_config file, I entered following command in my terminal:

PATH=$PATH:/opt/local/lib/postgresql91/bin/

This command ensures that when you try to pip install psycopg2, it would find the PATH to pg_config automatically this time.

I have also posted a full error with trace and its solution on my blog which you may want to refer. Its for Mac OS X but the pg_config PATH problem is generic and applicable to Linux also.


回答 9

sudo apt-get install libpq-dev 在Ubuntu 15.4上为我工作

sudo apt-get install libpq-dev works for me on Ubuntu 15.4


回答 10

在Linux上Mint sudo apt-get install libpq-dev为我工作。

On Linux Mint sudo apt-get install libpq-dev worked for me.


回答 11

您可以使用pip或在任何平台上安装预编译的二进制文件conda

python -m pip install psycopg2-binary

要么

conda install psycopg2

请注意,psycopg2-binary pypi页面建议在生产中从源代码构建:

二进制软件包是开发和测试的实际选择,但在生产中,建议使用从源构建的软件包

要使用从源构建的软件包,请使用python -m pip install psycopg2。该过程将需要几个依赖项(文档)(重点是我的):

  • 交流编译器
  • Python的头文件。它们通常安装在python-dev之类的软件包中。诸如错误消息:Python.h:没有这样的文件或目录表示缺少Python标头。
  • libpq的头文件。它们通常安装在libpq-dev之类的软件包中。如果出现错误:libpq-fe.h:没有此类文件或目录,您将丢失它们。
  • pg_config程序:它通常是由安装的libpq-dev的包,但有时它是不是在路径目录。将它放在PATH中可以大大简化安装,因此请尝试运行pg_config –version:如果返回错误或意外的版本号,请找到包含正确libpq版本附带的pg_config的目录(通常是/ usr / lib / postgresql / XY / bin /)并将其添加到PATH: $ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH 您仅需要pg_config来编译psycopg2,而无需常规使用。

You can install pre-compiled binaries on any platform with pip or conda:

python -m pip install psycopg2-binary

or

conda install psycopg2

Please be advised that the psycopg2-binary pypi page recommends building from source in production:

The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources

To use the package built from sources, use python -m pip install psycopg2. That process will require several dependencies (documentation) (emphasis mine):

  • A C compiler.
  • The Python header files. They are usually installed in a package such as python-dev. A message such as error: Python.h: No such file or directory is an indication that the Python headers are missing.
  • The libpq header files. They are usually installed in a package such as libpq-dev. If you get an error: libpq-fe.h: No such file or directory you are missing them.
  • The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATH directory. Having it in the PATH greatly streamlines the installation, so try running pg_config –version: if it returns an error or an unexpected version number then locate the directory containing the pg_config shipped with the right libpq version (usually /usr/lib/postgresql/X.Y/bin/) and add it to the PATH: $ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH You only need pg_config to compile psycopg2, not for its regular usage.

回答 12

UPDATE /etc/yum.repos.d/CentOS-Base.repo、[base]和[updates]部分
ADD exclude = postgresql *

curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpmr  
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm

yum install postgresql  
yum install postgresql-devel

PATH=$PATH:/usr/pgsql-9.1/bin/

pip install psycopg2

UPDATE /etc/yum.repos.d/CentOS-Base.repo, [base] and [updates] sections
ADD exclude=postgresql*

curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpmr  
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm

yum install postgresql  
yum install postgresql-devel

PATH=$PATH:/usr/pgsql-9.1/bin/

pip install psycopg2

回答 13

对于运行OS X的用户,此解决方案对我有用:

1)安装Postgres.app:

http://www.postgresql.org/download/macosx/

2)然后打开终端并运行以下命令,将其显示为{{version}}的位置替换为Postgres版本号:

导出PATH = $ PATH:/Applications/Postgres.app/Contents/Versions / {{version}} / bin

例如

导出PATH = $ PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin

For those running OS X, this solution worked for me:

1) Install Postgres.app:

http://www.postgresql.org/download/macosx/

2) Then open the Terminal and run this command, replacing where it says {{version}} with the Postgres version number:

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/{{version}}/bin

e.g.

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin


回答 14

尝试将其添加到PATH:

PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2

Try to add it to PATH:

PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2

回答 15

Ali的解决方案对我有用,但是我在查找bin文件夹位置时遇到了麻烦。在Mac OS X上查找路径的快速方法是打开psql(顶部菜单栏中有一个快速链接)。这将打开一个单独的终端窗口,在第二行,您的Postgres安装路径将如下所示:

My-MacBook-Pro:~ Me$ /Applications/Postgres93.app/Contents/MacOS/bin/psql ; exit;

您的pg_config文件在该bin文件夹中。因此,在安装psycopg2之前,请设置pg_config文件的路径:

PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin/

或较新版本:

PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin

然后安装psycopg2。

Ali’s solution worked for me but I was having trouble finding the bin folder location. A quick way to find the path on Mac OS X is to open psql (there’s a quick link in the top menu bar). This will open a separate terminal window and on the second line the path of your Postgres installation will appear like so:

My-MacBook-Pro:~ Me$ /Applications/Postgres93.app/Contents/MacOS/bin/psql ; exit;

Your pg_config file is in that bin folder. Therefore, before installing psycopg2 set the path of the pg_config file:

PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin/

or for newer version:

PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin

Then install psycopg2.


回答 16

在安装psycopg2之前,您需要升级您的pip。使用此命令

pip install --upgrade pip

You need to upgrade your pip before installing psycopg2. Use this command

pip install --upgrade pip

回答 17

我将把这个留给下一个不幸的灵魂,尽管所有提供的解决方案都无法解决这个问题。只需使用sudo pip3 install psycopg2-binary

I’m going to leave this here for the next unfortunate soul who can’t get around this problem despite all the provided solutions. Simply use sudo pip3 install psycopg2-binary


回答 18

刚刚通过以下方法解决了Cent OS 7中的问题:

export PATH=$PATH:/usr/pgsql-9.5/bin

确保您的PostgreSql版本与上面的正确版本匹配。

Just solved the problem in Cent OS 7 by:

export PATH=$PATH:/usr/pgsql-9.5/bin

make sure your PostgreSql version matches the right version above.


回答 19

在Mac OS X上,如果您使用的是Postgres App(http://postgresapp.com/):

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin

无需在此命令中指定Postgres的版本。它将始终指向最新。

并做

pip install psycopg2

PS:如果更改未反映出您可能需要重新启动终端/命令提示符

资源

On Mac OS X and If you are using Postgres App (http://postgresapp.com/):

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin

No need to specify version of Postgres in this command. It will be always pointed to latest.

and do

pip install psycopg2

P.S: If Changes doesn’t reflect you may need to restart the Terminal/Command prompt

Source


回答 20

安装python-psycopg2在Arch Linux上为我解决了这个问题:

pacman -S python-psycopg2

Installing python-psycopg2 solved it for me on Arch Linux:

pacman -S python-psycopg2

回答 21

在Windows上,您可能需要安装PsycopgWindows端口,该端口psycopg的文档中建议使用。

On Windows, You may want to install the Windows port of Psycopg, which is recommended in psycopg’s documentation.


回答 22

在MacOS上,最简单的解决方案是将正确的二进制文件符号链接到Postgres软件包下。

sudo ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config /usr/local/bin/pg_config

这是相当无害的,并且如果需要,所有应用程序都可以在系统范围内使用它。

On MacOS, the simplest solution will be to symlink the correct binary, that is under the Postgres package.

sudo ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config /usr/local/bin/pg_config

This is fairly harmless, and all the applications will be able to use it system wide, if required.


回答 23

sudo yum安装postgresql-devel(centos6X)

点安装psycopg2 == 2.5.2

sudo yum install postgresql-devel (centos6X)

pip install psycopg2==2.5.2


回答 24

在这里,为了确保OS X的完整性:如果从MacPorts安装PostgreSQL,则pg_config将位于 /opt/local/lib/postgresql94/bin/pg_config

安装MacPorts时,它已经添加了 /opt/local/bin到PATH中。

因此,这将解决问题: $ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config

现在pip install psycopg2将可以pg_config毫无问题地运行。

Here, for OS X completeness: if you install PostgreSQL from MacPorts, pg_config will be in /opt/local/lib/postgresql94/bin/pg_config.

When you installed MacPorts, it already added /opt/local/bin to your PATH.

So, this will fix the problem: $ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config

Now pip install psycopg2 will be able to run pg_config without issues.


回答 25

对于使用zshshell的macOS Catalina 上也安装了postgres应用程序的用户

打开~/.zshrc文件,并添加以下行:

export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"

然后关闭所有终端,重新打开它们,您将解决问题。

如果您不想关闭终端,只需输入要继续使用的终端即可source ~/.zshrc

To those on macOS Catalina using the zsh shell who have also installed the postgres app:

Open your ~/.zshrc file, and add the following line:

export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"

Then close all your terminals, reopen them, and you’ll have resolved your problem.

If you don’t want to close your terminals, simply enter source ~/.zshrc in whatever terminal you’d like to keep working on.


回答 26

对于mac用户,扩展您的path变量以包括PostgreSQL这样的export PATH=$PATH:/Library/PostgreSQL/12/bin

For mac users, extend your path variable to include PostgreSQL like this export PATH=$PATH:/Library/PostgreSQL/12/bin.


回答 27

这是我设法安装psycopg2的方法

$ wget http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.3.tar.gz
$ tar -xzf psycopg2-2.5.3.tar.gz
$ cd psycopg2-2.5.3
$ pip install .

This is how I managed to install psycopg2

$ wget http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.3.tar.gz
$ tar -xzf psycopg2-2.5.3.tar.gz
$ cd psycopg2-2.5.3
$ pip install .

回答 28

我敢肯定,您会遇到与我相同的“问题”,因此,我将为您提供极为简单的解决方案…

在您的情况下,您需要添加到$ PATH(或作为命令参数)的实际路径是:

/usr/pgsql-9.1/bin/pg_config

/usr/pgsql-9.1/bin

例如,如果您随后运行python setup.py脚本,则可以这样运行它:

python setup.py build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build

可能为时已晚,但仍然是最简单的解决方案。

之后编辑:

在进一步测试下,我发现如果您最初以以下形式将路径添加到pg_config

/usr/pgsql-9.1/bin

(在../bin之后没有/ pg_config)并运行pip install命令,它将起作用。

但是,如果您随后决定按照说明运行python setup.py,则必须在….. / bin之后使用/ pg_config指定路径,即

python setup.py build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build

I am pretty sure you’ve experienced the same “problem” i did, therefore I’ll offer you the extremely easy solution…

In your case, the actual path that you need to add to $PATH (or as a command param) is:

/usr/pgsql-9.1/bin/pg_config

not

/usr/pgsql-9.1/bin

E.g. if you run the python setup.py script afterwards, you would run it like this:

python setup.py build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build

Probably too late, but still the easiest solution.

LATER EDIT:

Under further test I found out that if you initially add the path to pg_config in the form

/usr/pgsql-9.1/bin

(without /pg_config after …../bin) and run the pip install command it will work.

However, if you then decide to follow the indication to run python setup.py, you will have to specify the path with /pg_config after …../bin, i.e.

python setup.py build_ext --pg-config /usr/pgsql-9.1/bin/pg_config build

回答 29

对于CentOS / RedHat,请确保这/etc/alternatives/pgsql-pg_config是一个不间断的符号链接

for CentOS/RedHat make sure that /etc/alternatives/pgsql-pg_config is a non-broken symlink


pip和conda有什么区别?

问题:pip和conda有什么区别?

我知道pip是python软件包的软件包管理器。但是,我看到IPython网站conda上的安装用于安装IPython。

我可以pip用来安装IPython吗?conda我已经拥有了为什么还要用作另一个python软件包管理器pip

pip和之间有什么区别conda

I know pip is a package manager for python packages. However, I saw the installation on IPython’s website use conda to install IPython.

Can I use pip to install IPython? Why should I use conda as another python package manager when I already have pip?

What is the difference between pip and conda?


回答 0

引用来自Conda博客

参与python世界已经很长时间了,我们都知道pip,easy_install和virtualenv,但是这些工具不能满足我们所有的特定要求。主要问题是它们专注于Python,而忽略了非Python库依赖项,例如HDF5,MKL,LLVM等,它们的源代码中没有setup.py,也没有将文件安装到Python的站点中-packages目录。

因此,Conda是一种包装工具和安装程序,旨在做更多的事情pip。处理Python包之外的库依赖关系以及Python包本身。Conda也像创建虚拟环境一样virtualenv

因此,也许应该将Conda与Buildout进行比较,后者是另一个可以让您处理Python和非Python安装任务的工具。

由于Conda引入了新的包装格式,因此您不能pip与Conda互换使用。 pip无法安装Conda软件包格式。您可以使用并排的两个工具侧(通过安装pipconda install pip),但他们不具备互操作性无论是。

自编写此答案以来,Anaconda 理解Conda和Pip发布了新页面,该页面也与此相呼应:

这凸显了conda和pip之间的关键区别。Pip安装Python软件包,而conda安装软件包,其中可能包含以任何语言编写的软件。例如,在使用pip之前,必须通过系统软件包管理器或下载并运行安装程序来安装Python解释器。另一方面,Conda可以直接安装Python软件包以及Python解释器。

并进一步

有时需要一个软件包,该软件包不是conda软件包,但在PyPI上可用,可以与pip一起安装。在这些情况下,尝试同时使用conda和pip是有意义的。

Quoting from the Conda blog:

Having been involved in the python world for so long, we are all aware of pip, easy_install, and virtualenv, but these tools did not meet all of our specific requirements. The main problem is that they are focused around Python, neglecting non-Python library dependencies, such as HDF5, MKL, LLVM, etc., which do not have a setup.py in their source code and also do not install files into Python’s site-packages directory.

So Conda is a packaging tool and installer that aims to do more than what pip does; handle library dependencies outside of the Python packages as well as the Python packages themselves. Conda also creates a virtual environment, like virtualenv does.

As such, Conda should be compared to Buildout perhaps, another tool that lets you handle both Python and non-Python installation tasks.

Because Conda introduces a new packaging format, you cannot use pip and Conda interchangeably; pip cannot install the Conda package format. You can use the two tools side by side (by installing pip with conda install pip) but they do not interoperate either.

Since writing this answer, Anaconda has published a new page on Understanding Conda and Pip, which echoes this as well:

This highlights a key difference between conda and pip. Pip installs Python packages whereas conda installs packages which may contain software written in any language. For example, before using pip, a Python interpreter must be installed via a system package manager or by downloading and running an installer. Conda on the other hand can install Python packages as well as the Python interpreter directly.

and further on

Occasionally a package is needed which is not available as a conda package but is available on PyPI and can be installed with pip. In these cases, it makes sense to try to use both conda and pip.


回答 1

这是一个简短的摘要:

点子

  • 仅Python软件包。
  • 从源代码编译所有内容。编辑:pip现在会安装二进制车轮(如果可用)。
  • 受核心Python社区的祝福(即Python 3.4+包含自动引导pip的代码)。

康达

  • 不可知的Python。现有软件包的主要焦点是用于Python,的确Conda本身是用Python编写的,但是您也可以拥有用于C库,R软件包或其他任何东西的Conda软件包。
  • 安装二进制文件。有一个名为的工具conda build可以从源代码构建软件包,但conda install它本身可以从已构建的Conda软件包安装东西。
  • 外部。Conda是Anaconda的软件包管理器,它是Continuum Analytics提供的Python发行版,但也可以在Anaconda之外使用。您可以通过pip安装将其与现有的Python安装配合使用(尽管除非您有充分的理由使用现有的安装,否则不建议这样做)。

在两种情况下:

  • 用Python编写
  • 开源(Conda是BSD,pip是MIT)

实际上,Conda的前两个要点是使许多包装优于点子的原因。由于pip是从源代码安装的,因此如果您无法编译源代码,则可能会很麻烦地安装东西(在Windows上尤其如此,但在Linux上,如果软件包中包含一些困难的C或FORTRAN库,甚至可能也是这样。依赖项)。Conda从二进制安装,这意味着某人(例如Continuum)已经完成了编译软件包的艰苦工作,因此安装很容易。

如果您对构建自己的软件包感兴趣,也有一些区别。例如,pip是建立在setuptools之上的,而Conda使用自己的格式,这种格式具有一些优点(例如,静态的,Python不可知的)。

Here is a short rundown:

pip

  • Python packages only.
  • Compiles everything from source. EDIT: pip now installs binary wheels, if they are available.
  • Blessed by the core Python community (i.e., Python 3.4+ includes code that automatically bootstraps pip).

conda

  • Python agnostic. The main focus of existing packages are for Python, and indeed Conda itself is written in Python, but you can also have Conda packages for C libraries, or R packages, or really anything.
  • Installs binaries. There is a tool called conda build that builds packages from source, but conda install itself installs things from already built Conda packages.
  • External. Conda is the package manager of Anaconda, the Python distribution provided by Continuum Analytics, but it can be used outside of Anaconda too. You can use it with an existing Python installation by pip installing it (though this is not recommended unless you have a good reason to use an existing installation).

In both cases:

  • Written in Python
  • Open source (Conda is BSD and pip is MIT)

The first two bullet points of Conda are really what make it advantageous over pip for many packages. Since pip installs from source, it can be painful to install things with it if you are unable to compile the source code (this is especially true on Windows, but it can even be true on Linux if the packages have some difficult C or FORTRAN library dependencies). Conda installs from binary, meaning that someone (e.g., Continuum) has already done the hard work of compiling the package, and so the installation is easy.

There are also some differences if you are interested in building your own packages. For instance, pip is built on top of setuptools, whereas Conda uses its own format, which has some advantages (like being static, and again, Python agnostic).


回答 2

其他答案对这些细节给出了合理的描述,但我想强调一些高级要点。

pip是一个软件包管理器,可简化python软件包的安装,升级和卸载。它还适用于虚拟python环境。

conda是任何软件(安装,升级和卸载)的软件包管理器。它还适用于虚拟系统环境。

conda设计的目标之一是促进用户所需的整个软件堆栈的软件包管理,其中一个或多个python版本可能只是其中的一小部分。这包括低级库(例如线性代数),编译器(例如Windows上的mingw),编辑器,版本控制工具(例如Hg和Git)或其他需要分发和管理的内容

对于版本管理,pip允许您在多个python环境之间切换和管理。

Conda允许您在多个通用环境之间进行切换和管理,在多个通用环境中,其他多个版本的版本号可能会有所不同,例如C库,编译器,测试套件或数据库引擎等。

Conda不是以Windows为中心的,但是在Windows上,当需要安装和管理需要编译的复杂科学软件包时,它是目前可用的高级解决方案。

当我想到尝试通过Windows上的pip编译许多这些软件包或pip install在需要编译时调试失败的会话时浪费了多少时间时,我想哭。

最后,Continuum Analytics还托管(免费)binstar.org(现在称为anaconda.org),以允许常规软件包开发人员创建自己的自定义(内置!)软件堆栈,包用户可以conda install从中使用它们。

The other answers give a fair description of the details, but I want to highlight some high-level points.

pip is a package manager that facilitates installation, upgrade, and uninstallation of python packages. It also works with virtual python environments.

conda is a package manager for any software (installation, upgrade and uninstallation). It also works with virtual system environments.

One of the goals with the design of conda is to facilitate package management for the entire software stack required by users, of which one or more python versions may only be a small part. This includes low-level libraries, such as linear algebra, compilers, such as mingw on Windows, editors, version control tools like Hg and Git, or whatever else requires distribution and management.

For version management, pip allows you to switch between and manage multiple python environments.

Conda allows you to switch between and manage multiple general purpose environments across which multiple other things can vary in version number, like C-libraries, or compilers, or test-suites, or database engines and so on.

Conda is not Windows-centric, but on Windows it is by far the superior solution currently available when complex scientific packages requiring compilation are required to be installed and managed.

I want to weep when I think of how much time I have lost trying to compile many of these packages via pip on Windows, or debug failed pip install sessions when compilation was required.

As a final point, Continuum Analytics also hosts (free) binstar.org (now called anaconda.org) to allow regular package developers to create their own custom (built!) software stacks that their package-users will be able to conda install from.


回答 3

不要再让您感到困惑了,但是您也可以在conda环境中使用pip,这可以验证上面的一般管理员和python特定管理员的评论。

conda install -n testenv pip
source activate testenv
pip <pip command>

您还可以将pip添加到任何环境的默认程序包中,因此每次都会显示pip,因此您不必遵循上述代码段。

Not to confuse you further, but you can also use pip within your conda environment, which validates the general vs. python specific managers comments above.

conda install -n testenv pip
source activate testenv
pip <pip command>

you can also add pip to default packages of any environment so it is present each time so you don’t have to follow the above snippet.


回答 4

引用康达在Continuum网站上发表的关于数据科学的文章:

康达vs点

Python程序员可能很熟悉pip从PyPI下载软件包并管理他们的要求。尽管conda和pip都是程序包管理器,但它们却大不相同:

  • Pip是特定于Python软件包的,而conda是与语言无关的,这意味着我们可以使用conda管理任何语言的软件包。
  • Conda本机创建与语言无关的环境,而pip依靠virtualenv仅管理Python环境尽管建议始终使用conda软件包,但conda也包含pip,因此您不必在这两者之间进行选择。例如,要安装没有conda软件包但可通过pip获得的python软件包,请运行,例如:
conda install pip
pip install gensim

Quote from Conda for Data Science article onto Continuum’s website:

Conda vs pip

Python programmers are probably familiar with pip to download packages from PyPI and manage their requirements. Although, both conda and pip are package managers, they are very different:

  • Pip is specific for Python packages and conda is language-agnostic, which means we can use conda to manage packages from any language Pip compiles from source and conda installs binaries, removing the burden of compilation
  • Conda creates language-agnostic environments natively whereas pip relies on virtualenv to manage only Python environments Though it is recommended to always use conda packages, conda also includes pip, so you don’t have to choose between the two. For example, to install a python package that does not have a conda package, but is available through pip, just run, for example:
conda install pip
pip install gensim

回答 5

引用《Conda:神话与误解》(全面描述):

误解3:Conda和Pip是直接竞争对手

现实:Conda和pip服务于不同的目的,仅直接竞争一小部分任务:即在隔离的环境中安装Python软件包。

皮普,代表P IP nstalls P ackages,是Python的官方认可的包管理器,并且是最常用的在其上安装Python包索引(PyPI中)发布的数据包。pip和PyPI均受Python Packaging Authority(PyPA)管辖和支持。

简而言之,pip是Python软件包的通用管理器。conda是与语言无关的跨平台环境管理器。对于用户而言,最明显的区别可能是:pip在任何环境中安装python软件包;conda在conda环境中安装任何软件包。如果您要做的只是在隔离的环境中安装Python软件包,则conda和pip + virtualenv通常是可互换的,从而在依赖项处理和软件包可用性方面取得了一些差异。隔离环境是指conda-env或virtualenv,您可以在其中安装软件包而无需修改系统Python安装。

即使抛开神话#2,如果我们只关注Python软件包的安装,conda和pip也可以为不同的受众和不同的目的服务。例如,如果要管理现有系统Python安装中的Python软件包,conda不能为您提供帮助:根据设计,它只能在conda环境中安装软件包。例如,如果您想使用许多依赖于外部依赖关系的Python包(NumPy,SciPy和Matplotlib是常见的示例),而以有意义的方式跟踪这些依赖关系时,pip并不能帮助您:通过设计,它仅管理Python软件包。

Conda和pip不是竞争对手,而是针对不同用户群和使用方式的工具。

Quoting from Conda: Myths and Misconceptions (a comprehensive description):

Myth #3: Conda and pip are direct competitors

Reality: Conda and pip serve different purposes, and only directly compete in a small subset of tasks: namely installing Python packages in isolated environments.

Pip, which stands for Pip Installs Packages, is Python’s officially-sanctioned package manager, and is most commonly used to install packages published on the Python Package Index (PyPI). Both pip and PyPI are governed and supported by the Python Packaging Authority (PyPA).

In short, pip is a general-purpose manager for Python packages; conda is a language-agnostic cross-platform environment manager. For the user, the most salient distinction is probably this: pip installs python packages within any environment; conda installs any package within conda environments. If all you are doing is installing Python packages within an isolated environment, conda and pip+virtualenv are mostly interchangeable, modulo some difference in dependency handling and package availability. By isolated environment I mean a conda-env or virtualenv, in which you can install packages without modifying your system Python installation.

Even setting aside Myth #2, if we focus on just installation of Python packages, conda and pip serve different audiences and different purposes. If you want to, say, manage Python packages within an existing system Python installation, conda can’t help you: by design, it can only install packages within conda environments. If you want to, say, work with the many Python packages which rely on external dependencies (NumPy, SciPy, and Matplotlib are common examples), while tracking those dependencies in a meaningful way, pip can’t help you: by design, it manages Python packages and only Python packages.

Conda and pip are not competitors, but rather tools focused on different groups of users and patterns of use.


回答 6

对于WINDOWS用户

最近,“标准”包装工具的状况正在改善:

  • 截至9月,在pypi本身上,有48%的车轮包装。2015年11月11日(高于2015年5月的38%和2014年9月的24%),

  • 现在,最新的python 2.7.9支持开箱即用的wheel格式,

“标准” +“调整”包装工具的状况也在改善:

  • 您可以在http://www.lfd.uci.edu/~gohlke/pythonlibs上找到几乎所有关于转轮格式的科学软件包,

  • mingwpy项目可能有一天为Windows用户带来一个“编译”包,允许在需要时从源代码安装所有内容。

“康达”包装对于所服务的市场而言仍然更好,并强调了“标准” 应该改进的地方。

(同样,在标准车轮系统和conda系统中,或者在扩展方面,依赖规范的多方面努力不是很Python,如果所有这些打包的“核心”技术都可以通过某种PEP收敛,那就太好了)

For WINDOWS users

“standard” packaging tools situation is improving recently:

  • on pypi itself, there are now 48% of wheel packages as of sept. 11th 2015 (up from 38% in may 2015 , 24% in sept. 2014),

  • the wheel format is now supported out-of-the-box per latest python 2.7.9,

“standard”+”tweaks” packaging tools situation is improving also:

  • you can find nearly all scientific packages on wheel format at http://www.lfd.uci.edu/~gohlke/pythonlibs,

  • the mingwpy project may bring one day a ‘compilation’ package to windows users, allowing to install everything from source when needed.

“Conda” packaging remains better for the market it serves, and highlights areas where the “standard” should improve.

(also, the dependency specification multiple-effort, in standard wheel system and in conda system, or buildout, is not very pythonic, it would be nice if all these packaging ‘core’ techniques could converge, via a sort of PEP)


回答 7

pip 是包裹经理。

conda 既是包管理器又是环境管理器。

详情:

在此处输入图片说明

参考文献

pip is a package manager.

conda is both a package manager and an environment manager.

Detail:

enter image description here

References


回答 8

我可以使用pip安装iPython吗?

当然,两者(第一种方法在页面上)

pip install ipython

和(第三种方法,第二种是conda

您可以从GitHub或PyPI手动下载IPython。要安装这些版本之一,请解压缩它并使用终端从顶级源目录运行以下命令:

pip install .

官方推荐的安装方法

当我已经有了pip时,为什么还要使用conda作为另一个python软件包管理器?

这里所说:

如果您需要一个特定的软件包,也许仅用于一个项目,或者需要与其他人共享该项目,那么conda似乎更合适。

康达(YMMV)超过点

  • 使用非Python工具的项目
  • 与同事分享
  • 在版本之间切换
  • 在具有不同库版本的项目之间切换

pip和conda有什么区别?

其他所有人对此都有广泛的回答。

Can I use pip to install iPython?

Sure, both (first approach on page)

pip install ipython

and (third approach, second is conda)

You can manually download IPython from GitHub or PyPI. To install one of these versions, unpack it and run the following from the top-level source directory using the Terminal:

pip install .

are officially recommended ways to install.

Why should I use conda as another python package manager when I already have pip?

As said here:

If you need a specific package, maybe only for one project, or if you need to share the project with someone else, conda seems more appropriate.

Conda surpasses pip in (YMMV)

  • projects that use non-python tools
  • sharing with colleagues
  • switching between versions
  • switching between projects with different library versions

What is the difference between pip and conda?

That is extensively answered by everyone else.


回答 9

pip 仅适用于Python

conda仅适用于Anaconda +其他科学软件包,例如R依赖等。并非每个人都需要Python附带的Anaconda。Anaconda主要适合那些进行机器学习/深度学习等的人。Casual Python开发人员不会在他的笔记本电脑上运行Anaconda。

pip is for Python only

conda is only for Anaconda + other scientific packages like R dependencies etc. NOT everyone needs Anaconda that already comes with Python. Anaconda is mostly for those who do Machine learning/deep learning etc. Casual Python dev won’t run Anaconda on his laptop.


回答 10

我可能已经发现了另一小的区别。我在python环境下/usr而不是在/home任何环境下。为了安装它,我将不得不使用sudo install pip。对我来说,不想要的副作用sudo install pip是比被广泛报道的其他地方略有不同:这样做之后,我还得跑pythonsudo以进口任何的sudo-installed包。我放弃了这一点,最终发现我可以sudo conda将软件包安装到一个环境中/usr,然后在该环境下可以正常导入而不需要sudo获得许可python。我什sudo conda至习惯于修复损坏的东西,pip而不是使用sudo pip uninstall pipor sudo pip --upgrade install pip

I may have found one further difference of a minor nature. I have my python environments under /usr rather than /home or whatever. In order to install to it, I would have to use sudo install pip. For me, the undesired side effect of sudo install pip was slightly different than what are widely reported elsewhere: after doing so, I had to run python with sudo in order to import any of the sudo-installed packages. I gave up on that and eventually found I could use sudo conda to install packages to an environment under /usr which then imported normally without needing sudo permission for python. I even used sudo conda to fix a broken pip rather than using sudo pip uninstall pip or sudo pip --upgrade install pip.


查找pip安装了哪个版本的软件包

问题:查找pip安装了哪个版本的软件包

使用pip,可以确定当前安装了哪个版本的软件包?

我知道,pip install XYZ --upgrade但是我想知道是否有类似的东西pip info XYZ。如果不是,最好的方法就是告诉我当前使用的版本。

Using pip, is it possible to figure out which version of a package is currently installed?

I know about pip install XYZ --upgrade but I am wondering if there is anything like pip info XYZ. If not what would be the best way to tell what version I am currently using.


回答 0

pip 1.3开始,有一个pip show命令。

$ pip show Jinja2
---
Name: Jinja2
Version: 2.7.3
Location: /path/to/virtualenv/lib/python2.7/site-packages
Requires: markupsafe

在旧版本,pip freezegrep应做的工作很好。

$ pip freeze | grep Jinja2
Jinja2==2.7.3

As of pip 1.3, there is a pip show command.

$ pip show Jinja2
---
Name: Jinja2
Version: 2.7.3
Location: /path/to/virtualenv/lib/python2.7/site-packages
Requires: markupsafe

In older versions, pip freeze and grep should do the job nicely.

$ pip freeze | grep Jinja2
Jinja2==2.7.3

回答 1

我刚刚以增强的雨果·塔瓦雷斯(Hugo Tavares)的点子发送了请求请求:

(以specloud为例)

$ pip show specloud

Package: specloud
Version: 0.4.4
Requires:
nose
figleaf
pinocchio

I just sent a pull request in pip with the enhancement Hugo Tavares said:

(specloud as example)

$ pip show specloud

Package: specloud
Version: 0.4.4
Requires:
nose
figleaf
pinocchio

回答 2

Pip 1.3现在也有一个list命令:

$ pip list
argparse (1.2.1)
pip (1.5.1)
setuptools (2.1)
wsgiref (0.1.2)

Pip 1.3 now also has a list command:

$ pip list
argparse (1.2.1)
pip (1.5.1)
setuptools (2.1)
wsgiref (0.1.2)

回答 3

并将–outdated作为额外的参数,您将获得所使用软件包的当前版本和最新版本:

$ pip list --outdated
distribute (Current: 0.6.34 Latest: 0.7.3)
django-bootstrap3 (Current: 1.1.0 Latest: 4.3.0)
Django (Current: 1.5.4 Latest: 1.6.4)
Jinja2 (Current: 2.6 Latest: 2.8)

因此,结合AdamKG的答案:

$ pip list --outdated | grep Jinja2
Jinja2 (Current: 2.6 Latest: 2.8)

也检查pip-toolshttps : //github.com/nvie/pip-tools

and with –outdated as an extra argument, you will get the Current and Latest versions of the packages you are using :

$ pip list --outdated
distribute (Current: 0.6.34 Latest: 0.7.3)
django-bootstrap3 (Current: 1.1.0 Latest: 4.3.0)
Django (Current: 1.5.4 Latest: 1.6.4)
Jinja2 (Current: 2.6 Latest: 2.8)

So combining with AdamKG ‘s answer :

$ pip list --outdated | grep Jinja2
Jinja2 (Current: 2.6 Latest: 2.8)

Check pip-tools too : https://github.com/nvie/pip-tools


回答 4

您还可以安装yolk然后运行yolk -l,这也会提供一些不错的输出。这是我的小virtualenv获得的:

(venv)CWD> /space/vhosts/pyramid.xcode.com/venv/build/unittest 
project@pyramid 43> yolk -l
Chameleon       - 2.8.2        - active 
Jinja2          - 2.6          - active 
Mako            - 0.7.0        - active 
MarkupSafe      - 0.15         - active 
PasteDeploy     - 1.5.0        - active 
Pygments        - 1.5          - active 
Python          - 2.7.3        - active development (/usr/lib/python2.7/lib-dynload)
SQLAlchemy      - 0.7.6        - active 
WebOb           - 1.2b3        - active 
account         - 0.0          - active development (/space/vhosts/pyramid.xcode.com/project/account)
distribute      - 0.6.19       - active 
egenix-mx-base  - 3.2.3        - active 
ipython         - 0.12         - active 
logilab-astng   - 0.23.1       - active 
logilab-common  - 0.57.1       - active 
nose            - 1.1.2        - active 
pbkdf2          - 1.3          - active 
pip             - 1.0.2        - active 
pyScss          - 1.1.3        - active 
pycrypto        - 2.5          - active 
pylint          - 0.25.1       - active 
pyramid-debugtoolbar - 1.0.1        - active 
pyramid-tm      - 0.4          - active 
pyramid         - 1.3          - active 
repoze.lru      - 0.5          - active 
simplejson      - 2.5.0        - active 
transaction     - 1.2.0        - active 
translationstring - 1.1          - active 
venusian        - 1.0a3        - active 
waitress        - 0.8.1        - active 
wsgiref         - 0.1.2        - active development (/usr/lib/python2.7)
yolk            - 0.4.3        - active 
zope.deprecation - 3.5.1        - active 
zope.interface  - 3.8.0        - active 
zope.sqlalchemy - 0.7          - active 

You can also install yolk and then run yolk -l which also gives some nice output. Here is what I get for my little virtualenv:

(venv)CWD> /space/vhosts/pyramid.xcode.com/venv/build/unittest 
project@pyramid 43> yolk -l
Chameleon       - 2.8.2        - active 
Jinja2          - 2.6          - active 
Mako            - 0.7.0        - active 
MarkupSafe      - 0.15         - active 
PasteDeploy     - 1.5.0        - active 
Pygments        - 1.5          - active 
Python          - 2.7.3        - active development (/usr/lib/python2.7/lib-dynload)
SQLAlchemy      - 0.7.6        - active 
WebOb           - 1.2b3        - active 
account         - 0.0          - active development (/space/vhosts/pyramid.xcode.com/project/account)
distribute      - 0.6.19       - active 
egenix-mx-base  - 3.2.3        - active 
ipython         - 0.12         - active 
logilab-astng   - 0.23.1       - active 
logilab-common  - 0.57.1       - active 
nose            - 1.1.2        - active 
pbkdf2          - 1.3          - active 
pip             - 1.0.2        - active 
pyScss          - 1.1.3        - active 
pycrypto        - 2.5          - active 
pylint          - 0.25.1       - active 
pyramid-debugtoolbar - 1.0.1        - active 
pyramid-tm      - 0.4          - active 
pyramid         - 1.3          - active 
repoze.lru      - 0.5          - active 
simplejson      - 2.5.0        - active 
transaction     - 1.2.0        - active 
translationstring - 1.1          - active 
venusian        - 1.0a3        - active 
waitress        - 0.8.1        - active 
wsgiref         - 0.1.2        - active development (/usr/lib/python2.7)
yolk            - 0.4.3        - active 
zope.deprecation - 3.5.1        - active 
zope.interface  - 3.8.0        - active 
zope.sqlalchemy - 0.7          - active 

回答 5

您可以使用grep命令进行查找。

pip show <package_name>|grep Version

例:

pip show urllib3|grep Version

将仅显示版本。

元数据版本:2.0
版本:1.12

You can use the grep command to find out.

pip show <package_name>|grep Version

Example:

pip show urllib3|grep Version

will show only the versions.

Metadata-Version: 2.0
Version: 1.12


回答 6

最简单的方法是这样的:

import jinja2
print jinja2.__version__

The easiest way is this:

import jinja2
print jinja2.__version__

回答 7

还有一个名为的工具pip-check,可为您提供所有已安装软件包及其更新状态的快速概述:

在此处输入图片说明

我自己没有使用过;只是偶然地偶然发现了这个问题,因此没有被提及…

There’s also a tool called pip-check which gives you a quick overview of all installed packages and their update status:

enter image description here

Haven’t used it myself; just stumbled upon it and this SO question in quick succession, and since it wasn’t mentioned…


回答 8

在Windows上,您可以发出以下命令:

pip show setuptools | findstr "Version"

输出:

Version: 34.1.1

On windows, you can issue command such as:

pip show setuptools | findstr "Version"

Output:

Version: 34.1.1

回答 9

python函数仅以机器可读格式返回软件包版本:

from importlib.metadata import version 
version('numpy')

在python 3.8之前:

pip install importlib-metadata 
from importlib_metadata import version
version('numpy')

bash等效项(这里也从python调用)会复杂得多(但更健壮-请参见下面的注意事项):

import subprocess
def get_installed_ver(pkg_name):
    bash_str="pip freeze | grep -w %s= | awk -F '==' {'print $2'} | tr -d '\n'" %(pkg_name)
    return(subprocess.check_output(bash_str, shell=True).decode())

用法示例:

# pkg_name="xgboost"
# pkg_name="Flask"
# pkg_name="Flask-Caching"
pkg_name="scikit-learn"

print(get_installed_ver(pkg_name))
>>> 0.22

请注意,在两种情况下,pkg_name参数都应包含程序包名称,其格式应为返回的格式,pip freeze而不是在此过程中使用的格式import,例如scikit-learnnot sklearnFlask-Caching,not flask_caching

请注意,虽然pip freeze在bash版本中调用似乎效率低下,但只有这种方法被证明足够强大,可以打包命名的特殊性和不一致性(例如,下划线vs破折号,小写vs大写字母以及缩写,例如sklearnvs scikit-learn)。

注意:在复杂的环境中,这两种变体都可能返回令人惊讶的版本号,这与您在期间实际获得的内容不一致import

用户 site-packages子文件夹中隐藏了其他版本的软件包时,就会出现这样的问题。为了说明使用version()这种情况的危险,我遇到了这种情况:

$ pip freeze | grep lightgbm
lightgbm==2.3.1

and

$ python -c "import lightgbm; print(lightgbm.__version__)"
2.3.1

vs.

$ python -c "from importlib_metadata import version; print(version(\"lightgbm\"))"
2.2.3

until you delete the subfolder with the old version (here 2.2.3) from the user folder (only one would normally be preserved by `pip` - the one installed as last with the `--user` switch):

$ ls /home/jovyan/.local/lib/python3.7/site-packages/lightgbm*
/home/jovyan/.local/lib/python3.7/site-packages/lightgbm-2.2.3.dist-info
/home/jovyan/.local/lib/python3.7/site-packages/lightgbm-2.3.1.dist-info

另一个问题是在同一环境中有一些conda安装的软件包。如果它们与pip安装的软件包共享依赖关系,并且这些依赖关系的版本不同,则您可能会降低pip安装的依赖关系的等级。

为了说明这一点,numpyPyPI于04-01-2020 上提供的最新版本是1.18.0,与此同时,Anaconda的conda-forge频道仅提供了1.17.3版本numpy。因此,当您basemap使用conda(第二个)安装软件包时,先前pip安装的numpy版本将被conda降级为1.17.3,并且该import功能无法使用1.18.0版本。在这种情况下version()是正确的,和pip freeze/或conda list错误的:

$ python -c "from importlib_metadata import version; print(version(\"numpy\"))"
1.17.3

$ python -c "import numpy; print(numpy.__version__)"
1.17.3

$ pip freeze | grep numpy
numpy==1.18.0

$ conda list | grep numpy
numpy                     1.18.0                   pypi_0    pypi

The python function returning just the package version in a machine-readable format:

from importlib.metadata import version 
version('numpy')

Prior to python 3.8:

pip install importlib-metadata 
from importlib_metadata import version
version('numpy')

The bash equivalent (here also invoked from python) would be much more complex (but more robust – see caution below):

import subprocess
def get_installed_ver(pkg_name):
    bash_str="pip freeze | grep -w %s= | awk -F '==' {'print $2'} | tr -d '\n'" %(pkg_name)
    return(subprocess.check_output(bash_str, shell=True).decode())

Sample usage:

# pkg_name="xgboost"
# pkg_name="Flask"
# pkg_name="Flask-Caching"
pkg_name="scikit-learn"

print(get_installed_ver(pkg_name))
>>> 0.22

Note that in both cases pkg_name parameter should contain package name in the format as returned by pip freeze and not as used during import, e.g. scikit-learn not sklearn or Flask-Caching, not flask_caching.

Note that while invoking pip freeze in bash version may seem inefficient, only this method proves to be sufficiently robust to package naming peculiarities and inconsistencies (e.g. underscores vs dashes, small vs large caps, and abbreviations such as sklearn vs scikit-learn).

Caution: in complex environments both variants can return surprise version numbers, inconsistent with what you can actually get during import.

One such problem arises when there are other versions of the package hidden in a user site-packages subfolder. As an illustration of the perils of using version() here’s a situation I encountered:

$ pip freeze | grep lightgbm
lightgbm==2.3.1

and

$ python -c "import lightgbm; print(lightgbm.__version__)"
2.3.1

vs.

$ python -c "from importlib_metadata import version; print(version(\"lightgbm\"))"
2.2.3

until you delete the subfolder with the old version (here 2.2.3) from the user folder (only one would normally be preserved by `pip` - the one installed as last with the `--user` switch):

$ ls /home/jovyan/.local/lib/python3.7/site-packages/lightgbm*
/home/jovyan/.local/lib/python3.7/site-packages/lightgbm-2.2.3.dist-info
/home/jovyan/.local/lib/python3.7/site-packages/lightgbm-2.3.1.dist-info

Another problem is having some conda-installed packages in the same environment. If they share dependencies with your pip-installed packages, and versions of these dependencies differ, you may get downgrades of your pip-installed dependencies.

To illustrate, the latest version of numpy available in PyPI on 04-01-2020 was 1.18.0, while at the same time Anaconda’s conda-forge channel had only 1.17.3 version on numpy as their latest. So when you installed a basemap package with conda (as second), your previously pip-installed numpy would get downgraded by conda to 1.17.3, and version 1.18.0 would become unavailable to the import function. In this case version() would be right, and pip freeze/conda list wrong:

$ python -c "from importlib_metadata import version; print(version(\"numpy\"))"
1.17.3

$ python -c "import numpy; print(numpy.__version__)"
1.17.3

$ pip freeze | grep numpy
numpy==1.18.0

$ conda list | grep numpy
numpy                     1.18.0                   pypi_0    pypi

回答 10

pip show在python 3.7中有效:

pip show selenium
Name: selenium
Version: 4.0.0a3
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache 2.0
Location: c:\python3.7\lib\site-packages\selenium-4.0.0a3-py3.7.egg
Requires: urllib3
Required-by:

pip show works in python 3.7:

pip show selenium
Name: selenium
Version: 4.0.0a3
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache 2.0
Location: c:\python3.7\lib\site-packages\selenium-4.0.0a3-py3.7.egg
Requires: urllib3
Required-by:

回答 11

为此,请使用Python代码:

使用 importlib.metadata.version

Python≥3.8

import importlib.metadata
importlib.metadata.version('beautifulsoup4')
'4.9.1'

Python≤3.7

(使用importlib_metadata.version

!pip install importlib-metadata

import importlib_metadata
importlib_metadata.version('beautifulsoup4')
'4.9.1'

使用 pkg_resources.Distribution

import pkg_resources
pkg_resources.get_distribution('beautifulsoup4').version
'4.9.1'
pkg_resources.get_distribution('beautifulsoup4').parsed_version
<Version('4.9.1')>

归功于sinorocmirekphd的评论。

To do this using Python code:

Using importlib.metadata.version

Python ≥3.8

import importlib.metadata
importlib.metadata.version('beautifulsoup4')
'4.9.1'

Python ≤3.7

(using importlib_metadata.version)

!pip install importlib-metadata

import importlib_metadata
importlib_metadata.version('beautifulsoup4')
'4.9.1'

Using pkg_resources.Distribution

import pkg_resources
pkg_resources.get_distribution('beautifulsoup4').version
'4.9.1'
pkg_resources.get_distribution('beautifulsoup4').parsed_version
<Version('4.9.1')>

Credited to comments by sinoroc and mirekphd.


回答 12

对于Windows,您可以

  1. 打开cmd并键入python,然后按Enter。

  2. 键入导入,然后按Enter。

  3. 输入._version__并按Enter。

如您在此处的屏幕快照中所见,我正在使用此方法检查串行模块的版本。

图片


For Windows you can

  1. open cmd and type python, press enter.

  2. type the import and press enter.

  3. type ._version__ and press enter.

As you can see in screen shot here I am using this method for checking the version of serial module.

Image



回答 13

有问题的是,没有提到哪个OS用户正在使用(Windows / Linux / Mac)

因为有几个答案可以在Mac和Linux上完美运行。

如果用户试图在Windows上查找python软件包的版本,可以使用以下命令。

在PowerShell中,使用以下命令:

pip list | findstr <PackageName>

例:- pip list | findstr requests

输出: requests 2.18.4

In question, it is not mentioned which OS user is using (Windows/Linux/Mac)

As there are couple of answers which will work flawlessly on Mac and Linux.

Below command can be used in case the user is trying to find the version of a python package on windows.

In PowerShell use below command :

pip list | findstr <PackageName>

Example:- pip list | findstr requests

Output : requests 2.18.4


从git repo分支安装pip

问题:从git repo分支安装pip

尝试pip安装仓库的特定分支。Google告诉我

点安装git + https://github.com/user/repo.git@branch

分支的名称是issue/34/oscar-0.6我这样做的,pip install https://github.com/tangentlabs/django-oscar-paypal.git@/issue/34/oscar-0.6但是它返回了404。

如何安装此分支?

Trying to pip install a repo’s specific branch. Google tells me to

pip install git+https://github.com/user/repo.git@branch

The branch’s name is issue/34/oscar-0.6 so I did pip install https://github.com/tangentlabs/django-oscar-paypal.git@/issue/34/oscar-0.6 but its returning a 404.

How do I install this branch?


回答 0

在url前缀之前git+(请参阅VCS支持):

pip install git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6

并指定分支名称,但不要以/。开头。

Prepend the url prefix git+ (See VCS Support):

pip install git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6

And specify the branch name without the leading /.


回答 1

将git +与pip一起使用来克隆存储库可能非常慢(例如,使用https://github.com/django/django@stable/1.6.x进行测试,这将需要几分钟的时间)。我发现与GitHub和BitBucket兼容的最快的东西是:

pip install https://github.com/user/repository/archive/branch.zip

成为django master的对象:

pip install https://github.com/django/django/archive/master.zip

对于django stable / 1.7.x:

pip install https://github.com/django/django/archive/stable/1.7.x.zip

使用BitBucket,它具有相同的可预测模式:

pip install https://bitbucket.org/izi/django-admin-tools/get/default.zip

在这里,master分支通常被命名为default。这将使您的requirements.txt安装速度更快。

其他一些答案提到将要安装的软件包放入您的时所需的变体requirements.txt。请注意,这个档案的语法,领先-e和落后#egg=blah-blah不是必需的,你可以只是简单粘贴URL,所以你requirements.txt的样子:

https://github.com/user/repository/archive/branch.zip

Using pip with git+ to clone a repository can be extremely slow (test with https://github.com/django/django@stable/1.6.x for example, it will take a few minutes). The fastest thing I’ve found, which works with GitHub and BitBucket, is:

pip install https://github.com/user/repository/archive/branch.zip

which becomes for django master:

pip install https://github.com/django/django/archive/master.zip

for django stable/1.7.x:

pip install https://github.com/django/django/archive/stable/1.7.x.zip

With BitBucket it’s about the same predictable pattern:

pip install https://bitbucket.org/izi/django-admin-tools/get/default.zip

Here, the master branch is generally named default. This will make your requirements.txt installing much faster.

Some other answers mention variations required when placing the package to be installed into your requirements.txt. Note that with this archive syntax, the leading -e and trailing #egg=blah-blah are not required, and you can just simply paste the URL, so your requirements.txt looks like:

https://github.com/user/repository/archive/branch.zip

回答 2

使用ssh凭证从专用存储库安装的说明:

$ pip install git+ssh://git@github.com/myuser/foo.git@my_version

Instructions to install from private repo using ssh credentials:

$ pip install git+ssh://git@github.com/myuser/foo.git@my_version

回答 3

只是要添加一个额外的内容,如果要在pip文件中安装它,可以这样添加:

-e git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6#egg=django-oscar-paypal

但是它将被保存为鸡蛋。

Just to add an extra, if you want to install it in your pip file it can be added like this:

-e git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6#egg=django-oscar-paypal

It will be saved as an egg though.


回答 4

您使用了egg文件的安装过程。该程序支持安装了gitgit+httpgit+httpsgit+sshgit+gitgit+file。其中提到了一些。

可以使用分支,标签或哈希值进行安装是很好的。

@Steve_K指出,使用“ git +”安装可能会很慢,并建议通过zip文件进行安装:

pip install https://github.com/user/repository/archive/branch.zip

或者,建议您使用该.whl文件(如果存在)进行安装。

pip install https://github.com/user/repository/archive/branch.whl

这是一种非常新的格式,比egg文件更新。它需要wheel和setuptools> = 0.8软件包。您可以在这里找到更多。

You used the egg files install procedure. This procedure supports installing over git, git+http, git+https, git+ssh, git+git and git+file. Some of these are mentioned.

It’s good you can use branches, tags, or hashes to install.

@Steve_K noted it can be slow to install with “git+” and proposed installing via zip file:

pip install https://github.com/user/repository/archive/branch.zip

Alternatively, I suggest you may install using the .whl file if this exists.

pip install https://github.com/user/repository/archive/branch.whl

It’s pretty new format, newer than egg files. It requires wheel and setuptools>=0.8 packages. You can find more in here.


回答 5

这就像魅力一样工作:

pip3 install git+https://github.com/deepak1725/fabric8-analytics-worker.git@develop

哪里:

发展:分支

fabric8-analytics-worker.git:回购

deepak1725:用户

This worked like charm:

pip3 install git+https://github.com/deepak1725/fabric8-analytics-worker.git@develop

Where :

develop: Branch

fabric8-analytics-worker.git : Repo

deepak1725: user


Pip-Python软件包安装程序

PIP-Python软件包安装程序

PIP是package installer为了Python。您可以使用pip从Python Package Index和其他索引

请查看我们的文档,了解如何安装和使用pip:

我们定期发布更新,每3个月更新一次。有关更多详细信息,请参阅我们的文档:

在PIP20.3中,我们已经made a big improvement to the heart of piplearn more我们需要你的意见,所以sign up for our user experience research studies来帮助我们做好这件事

注意事项:pip 21.0,在2021年1月,删除了对每个pip的Python 2支持Python 2 support policy请迁移到Python 3

如果您发现错误、需要帮助或想与开发人员交谈,请使用我们的邮件列表或聊天室:

如果您想参与到GitHub获取源代码,请查看我们的开发文档,并随时跳转到开发人员邮件列表和聊天室:

行为规范

在pip项目的代码库、问题跟踪器、聊天室和邮件列表中交互的每个人都应该遵循PSF Code of Conduct

如何使用pip升级所有Python软件包?

问题:如何使用pip升级所有Python软件包?

是否可以一次升级所有Python软件包pip

注意:官方问题追踪器上对此功能有要求

Is it possible to upgrade all Python packages at one time with pip?

Note: that there is a feature request for this on the official issue tracker.


回答 0

还没有内置标志,但是您可以使用

pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U

注意:为此存在无限的潜在变化。我试图使这个答案简短而简单,但是请在评论中提出一些建议!

在的旧版本中pip,您可以改用以下代码:

pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U

grep@jawache所建议的,该命令将跳过可编辑的(“ -e”)程序包定义。(是的,您可以将grep+ 替换cutsedor awkperlor or …)。

-n1标志用于xargs防止在更新一个软件包失败时停止所有操作(感谢@andsens)。

There isn’t a built-in flag yet, but you can use

pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U

Note: there are infinite potential variations for this. I’m trying to keep this answer short and simple, but please do suggest variations in the comments!

In older version of pip, you can use this instead:

pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U

The grep is to skip editable (“-e”) package definitions, as suggested by @jawache. (Yes, you could replace grep+cut with sed or awk or perl or…).

The -n1 flag for xargs prevents stopping everything if updating one package fails (thanks @andsens).


回答 1

您可以使用以下Python代码。与不同pip freeze,这不会打印警告和FIXME错误。 对于点<10.0.1

import pip
from subprocess import call

packages = [dist.project_name for dist in pip.get_installed_distributions()]
call("pip install --upgrade " + ' '.join(packages), shell=True)

对于点> = 10.0.1

import pkg_resources
from subprocess import call

packages = [dist.project_name for dist in pkg_resources.working_set]
call("pip install --upgrade " + ' '.join(packages), shell=True)

You can use the following Python code. Unlike pip freeze, this will not print warnings and FIXME errors. For pip < 10.0.1

import pip
from subprocess import call

packages = [dist.project_name for dist in pip.get_installed_distributions()]
call("pip install --upgrade " + ' '.join(packages), shell=True)

For pip >= 10.0.1

import pkg_resources
from subprocess import call

packages = [dist.project_name for dist in pkg_resources.working_set]
call("pip install --upgrade " + ' '.join(packages), shell=True)

回答 2

升级所有本地软件包;您可以使用pip-review

$ pip install pip-review
$ pip-review --local --interactive

pip-review是的叉子pip-tools。见pip-tools问题被提到@knedlsepppip-review包有效,但pip-tools包不再有效。

pip-review从0.5版开始在Windows上运行。

To upgrade all local packages; you could use pip-review:

$ pip install pip-review
$ pip-review --local --interactive

pip-review is a fork of pip-tools. See pip-tools issue mentioned by @knedlsepp. pip-review package works but pip-tools package no longer works.

pip-review works on Windows since version 0.5.


回答 3

适用于Windows。也应该对别人有好处。($是您在命令提示符下所在的目录,例如C:/ Users / Username>)

$ pip freeze > requirements.txt

打开文本文件,替换==>=,并执行

$ pip install -r requirements.txt --upgrade

如果您对某个软件包停止升级有问题(有时为numpy),则只需转到目录($),注释掉名称(在其前面添加#),然后再次运行升级。您稍后可以取消对该部分的注释。这对于复制python全局环境也非常有用。


另一种方式:

我也喜欢pip-review方法:

py2
$ pip install pip-review

$ pip-review --local --interactive

py3
$ pip3 install pip-review

$ py -3 -m pip_review --local --interactive

您可以选择“ a”来升级所有软件包。如果一次升级失败,请再次运行它,然后继续进行下一次升级。

Works on Windows. Should be good for others too. ($ is whatever directory you’re in, in command prompt. eg. C:/Users/Username>)

do

$ pip freeze > requirements.txt

open the text file, replace the == with >= , and execute

$ pip install -r requirements.txt --upgrade

If you have a problem with a certain package stalling the upgrade (numpy sometimes), just go to the directory ($), comment out the name (add a # before it) and run the upgrade again. You can later uncomment that section back. This is also great for copying python global environments.


Another way:

I also like the pip-review method:

py2
$ pip install pip-review

$ pip-review --local --interactive

py3
$ pip3 install pip-review

$ py -3 -m pip_review --local --interactive

You can select ‘a’ to upgrade all packages; if one upgrade fails, run it again and it continues at the next one.


回答 4

咨询优良的售后服务Windows版本文档FOR罗布范德Woude

for /F "delims===" %i in ('pip freeze -l') do pip install -U %i

Windows version after consulting excellent documentation for FOR by Rob van der Woude

for /F "delims===" %i in ('pip freeze -l') do pip install -U %i

回答 5

使用pipupgrade

$ pip install pipupgrade
$ pipupgrade --verbose --latest --yes

pipupgrade可帮助您从requirements.txt文件升级系统,本地或软件包!它还有选择地升级不会破坏更改的软件包。pipupgrade还确保升级存在于多个Python环境中的软件包。与Python2.7 +,Python3.4 +和pip9 +,pip10 +,pip18 +,pip19 +兼容。

在此处输入图片说明

注意:我是该工具的作者。

Use pipupgrade!

$ pip install pipupgrade
$ pipupgrade --verbose --latest --yes

pipupgrade helps you upgrade your system, local or packages from a requirements.txt file! It also selectively upgrades packages that don’t break change. pipupgrade also ensures to upgrade packages present within multiple Python environments. Compatible with Python2.7+, Python3.4+ and pip9+, pip10+, pip18+, pip19+.

enter image description here

NOTE: I’m the author of the tool.


回答 6

您可以只打印过时的软件包

pip freeze | cut -d = -f 1 | xargs -n 1 pip search | grep -B2 'LATEST:'

You can just print the packages that are outdated

pip freeze | cut -d = -f 1 | xargs -n 1 pip search | grep -B2 'LATEST:'

回答 7

在我看来,此选项更直接易读:

pip install -U `pip list --outdated | awk 'NR>2 {print $1}'`

解释是以pip list --outdated这种格式输出所有过时软件包的列表:

Package   Version Latest Type 
--------- ------- ------ -----
fonttools 3.31.0  3.32.0 wheel
urllib3   1.24    1.24.1 wheel
requests  2.20.0  2.20.1 wheel

在awk命令中,NR>2跳过前两个记录(行)并{print $1}选择每行的第一个单词(如SergioAraujo所建议,我删除了它,tail -n +3因为awk它确实可以处理跳过的记录)。

This option seems to me more straightforward and readable:

pip install -U `pip list --outdated | awk 'NR>2 {print $1}'`

The explanation is that pip list --outdated outputs a list of all the outdated packages in this format:

Package   Version Latest Type 
--------- ------- ------ -----
fonttools 3.31.0  3.32.0 wheel
urllib3   1.24    1.24.1 wheel
requests  2.20.0  2.20.1 wheel

In the awk command, NR>2 skips the first two records (lines) and {print $1} selects the first word of each line (as suggested by SergioAraujo, I removed tail -n +3 since awk can indeed handle skipping records).


回答 8

以下一线可能会有所帮助:

(点> 20.0)

pip list --format freeze --outdated | sed 's/=.*//g' | xargs -n1 pip install -U

旧版本:

pip list --format freeze --outdated | sed 's/(.*//g' | xargs -n1 pip install -U

xargs -n1 继续发生错误。

如果您需要对遗漏的内容和引起错误的内容进行更多的“细粒度”控制,则不应添加-n1标记并显式定义要忽略的错误,方法是为每个单独的错误“插入”以下行:

| sed 's/^<First characters of the error>.*//'

这是一个工作示例:

pip list --format freeze --outdated | sed 's/=.*//g' | sed 's/^<First characters of the first error>.*//' | sed 's/^<First characters of the second error>.*//' | xargs pip install -U

The following one-liner might prove of help:

(pip > 20.0)

pip list --format freeze --outdated | sed 's/=.*//g' | xargs -n1 pip install -U

Older Versions:

pip list --format freeze --outdated | sed 's/(.*//g' | xargs -n1 pip install -U

xargs -n1 keeps going if an error occurs.

If you need more “fine grained” control over what is omitted and what raises an error you should not add the -n1 flag and explicitly define the errors to ignore, by “piping” the following line for each separate error:

| sed 's/^<First characters of the error>.*//'

Here is a working example:

pip list --format freeze --outdated | sed 's/=.*//g' | sed 's/^<First characters of the first error>.*//' | sed 's/^<First characters of the second error>.*//' | xargs pip install -U

回答 9

更强大的解决方案

对于pip3,请使用以下命令:

pip3 freeze --local |sed -rn 's/^([^=# \t\\][^ \t=]*)=.*/echo; echo Processing \1 ...; pip3 install -U \1/p' |sh

对于点子,只需将3删除即可:

pip freeze --local |sed -rn 's/^([^=# \t\\][^ \t=]*)=.*/echo; echo Processing \1 ...; pip install -U \1/p' |sh

OSX奇数

截至2017年7月,OSX随附了非常老版本的sed(已有十二年历史)。要获取扩展的正则表达式,请在上述解决方案中使用-E而不是-r。

用流行的解决方案解决问题

该解决方案经过精心设计和测试1,而即使是最流行的解决方案也存在问题。

  • 由于更改pip命令行功能而导致的可移植性问题
  • 由于常见的pip或pip3子进程失败而导致xargs崩溃
  • 来自原始xargs输出的拥挤日志
  • 依靠Python到OS的网桥,同时可能对其进行升级3

上面的命令结合使用sed和sh来使用最简单,最可移植的pip语法来完全解决这些问题。sed操作的详细信息可以通过注释的版本2进行审查。


细节

[1]经过测试并在Linux 4.8.16-200.fc24.x86_64群集中正常使用,并在其他五种Linux / Unix版本上进行了测试。它还可以在Windows 10上安装的Cygwin64上运行。需要在iOS上进行测试。

[2]为了更清楚地了解命令的结构,这与上面带有注释的pip3命令完全等效:

# match lines from pip's local package list output
# that meet the following three criteria and pass the
# package name to the replacement string in group 1.
# (a) Do not start with invalid characters
# (b) Follow the rule of no white space in the package names
# (c) Immediately follow the package name with an equal sign
sed="s/^([^=# \t\\][^ \t=]*)=.*"

# separate the output of package upgrades with a blank line
sed="$sed/echo"

# indicate what package is being processed
sed="$sed; echo Processing \1 ..."

# perform the upgrade using just the valid package name
sed="$sed; pip3 install -U \1"

# output the commands
sed="$sed/p"

# stream edit the list as above
# and pass the commands to a shell
pip3 freeze --local |sed -rn "$sed" |sh

[3]升级还用于升级Python或PIP组件的Python或PIP组件可能是导致死锁或软件包数据库损坏的潜在原因。

More Robust Solution

For pip3 use this:

pip3 freeze --local |sed -rn 's/^([^=# \t\\][^ \t=]*)=.*/echo; echo Processing \1 ...; pip3 install -U \1/p' |sh

For pip, just remove the 3s as such:

pip freeze --local |sed -rn 's/^([^=# \t\\][^ \t=]*)=.*/echo; echo Processing \1 ...; pip install -U \1/p' |sh

OSX Oddity

OSX, as of July 2017, ships with a very old version of sed (a dozen years old). To get extended regular expressions, use -E instead of -r in the solution above.

Solving Issues with Popular Solutions

This solution is well designed and tested1, whereas there are problems with even the most popular solutions.

  • Portability issues due to changing pip command line features
  • Crashing of xargs because common pip or pip3 child process failures
  • Crowded logging from the raw xargs output
  • Relying on a Python-to-OS bridge while potentially upgrading it3

The above command uses the simplest and most portable pip syntax in combination with sed and sh to overcome these issues completely. Details of sed operation can be scrutinized with the commented version2.


Details

[1] Tested and regularly used in a Linux 4.8.16-200.fc24.x86_64 cluster and tested on five other Linux/Unix flavors. It also runs on Cygwin64 installed on Windows 10. Testing on iOS is needed.

[2] To see the anatomy of the command more clearly, this is the exact equivalent of the above pip3 command with comments:

# match lines from pip's local package list output
# that meet the following three criteria and pass the
# package name to the replacement string in group 1.
# (a) Do not start with invalid characters
# (b) Follow the rule of no white space in the package names
# (c) Immediately follow the package name with an equal sign
sed="s/^([^=# \t\\][^ \t=]*)=.*"

# separate the output of package upgrades with a blank line
sed="$sed/echo"

# indicate what package is being processed
sed="$sed; echo Processing \1 ..."

# perform the upgrade using just the valid package name
sed="$sed; pip3 install -U \1"

# output the commands
sed="$sed/p"

# stream edit the list as above
# and pass the commands to a shell
pip3 freeze --local |sed -rn "$sed" |sh

[3] Upgrading a Python or PIP component that is also used in the upgrading of a Python or PIP component can be a potential cause of a deadlock or package database corruption.


回答 10

这似乎更简洁。

pip list --outdated | cut -d ' ' -f1 | xargs -n1 pip install -U

说明:

pip list --outdated 得到这样的线

urllib3 (1.7.1) - Latest: 1.15.1 [wheel]
wheel (0.24.0) - Latest: 0.29.0 [wheel]

在中cut -d ' ' -f1-d ' '将“空格”设置为定界符,-f1表示获取第一列。

因此,以上几行变为:

urllib3
wheel

然后将它们传递xargs给运行命令pip install -U,并将每行作为附加参数

-n1将传递给每个命令的参数数量限制pip install -U为1

This seems more concise.

pip list --outdated | cut -d ' ' -f1 | xargs -n1 pip install -U

Explanation:

pip list --outdated gets lines like these

urllib3 (1.7.1) - Latest: 1.15.1 [wheel]
wheel (0.24.0) - Latest: 0.29.0 [wheel]

In cut -d ' ' -f1, -d ' ' sets “space” as the delimiter, -f1 means to get the first column.

So the above lines becomes:

urllib3
wheel

then pass them to xargs to run the command, pip install -U, with each line as appending arguments

-n1 limits the number of arguments passed to each command pip install -U to be 1


回答 11

我在升级时遇到了同样的问题。问题是,我从不升级所有软件包。我只升级我需要的东西,因为项目可能会中断。

因为没有简便的方法来逐个软件包升级软件包和更新requirements.txt文件,所以我写了这个pip-upgrader,它requirements.txt为所选软件包(或所有软件包)更新了文件中的版本

安装

pip install pip-upgrader

用法

激活您的virtualenv(这很重要,因为它还将在当前virtualenv中安装新版本的升级软件包)。

cd 进入您的项目目录,然后运行:

pip-upgrade

高级用法

如果需求放置在非标准位置,请将其作为参数发送:

pip-upgrade path/to/requirements.txt

如果您已经知道要升级的软件包,只需将它们作为参数发送:

pip-upgrade -p django -p celery -p dateutil

如果您需要升级到发行前/发行后版本,--prerelease请在命令中添加参数。

全面披露:我写了这个包裹。

I had the same problem with upgrading. Thing is, i never upgrade all packages. I upgrade only what i need, because project may break.

Because there was no easy way for upgrading package by package, and updating the requirements.txt file, i wrote this pip-upgrader which also updates the versions in your requirements.txt file for the packages chosen (or all packages).

Installation

pip install pip-upgrader

Usage

Activate your virtualenv (important, because it will also install the new versions of upgraded packages in current virtualenv).

cd into your project directory, then run:

pip-upgrade

Advanced usage

If the requirements are placed in a non-standard location, send them as arguments:

pip-upgrade path/to/requirements.txt

If you already know what package you want to upgrade, simply send them as arguments:

pip-upgrade -p django -p celery -p dateutil

If you need to upgrade to pre-release / post-release version, add --prerelease argument to your command.

Full disclosure: I wrote this package.


回答 12

https://github.com/cakebread/yolk

$ pip install -U `yolk -U | awk '{print $1}' | uniq`

但是,您需要先获得蛋黄:

$ sudo pip install -U yolk

From https://github.com/cakebread/yolk :

$ pip install -U `yolk -U | awk '{print $1}' | uniq`

however you need to get yolk first:

$ sudo pip install -U yolk

回答 13

@Ramana的答案的一线版。

python -c 'import pip, subprocess; [subprocess.call("pip install -U " + d.project_name, shell=1) for d in pip.get_installed_distributions()]'

`

One-liner version of @Ramana’s answer.

python -c 'import pip, subprocess; [subprocess.call("pip install -U " + d.project_name, shell=1) for d in pip.get_installed_distributions()]'

`


回答 14

使用virtualenv时,如果您只想升级添加到virtualenv中的软件包,则可能需要执行以下操作:

pip install `pip freeze -l | cut --fields=1 -d = -` --upgrade

when using a virtualenv and if you just want to upgrade packages added to your virtualenv, you may want to do:

pip install `pip freeze -l | cut --fields=1 -d = -` --upgrade

回答 15

点子问题讨论中找到的最简单,最快的解决方案是:

pip install pipdate
pipdate

来源:https//github.com/pypa/pip/issues/3819

The simplest and fastest solution that I found in the pip issue discussion is:

pip install pipdate
pipdate

Source: https://github.com/pypa/pip/issues/3819


回答 16

Windows Powershell解决方案

pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade $_}

Windows Powershell solution

pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade $_}

回答 17

使用awk更新包: pip install -U $(pip freeze | awk -F'[=]' '{print $1}')

Windows Powershell更新 foreach($p in $(pip freeze)){ pip install -U $p.Split("=")[0]}

use awk update packges: pip install -U $(pip freeze | awk -F'[=]' '{print $1}')

windows powershell update foreach($p in $(pip freeze)){ pip install -U $p.Split("=")[0]}


回答 18

您可以尝试以下方法:

for i in ` pip list|awk -F ' ' '{print $1}'`;do pip install --upgrade $i;done

You can try this :

for i in ` pip list|awk -F ' ' '{print $1}'`;do pip install --upgrade $i;done

回答 19

相当惊人的蛋黄使这一过程变得容易。

pip install yolk3k # don't install `yolk`, see https://github.com/cakebread/yolk/issues/35
yolk --upgrade

有关蛋黄的更多信息:https : //pypi.python.org/pypi/yolk/0.4.3

它可以做很多您可能会发现有用的事情。

The rather amazing yolk makes this easy.

pip install yolk3k # don't install `yolk`, see https://github.com/cakebread/yolk/issues/35
yolk --upgrade

For more info on yolk: https://pypi.python.org/pypi/yolk/0.4.3

It can do lots of things you’ll probably find useful.


回答 20

@Ramana的答案对我来说最有效,但是我不得不添加一些注意事项:

import pip
for dist in pip.get_installed_distributions():
    if 'site-packages' in dist.location:
        try:
            pip.call_subprocess(['pip', 'install', '-U', dist.key])
        except Exception, exc:
            print exc

site-packages检查不包括我的开发包,因为它们不在系统site-packages目录中。try-except仅跳过已从PyPI中删除的软件包。

@endolith:我也希望有一个简单的方法pip.install(dist.key, upgrade=True),但是它看起来不像pip应该被命令行以外的任何东西使用(文档没有提到内部API,并且pip开发人员没有使用文档字符串)。

@Ramana’s answer worked the best for me, of those here, but I had to add a few catches:

import pip
for dist in pip.get_installed_distributions():
    if 'site-packages' in dist.location:
        try:
            pip.call_subprocess(['pip', 'install', '-U', dist.key])
        except Exception, exc:
            print exc

The site-packages check excludes my development packages, because they are not located in the system site-packages directory. The try-except simply skips packages that have been removed from PyPI.

@endolith: I was hoping for an easy pip.install(dist.key, upgrade=True), too, but it doesn’t look like pip was meant to be used by anything but the command line (the docs don’t mention the internal API, and the pip developers didn’t use docstrings).


回答 21

pip_upgrade_outdated做这项工作。根据其文档

usage: pip_upgrade_outdated [-h] [-3 | -2 | --pip_cmd PIP_CMD]
                            [--serial | --parallel] [--dry_run] [--verbose]
                            [--version]

Upgrade outdated python packages with pip.

optional arguments:
  -h, --help         show this help message and exit
  -3                 use pip3
  -2                 use pip2
  --pip_cmd PIP_CMD  use PIP_CMD (default pip)
  --serial, -s       upgrade in serial (default)
  --parallel, -p     upgrade in parallel
  --dry_run, -n      get list, but don't upgrade
  --verbose, -v      may be specified multiple times
  --version          show program's version number and exit

步骤1:

pip install pip-upgrade-outdated

第2步:

pip_upgrade_outdated

The pip_upgrade_outdated does the job. According to its docs:

usage: pip_upgrade_outdated [-h] [-3 | -2 | --pip_cmd PIP_CMD]
                            [--serial | --parallel] [--dry_run] [--verbose]
                            [--version]

Upgrade outdated python packages with pip.

optional arguments:
  -h, --help         show this help message and exit
  -3                 use pip3
  -2                 use pip2
  --pip_cmd PIP_CMD  use PIP_CMD (default pip)
  --serial, -s       upgrade in serial (default)
  --parallel, -p     upgrade in parallel
  --dry_run, -n      get list, but don't upgrade
  --verbose, -v      may be specified multiple times
  --version          show program's version number and exit

Step 1:

pip install pip-upgrade-outdated

Step 2:

pip_upgrade_outdated

回答 22

通过拉动请求发送给小学生。同时使用此pip库解决方案,我写道:

from pip import get_installed_distributions
from pip.commands import install

install_cmd = install.InstallCommand()

options, args = install_cmd.parse_args([package.project_name
                                        for package in
                                        get_installed_distributions()])

options.upgrade = True
install_cmd.run(options, args)  # Chuck this in a try/except and print as wanted

Sent through a pull-request to the pip folk; in the meantime use this pip library solution I wrote:

from pip import get_installed_distributions
from pip.commands import install

install_cmd = install.InstallCommand()

options, args = install_cmd.parse_args([package.project_name
                                        for package in
                                        get_installed_distributions()])

options.upgrade = True
install_cmd.run(options, args)  # Chuck this in a try/except and print as wanted

回答 23

这似乎对我有用…

pip install -U $(pip list --outdated|awk '{printf $1" "}')

printf之后,我使用了一个空格来正确分隔软件包名称。

This seemed to work for me…

pip install -U $(pip list --outdated|awk '{printf $1" "}')

I used printf with a space afterwards to properly separate the package names.


回答 24

这是针对Python 3的PowerShell解决方案:

pip3 list --outdated --format=legacy | ForEach { pip3 install -U $_.split(" ")[0] }

对于Python 2:

pip2 list --outdated --format=legacy | ForEach { pip2 install -U $_.split(" ")[0] }

这将一个接一个地升级软件包。所以

pip3 check
pip2 check

之后应确保没有依赖项被破坏。

This is a PowerShell solution for Python 3:

pip3 list --outdated --format=legacy | ForEach { pip3 install -U $_.split(" ")[0] }

And for Python 2:

pip2 list --outdated --format=legacy | ForEach { pip2 install -U $_.split(" ")[0] }

This upgrades the packages one by one. So a

pip3 check
pip2 check

afterwards should make sure no dependencies are broken.


回答 25

怎么样:

pip install -r <(pip freeze) --upgrade

How about:

pip install -r <(pip freeze) --upgrade

回答 26

在Windows上最短,最简单。

pip freeze > requirements.txt && pip install --upgrade -r requirements.txt && rm requirements.txt

The shortest and easiest on Windows.

pip freeze > requirements.txt && pip install --upgrade -r requirements.txt && rm requirements.txt

回答 27

我的剧本:

pip list --outdated --format=legacy | cut -d ' ' -f1 | xargs -n1 pip install --upgrade

My script:

pip list --outdated --format=legacy | cut -d ' ' -f1 | xargs -n1 pip install --upgrade

回答 28

这不是更有效吗?

pip3 list -o | grep -v -i warning | cut -f1 -d' ' | tr " " "\n" | awk '{if(NR>=3)print}' | cut -d' ' -f1 | xargs -n1 pip3 install -U 
  1. pip list -o 列出过期的软件包;
  2. grep -v -i warning启用反向匹配warning以避免更新时出错
  3. cut -f1 -d1' ' 返回第一个单词-过时的包的名称;
  4. tr "\n|\r" " "将多行结果cut转换为单行,以空格分隔的列表;
  5. awk '{if(NR>=3)print}' 跳过标题行
  6. cut -d' ' -f1 获取第一列
  7. xargs -n1 pip install -U 从左管道中获取1个参数,并将其传递给命令以升级软件包列表。

Isn’t this more effective?

pip3 list -o | grep -v -i warning | cut -f1 -d' ' | tr " " "\n" | awk '{if(NR>=3)print}' | cut -d' ' -f1 | xargs -n1 pip3 install -U 
  1. pip list -o lists outdated packages;
  2. grep -v -i warning inverted match on warning to avoid errors when updating
  3. cut -f1 -d1' ' returns the first word – the name of the outdated package;
  4. tr "\n|\r" " " converts the multiline result from cut into a single-line, space-separated list;
  5. awk '{if(NR>=3)print}' skips header lines
  6. cut -d' ' -f1 fetches the first column
  7. xargs -n1 pip install -U takes 1 argument from the pipe left of it, and passes it to the command to upgrade the list of packages.

回答 29

在Powershell 5.1中具有adm权限,python 3.6.5和pip ver 10.0.1的一行:

pip list -o --format json | ConvertFrom-Json | foreach {pip install $_.name -U --no-warn-script-location}

如果列表中没有破损的包装或特殊的轮子,它会正常工作…

one line in powershell 5.1 with adm rights, python 3.6.5 and pip ver 10.0.1:

pip list -o --format json | ConvertFrom-Json | foreach {pip install $_.name -U --no-warn-script-location}

it works smoothly if there are no broken packages or special wheels in the list…