标签归档:pip

点破了。如何修复DistributionNotFound错误?

问题:点破了。如何修复DistributionNotFound错误?

每当我尝试使用pip时,都会出现错误。例如:

$ sudo pip install gevent-websocket

Traceback (most recent call last):  
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2675, in <module>
parse_requirements(__requires__), Environment()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 552, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==0.8.1

我很想将pip的值更改为pip == 0.8.2 ..,但是我没有处理“ hacking”我的安装的后果…我正在运行python 2.7,pip的版本为0.8.2。

Whenever i try to use pip I get an error. For exampple:

$ sudo pip install gevent-websocket

Traceback (most recent call last):  
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2675, in <module>
parse_requirements(__requires__), Environment()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 552, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==0.8.1

I feel tempted to change the value of into pip==0.8.2.. but I dont feel dealing with the consequences of ‘hacking’ up my installation… I’m running python 2.7 and pip is at version 0.8.2.


回答 0

我在MacBook中发现了这个问题,原因是因为正如@Stephan所说,我easy_install 用来安装pip,而这两种py软件包管理工具的混合导致了pkg_resources.DistributionNotFound问题。解决方法是:

easy_install --upgrade pip

记住:只使用一个以上的工具来管理您的PY包。

I find this problem in my MacBook, the reason is because as @Stephan said, I use easy_install to install pip, and the mixture of both py package manage tools led to the pkg_resources.DistributionNotFound problem. The resolve is:

easy_install --upgrade pip

Remember: just use one of the above tools to manage your Py packages.


回答 1

我在/ usr / local / bin / pip的0.8.2中替换了0.8.1,一切都恢复了。

__requires__ = 'pip==0.8.2'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('pip==0.8.2', 'console_scripts', 'pip')()
    )

我通过easy_install安装了pip,这可能使我头痛。我认为这是您现在应该做的..

$ sudo apt-get install python-pip python-dev build-essential 
$ sudo pip install --upgrade pip 
$ sudo pip install --upgrade virtualenv

I replaced 0.8.1 in 0.8.2 in /usr/local/bin/pip and everything worked again.

__requires__ = 'pip==0.8.2'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('pip==0.8.2', 'console_scripts', 'pip')()
    )

I installed pip through easy_install which probably caused me this headache. I think this is how you should do it nowadays..

$ sudo apt-get install python-pip python-dev build-essential 
$ sudo pip install --upgrade pip 
$ sudo pip install --upgrade virtualenv

回答 2

我在使用自制软件时遇到了这个问题。这是第26900期的解决方案

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

I had this issue when I was using homebrew. Here is the solution from Issue #26900

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

回答 3

尝试使用get-pip脚本重新安装:

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

这是从pip Github页面上获取的,并为我工作。

Try re-installing with the get-pip script:

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

This is sourced from the pip Github page, and worked for me.


回答 4

如果您使用的是CentOS,请确保已安装YUM软件包“ python-setuptools”

yum install python-setuptools

为我修复它。

If you’re on CentOS make sure you have the YUM package “python-setuptools” installed

yum install python-setuptools

Fixed it for me.


回答 5

问题的根源通常是bin(Linux)或Scripts(Windows)子目录中的过时脚本。我将以我遇到的问题为例对此进行解释。

我在用户站点包中安装了virtualenv 1.10版本(实际上,它在用户站点包中而不是系统站点包中是无关紧要的)

pdobrogost@host:~$ which virtualenv
/home/users/pdobrogost/.local/bin/virtualenv
pdobrogost@host:~$ virtualenv --version
1.10

将其升级到版本1.11后,出现以下错误:

pdobrogost@host:~$ virtualenv --version  
Traceback (most recent call last):   
  File "/home/users/pdobrogost/.local/bin/virtualenv", line 5, in <module>
    from pkg_resources import load_entry_point   
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2701, in <module>
    return self.__dep_map   
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 572, in resolve
    if insert: 
pkg_resources.DistributionNotFound: virtualenv==1.10

/home/users/pdobrogost/.local/bin/virtualenv错误消息中提到的文件如下所示:

#!/opt/python/2.7.5/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'virtualenv==1.10','console_scripts','virtualenv'
__requires__ = 'virtualenv==1.10'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('virtualenv==1.10', 'console_scripts', 'virtualenv')()
    ) 

在那里,我们看到该virtualenv脚本未更新,仍然需要先前安装的virtualenv 1.10版本。
现在,像这样重新安装virtualenv

pdobrogost@host:~$ pip install --user --upgrade virtualenv
Downloading/unpacking virtualenv from https://pypi.python.org/packages/py27/v/virtualenv/virtualenv-1.11.1-py27-none-any.whl#md5=265770b61de41d34d2e9fdfddcdf034c
  Using download cache from /home/users/pdobrogost/.pip_download_cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fpy27%2Fv%2Fvirtualenv%2Fvirtualenv-1.11.1-py27-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...

无济于事(两者都不是pip install --user --upgrade --force-reinstall virtualenv),因为脚本/home/users/pdobrogost/.local/bin/virtualenv保持不变。

我可以解决此问题的唯一方法是从/home/users/pdobrogost/.local/bin/文件夹中手动删除virtualenv *脚本,然后再次安装virtualenv。之后,新生成的脚本将引用该软件包的正确版本:

pdobrogost@host:~$ virtualenv --version
1.11

The root of the problem are often outdated scripts in the bin (Linux) or Scripts (Windows) subdirectory. I’ll explain this using problem I encountered myself as an example.

I had virtualenv version 1.10 installed in my user site-packages (the fact it’s in user site-packages not sytem site-packages is irrelevant here)

pdobrogost@host:~$ which virtualenv
/home/users/pdobrogost/.local/bin/virtualenv
pdobrogost@host:~$ virtualenv --version
1.10

After I upgraded it to version 1.11 I got the following error:

pdobrogost@host:~$ virtualenv --version  
Traceback (most recent call last):   
  File "/home/users/pdobrogost/.local/bin/virtualenv", line 5, in <module>
    from pkg_resources import load_entry_point   
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2701, in <module>
    return self.__dep_map   
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 572, in resolve
    if insert: 
pkg_resources.DistributionNotFound: virtualenv==1.10

File /home/users/pdobrogost/.local/bin/virtualenv mentioned in the error message looked like this:

#!/opt/python/2.7.5/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'virtualenv==1.10','console_scripts','virtualenv'
__requires__ = 'virtualenv==1.10'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('virtualenv==1.10', 'console_scripts', 'virtualenv')()
    ) 

There, we see that virtualenv script was not updated and still requires previously installed version 1.10 of virtualenv.
Now, reinstalling virtualenv like this

pdobrogost@host:~$ pip install --user --upgrade virtualenv
Downloading/unpacking virtualenv from https://pypi.python.org/packages/py27/v/virtualenv/virtualenv-1.11.1-py27-none-any.whl#md5=265770b61de41d34d2e9fdfddcdf034c
  Using download cache from /home/users/pdobrogost/.pip_download_cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fpy27%2Fv%2Fvirtualenv%2Fvirtualenv-1.11.1-py27-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...

does not help (neither pip install --user --upgrade --force-reinstall virtualenv) because script /home/users/pdobrogost/.local/bin/virtualenv is left unchanged.

The only way I could fix this was by manually removing virtualenv* scripts from /home/users/pdobrogost/.local/bin/ folder and installing virtualenv again. After this, newly generated scripts refer to the proper version of the package:

pdobrogost@host:~$ virtualenv --version
1.11

回答 6

我能够这样解决:

$ brew update
$ brew doctor
$ brew uninstall python
$ brew install python --build-from-source    # took ~5 mins
$ python --version                           # => Python 2.7.9
$ pip install --upgrade pip

我正在运行以下内容(截至2015年1月2日):

OS X Yosemite
Version 10.10.1

$ brew -v
Homebrew 0.9.5

$ python --version
Python 2.7.9

$ ipython --version
2.2.0

$ pip --version
pip 6.0.3 from /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.3-py2.7.egg (python 2.7)

$ which pip
/usr/local/bin/pip

I was able to resolve this like so:

$ brew update
$ brew doctor
$ brew uninstall python
$ brew install python --build-from-source    # took ~5 mins
$ python --version                           # => Python 2.7.9
$ pip install --upgrade pip

I’m running w/ the following stuff (as of Jan 2, 2015):

OS X Yosemite
Version 10.10.1

$ brew -v
Homebrew 0.9.5

$ python --version
Python 2.7.9

$ ipython --version
2.2.0

$ pip --version
pip 6.0.3 from /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.3-py2.7.egg (python 2.7)

$ which pip
/usr/local/bin/pip

回答 7

我在OSx中面临类似的问题。我的堆栈跟踪说

raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: setuptools>=11.3

然后我做了以下

sudo pip install --upgrade setuptools

这为我解决了问题。希望有人会觉得有用。

I was facing the similar problem in OSx. My stacktrace was saying

raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: setuptools>=11.3

Then I did the following

sudo pip install --upgrade setuptools

This solved the problem for me. Hope someone will find this useful.


回答 8

在Mac OS X(MBP)上,以下内容(从此处找到的另一个答案中解决)解决了我的问题:

C02L257NDV33:~ jjohnson$ brew install pip
Error: No available formula for pip
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can:
    sudo easy_install pip
C02L257NDV33:~ jjohnson$ sudo easy_install pip

显然,这里的根本原因是使用第二种方法来安装python(在我的情况下是Homebrew)。希望负责pip脚本的人员可以解决此问题,因为自从首次报告Stack Overflow以来,该问题仍然有意义两年。

On Mac OS X (MBP), the following (taken from another answer found herein) resolved my issues:

C02L257NDV33:~ jjohnson$ brew install pip
Error: No available formula for pip
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can:
    sudo easy_install pip
C02L257NDV33:~ jjohnson$ sudo easy_install pip

Clearly the root cause here is having a secondary method by which to install python (in my case Homebrew). Hopefully, the people responsible for the pip script can remedy this issue since its still relevant 2 years after first being reported on Stack Overflow.


回答 9

我遇到了这个问题,因为我安装了python / pip ~/.pydistutils.cfg,但我不记得自己写了。删除它,重新安装(带有pybrew),一切都很好。

I had this problem because I installed python/pip with a weird ~/.pydistutils.cfg that I didn’t remember writing. Deleted it, reinstalled (with pybrew), and everything was fine.


回答 10

就我而言(山姆问题,但其他软件包)没有版本依赖性。一系列的pip卸载和pip insstall确实有所帮助。

In my case (sam problem, but other packages) there was no version dependency. A sequence of pip uninstall and pip insstall did help.


ImportError:在Windows 7 32位中运行pip –version命令时无法导入名称main

问题:ImportError:在Windows 7 32位中运行pip –version命令时无法导入名称main

我已经为32位Windows安装了与pip和setuptools捆绑在一起的最新python(2.7.9)。我尝试重新安装pip,但问题仍然存在。

这是pip --version在Administrator cmd中运行后的错误:

Traceback (most recent call last):
 File "D:\Python\lib\runpy.py", line 162, in _run_module_as_main
  "__main__", fname, loader, pkg_name)
 File "D:\Python\lib\runpy.py", line 72, in _run_code 
  exec code in run_globals
 File "D:\Python\Scripts\pip.exe\__main__.py", line 5, in <module>
ImportError: cannot import name main

I’ve installed the latest python (2.7.9) bundled with pip and setuptools for windows 32-bit. I’ve tried reinstalling pip but the problem persists.

Here’s the error after running pip --version in Administrator cmd:

Traceback (most recent call last):
 File "D:\Python\lib\runpy.py", line 162, in _run_module_as_main
  "__main__", fname, loader, pkg_name)
 File "D:\Python\lib\runpy.py", line 72, in _run_code 
  exec code in run_globals
 File "D:\Python\Scripts\pip.exe\__main__.py", line 5, in <module>
ImportError: cannot import name main

回答 0

尽管最初的问题似乎来自2015年,但这个“错误”似乎也影响了用户的安装pip-10.0.0

解决方法是不修改pip,而是更改pip的调用方式。而不是通过Python本身调用/usr/bin/pipcall pip。例如,代替以下内容:

pip install <package>

如果来自Python版本2(或称为默认Python二进制文件python),请执行以下操作:

python -m pip install <package>

还是从Python版本3:

python3 -m pip install <package> 

Even though the original question seems to be from 2015, this ‘bug’ seems to affect users installing pip-10.0.0 as well.

The workaround is not to modify pip, however to change the way pip is called. Instead of calling /usr/bin/pip call pip via Python itself. For example, instead of the below:

pip install <package>

If from Python version 2 (or default Python binary is called python) do :

python -m pip install <package>

or if from Python version 3:

python3 -m pip install <package> 

回答 1

该错误位于pip 10.0.0中。

在Linux中,您需要从以下位置修改文件:/ usr / bin / pip:

from pip import main
if __name__ == '__main__':
    sys.exit(main())

对此:

from pip import __main__
if __name__ == '__main__':
    sys.exit(__main__._main())

The bug is found in pip 10.0.0.

In linux you need to modify file: /usr/bin/pip from:

from pip import main
if __name__ == '__main__':
    sys.exit(main())

to this:

from pip import __main__
if __name__ == '__main__':
    sys.exit(__main__._main())

回答 2

在Ubuntu Server 16上,python27也有相同的问题。试试这个:

更改

from pip import main
if __name__ == '__main__':
    sys.exit(main())

from pip._internal import main
if __name__ == '__main__':
    sys.exit(main())

On Ubuntu Server 16, I have the same problem with python27. Try this:

Change

from pip import main
if __name__ == '__main__':
    sys.exit(main())

To

from pip._internal import main
if __name__ == '__main__':
    sys.exit(main())

回答 3

在Windows 10上,我使用以下命令降级了pip:

python -m pip uninstall pip
python -m pip install pip==9.0.3

这也应该在Linux和Mac上也可以使用。

On Windows 10, I used the following commands to downgrade pip:

python -m pip uninstall pip
python -m pip install pip==9.0.3

This should also work on Linux and Mac too.


回答 4

我遇到了同样的问题,但是使用apt和pip卸载并重新安装对我来说不起作用。

我看到了另一个解决方案,它提供了一种恢复pip3路径的简便方法:

sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

I had the same problem, but uninstall and reinstall with apt and pip didn’t work for me.

I saw another solution that presents a easy way to recover pip3 path:

sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

回答 5

我通过使用重新安装pip来解决此问题get-pip.py

  1. 从官方链接下载get-pip:https//pip.pypa.io/en/stable/installing/#upgrading-pip
  2. 使用commande:运行它python get-pip.py

点子是固定的,可以完美地工作。

i fixed the problem by reinstalling pip using get-pip.py.

  1. Download get-pip from official link: https://pip.pypa.io/en/stable/installing/#upgrading-pip
  2. run it using commande: python get-pip.py.

And pip is fixed and work perfectly.


回答 6

在MacOS上,如果您通过Homebrew安装了python,请在 /usr/local/opt/python/libexec/bin/pip

from pip.internal import main

from pip._internal import main

或使用这种衬板: sed -i '' "s/from pip import main/from pip._internal import main/" /usr/local/opt/python/libexec/bin/pip

说明:

此问题是由于pip版本10中的内部移动命名空间的更改main._internal以及Homebrew仍然从旧位置(以前是版本9中)查找的bin脚本引起的。问题和一些讨论https://github.com/pypa/pip/issues/5240

On MacOS if you’ve installed python via Homebrew, change the line in /usr/local/opt/python/libexec/bin/pip

from

from pip.internal import main

to

from pip._internal import main

Or use this one liner: sed -i '' "s/from pip import main/from pip._internal import main/" /usr/local/opt/python/libexec/bin/pip

Explanation:

The issue is caused by the changes in pip version 10 moving internal namespace under main._internal and the bin script put in place by homebrew still looking it from the old place (where it used to be in version 9). Issue and some discussion https://github.com/pypa/pip/issues/5240


回答 7

如果您有要插入的硬链接PATH(即,如果安装了多个python版本),然后升级了pip,则也可能会遇到此错误。

解决方案包括再次创建硬链接。甚至更好的是,停止使用硬链接并使用软链接。

If you have a hardlink to pip in your PATH (i.e. if you have multiple python versions installed) and then you upgrade pip, you may also encounter this error.

The solution consists in creating the hardlink again. Or even better, stop using hardlinks and use softlinks.


回答 8

在Windows 10上,我遇到了同样的问题。PIP 19已安装在我的系统中,但没有显示。错误是No Module Found

python -m pip uninstall pip
python -m pip install pip==9.0.3

降级pip到9.0.3对我来说很好。

On Windows 10, I had the same problem. PIP 19 was already installed in my system but wasn’t showing up. The error was No Module Found.

python -m pip uninstall pip
python -m pip install pip==9.0.3

Downgrading pip to 9.0.3 worked fine for me.


回答 9

对于使用pip 10和PyCharm遇到类似问题的人,请在此处下载最新版本

For those having similar trouble using pip 10 with PyCharm, download the latest version here


回答 10

它适用于Ubuntu 16.04。第1步:

 sudo gedit /home/user_name/.local/bin/pip

将打开一个包含以下内容的文件:

#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from pip import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

将更main改为__main__,如下所示:

#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from pip import __main__

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(__main__._main())

保存文件并关闭它。您完成了!

It works on ubuntu 16.04. Step 1:

 sudo gedit /home/user_name/.local/bin/pip

a file opens with the content:

#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from pip import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

Change the main to __main__ as it appears below:

#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from pip import __main__

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(__main__._main())

Save the file and close it. And you are done!


回答 11

试试这个

#!/usr/bin/python
# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.i
try:
    from pip import main
except ImportError:
    from pip._internal import main
if __name__ == '__main__':
    sys.exit(main())

try this

#!/usr/bin/python
# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.i
try:
    from pip import main
except ImportError:
    from pip._internal import main
if __name__ == '__main__':
    sys.exit(main())

回答 12

一个适用于Ubuntu的简单解决方案,但也可以在Windows上解决该问题:

刚打电话

pip install --upgrade pip

A simple solution that works with Ubuntu, but may fix the problem on windows too:

Just call

pip install --upgrade pip

回答 13

这在尝试使用python3.6时解决了我在ubuntu 18.04中的问题:

rm -rf ~/.local/lib/python3.6

您可以使用mv将文件夹移动到另一个位置,而不是将其删除,以进行测试:

mv ~/.local/lib/python3.6 ./python3.6_old

This solved my problem in ubuntu 18.04 when trying to use python3.6:

rm -rf ~/.local/lib/python3.6

You can move the folder to another place using mv instead of deleting it too, for testing:

mv ~/.local/lib/python3.6 ./python3.6_old

回答 14

打开您的终端Linux。

hash -d pip

Open your terminal linux.

hash -d pip

回答 15

在我们的案例中,在2020年使用Python3,解决此问题的方法是将Python安装移至cloud-init实例化VM 的启动脚本。

当我们尝试使用VM生命周期中稍后由用户调用的脚本来安装Python时,我们也遇到了相同的错误,但是将相同的Python安装代码移至该cloud-init脚本可以解决此问题。

In our case, in 2020 using Python3, the solution to this problem was to move the Python installation to the cloud-init startup script which instantiated the VM.

We had been encountering this same error when we had been trying to install Python using scripts that were called by users later in the VM’s life cycle, but moving the same Python installation code to the cloud-init script eliminated this problem.


运行`pip install`的Ubuntu给出错误’无法构建以下必需的软件包:* freetype’

问题:运行`pip install`的Ubuntu给出错误’无法构建以下必需的软件包:* freetype’

执行时pip install -r requirements.txt,在安装阶段出现以下错误matplotlib

REQUIRED DEPENDENCIES AND EXTENSIONS
                 numpy: yes [not found. pip may install it below.]
              dateutil: yes [dateutil was not found. It is required for date
                        axis support. pip/easy_install may attempt to
                        install it after matplotlib.]
               tornado: yes [tornado was not found. It is required for the
                        WebAgg backend. pip/easy_install may attempt to
                        install it after matplotlib.]
             pyparsing: yes [pyparsing was not found. It is required for
                        mathtext support. pip/easy_install may attempt to
                        install it after matplotlib.]
                 pycxx: yes [Couldn't import.  Using local copy.]
                libagg: yes [pkg-config information for 'libagg' could not
                        be found. Using local copy.]
              freetype: no  [pkg-config information for 'freetype2' could
                        not be found.]

The following required packages can not be built:

                    * freetype

还不应该pip install -r requirements.txt安装freetype吗?freetype应该如何在Ubuntu 12.04中安装以便与它一起使用matplotlib

When performing pip install -r requirements.txt, I get the following error during the stage where it is installing matplotlib:

REQUIRED DEPENDENCIES AND EXTENSIONS
                 numpy: yes [not found. pip may install it below.]
              dateutil: yes [dateutil was not found. It is required for date
                        axis support. pip/easy_install may attempt to
                        install it after matplotlib.]
               tornado: yes [tornado was not found. It is required for the
                        WebAgg backend. pip/easy_install may attempt to
                        install it after matplotlib.]
             pyparsing: yes [pyparsing was not found. It is required for
                        mathtext support. pip/easy_install may attempt to
                        install it after matplotlib.]
                 pycxx: yes [Couldn't import.  Using local copy.]
                libagg: yes [pkg-config information for 'libagg' could not
                        be found. Using local copy.]
              freetype: no  [pkg-config information for 'freetype2' could
                        not be found.]

The following required packages can not be built:

                    * freetype

Shouldn’t pip install -r requirements.txt also install freetype? How should freetype be installed in Ubuntu 12.04 so it works with matplotlib?


回答 0

否。pip不会安装系统级别的依赖项。这意味着pip将不会安装RPM(基于Redhat的系统)或DEB(基于Debian的系统)。

要安装系统依赖项,您将需要根据系统使用以下方法之一。

Ubuntu / Debian:

apt-get install libfreetype6-dev

要在基于Ubuntu / Debian的系统上搜索软件包:

apt-cache search <string>

例如:

apt-cache search freetype | grep dev

Redhat / CentOS / Fedora:

yum -y install freetype-devel

要在基于Redhat / CentOS / Fedora的系统上搜索软件包:

yum search <string>

例如:

yum search freetype | grep devel

Mac OS X的:通过自制

brew install freetype

在基于Mac OS X的系统上搜索软件包:

brew search <string>

例如:

brew search freetype

No. pip will not install system-level dependencies. This means pip will not install RPM(s) (Redhat based systems) or DEB(s) (Debian based systems).

To install system dependencies you will need to use one of the following methods depending on your system.

Ubuntu/Debian:

apt-get install libfreetype6-dev

To search for packages on Ubuntu/Debian based systems:

apt-cache search <string>

e.g:

apt-cache search freetype | grep dev

Redhat/CentOS/Fedora:

yum -y install freetype-devel

To search for packages on Redhat/CentOS/Fedora based systems:

yum search <string>

e.g:

yum search freetype | grep devel

Mac OS X: (via Homebrew)

brew install freetype

To search for packages on Mac OS X based systems:

brew search <string>

e.g:

brew search freetype

回答 1

我必须安装libxft-dev才能在ubuntu服务器14.04上启用matplotlib。

sudo apt-get install libfreetype6-dev libxft-dev

然后我可以使用

sudo easy_install matplotlib

I had to install libxft-dev in order to enable matplotlib on ubuntu server 14.04.

sudo apt-get install libfreetype6-dev libxft-dev

And then I could use

sudo easy_install matplotlib

回答 2

sudo apt-get install pkg-config在此github问题中发现一种解决方法。

A workaround is to do sudo apt-get install pkg-config which I found in this github issue.


回答 3

现有的答案都无法在Ubuntu上升级matplotlib。这最终对我有用:

$ sudo apt-get install build-dep python-matplotlib
$ pip install matplotlib --upgrade

None of the existing answers worked for me to upgrade matplotlib on Ubuntu. This is what ultimately work for me:

$ sudo apt-get install build-dep python-matplotlib
$ pip install matplotlib --upgrade

回答 4

此命令将下载所有依赖项。

对于python 2.x

sudo apt-get install python-matplotlib

对于python 3.x

sudo apt-get install python3-matplotlib

安装后,您可以尝试

(sudo) pip install matplotlib

This command will download all dependencies.

For python 2.x

sudo apt-get install python-matplotlib

For python 3.x

sudo apt-get install python3-matplotlib

After installing, you can try

(sudo) pip install matplotlib

回答 5

在Ubuntu上,安装blt-dev软件包后它可以工作。

$sudo apt-get install blt-dev
$pip install matplotlib

On Ubuntu, it worked after I installed blt-dev package.

$sudo apt-get install blt-dev
$pip install matplotlib

回答 6

我正在使用Mint,但以下答案均不适合我,我需要:

sudo apt-get install build-essential g++

I’m using Mint an none of this answers worked for me, I needed to:

sudo apt-get install build-essential g++

回答 7

我在Windows上使用Python 3.6时遇到了同样的问题,但是后来我切换到Python 3.5.2,一切正常。

I had the same issue with Python 3.6 on Windows, but then I switched to Python 3.5.2 and everything works fine.


回答 8

这个命令sudo apt-get install libfreetype6-dev对我来说在Ubuntu 16.04上失败了,
The following packages have unmet dependencies: libfreetype6-dev : Depends: libfreetype6 (= 2.6.1-0.1ubuntu2) but 2.6.1-0.1ubuntu2.3 is to be installed

因此,我从源代码下载了已安装的freetype ,请参考本指南

$ tar -xvjf freetype-x.y.tar.bz2  # extract the downloaded version file
$ cd freetype-x.y/ 
$ ./configure
$ make
$ sudo make install 

切换到virtualenv并且pip install matplotlib一切正常。

This command sudo apt-get install libfreetype6-dev failed for me on ubuntu 16.04,
The following packages have unmet dependencies: libfreetype6-dev : Depends: libfreetype6 (= 2.6.1-0.1ubuntu2) but 2.6.1-0.1ubuntu2.3 is to be installed

So I downloaded installed freetype from the source, credit to this guide

$ tar -xvjf freetype-x.y.tar.bz2  # extract the downloaded version file
$ cd freetype-x.y/ 
$ ./configure
$ make
$ sudo make install 

switched to virtualenv and pip install matplotlib and everything is working.


如何在Windows上安装Python软件包?

问题:如何在Windows上安装Python软件包?

我很难设置python软件包。应该可以使用SetupTools的 EasyInstall来解决此问题,但是它们没有适用于Python 2.6的可执行文件。

例如,要安装Mechanize,我只想根据INSTALL.txt将Mechanize文件夹放在C:\ Python24 \ Lib \ site-packages中,但运行测试无效。有人可以帮忙阐明一下吗?谢谢!

I’m having a hard time setting up python packages. EasyInstall from SetupTools is supposed to help that, but they don’t have an executable for Python 2.6.

For instance to install Mechanize, I’m just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!


回答 0

接受的答案是过时的。因此,首先pip要优先于easy_install,(为什么要在easy_install上使用pip?)。然后按照以下步骤pip在Windows上安装,这非常容易。

  1. 安装setuptools

    curl https://bootstrap.pypa.io/ez_setup.py | python
  2. 安装pip

    curl https://bootstrap.pypa.io/get-pip.py | python
  3. (可选)您可以将路径添加到您的环境,以便可以pip在任何地方使用。就像C:\Python33\Scripts

The accepted answer is outdated. So first, pip is preferred over easy_install, (Why use pip over easy_install?). Then follow these steps to install pip on Windows, it’s quite easy.

  1. Install setuptools:

    curl https://bootstrap.pypa.io/ez_setup.py | python
    
  2. Install pip:

    curl https://bootstrap.pypa.io/get-pip.py | python
    
  3. Optionally, you can add the path to your environment so that you can use pip anywhere. It’s somewhere like C:\Python33\Scripts.


回答 1

pip软件包管理器随附了Windows的较新版本的Python 。(资源)

如果您使用的是Python 2> = 2.7.9或Python 3> = 3.4,则已经安装了pip

使用它来安装软件包:

cd C:\Python\Scripts\
pip.exe install <package-name>

因此,在您的情况下,它将是:

pip.exe install mechanize

Newer versions of Python for Windows come with the pip package manager. (source)

pip is already installed if you’re using Python 2 >=2.7.9 or Python 3 >=3.4

Use that to install packages:

cd C:\Python\Scripts\
pip.exe install <package-name>

So in your case it’d be:

pip.exe install mechanize

回答 2

是有关如何easy_install在Windows 上获得良好的教程。简短的答案:将C:\Python26\Scripts(或安装的任何python)添加到PATH。

This is a good tutorial on how to get easy_install on windows. The short answer: add C:\Python26\Scripts (or whatever python you have installed) to your PATH.


回答 3

您不需要setuptools的可执行文件。您可以下载源代码,解压缩它,遍历下载的目录并python setup.py install在命令提示符下运行

You don’t need the executable for setuptools. You can download the source code, unpack it, traverse to the downloaded directory and run python setup.py install in the command prompt


回答 4

从Python 2.7开始,默认情况下包含pip。只需通过以下网址下载所需的软件包

python -m pip install [package-name]

Starting with Python 2.7, pip is included by default. Simply download your desired package via

python -m pip install [package-name]

回答 5

正如我在其他地方写的

用Python打包很可怕。根本原因是该语言在没有软件包管理器的情况下出厂。

幸运的是,有一个用于Python的软件包管理器,称为Pip。Pip受Ruby’s Gem的启发,但缺少一些功能。具有讽刺意味的是,Pip本身安装起来很复杂。在流行的64位Windows上进行安装需要从源代码构建和安装两个软件包。对于任何刚接触编程的人来说,这都是一个很大的要求。


因此,正确的做法是安装pip。但是,如果您不介意的话,Christoph Gohlke将为所有Windows平台的流行Python软件包提供二进制文件http://www.lfd.uci.edu/~gohlke/pythonlibs/

实际上,构建某些Python软件包需要C编译器(例如mingw32)和依赖项的库头。在Windows上这可能是一场噩梦,因此请记住克里斯托夫·戈尔克(Christoph Gohlke)的名字。

As I wrote elsewhere

Packaging in Python is dire. The root cause is that the language ships without a package manager.

Fortunately, there is one package manager for Python, called Pip. Pip is inspired by Ruby’s Gem, but lacks some features. Ironically, Pip itself is complicated to install. Installation on the popular 64-bit Windows demands building and installing two packages from source. This is a big ask for anyone new to programming.


So the right thing to do is to install pip. However if you can’t be bothered, Christoph Gohlke provides binaries for popular Python packages for all Windows platforms http://www.lfd.uci.edu/~gohlke/pythonlibs/

In fact, building some Python packages requires a C compiler (eg. mingw32) and library headers for the dependencies. This can be a nightmare on Windows, so remember the name Christoph Gohlke.


回答 6

我在Windows上安装软件包时遇到问题。找到了解决方案。它适用于Windows7 +。主要是任何使用Windows Powershell的东西都应该能够使其工作。可以帮助您开始使用它。

  • 首先,您需要将python安装添加到PATH变量中。应该有所帮助。
  • 您需要下载要安装的zip格式的软件包,然后将其解压缩。如果是一些奇怪的zip格式,请使用7Zip,并且应该将其解压缩。
  • 使用Windows Powershell导航到setup.py提取的目录(如果遇到问题,请使用链接)
  • 运行命令 python setup.py install

当没有其他意义的时候,这对我有用。我使用的是Python 2.7,但文档显示,同样适用于Python3.x。

I had problems in installing packages on Windows. Found the solution. It works in Windows7+. Mainly anything with Windows Powershell should be able to make it work. This can help you get started with it.

  • Firstly, you’ll need to add python installation to your PATH variable. This should help.
  • You need to download the package in zip format that you are trying to install and unzip it. If it is some odd zip format use 7Zip and it should be extracted.
  • Navigate to the directory extracted with setup.py using Windows Powershell (Use link for it if you have problems)
  • Run the command python setup.py install

That worked for me when nothing else was making any sense. I use Python 2.7 but the documentation suggests that same would work for Python 3.x also.


回答 7

pip是python的软件包安装程序,请先对其进行更新,然后再下载所需的文件

python -m pip install --upgrade pip

然后:

python -m pip install <package_name>

pip is the package installer for python, update it first, then download what you need

python -m pip install --upgrade pip

Then:

python -m pip install <package_name>

回答 8

通过命令提示符升级pip(Python目录)

D:\Python 3.7.2>python -m pip install --upgrade pip

现在您可以安装所需的模块

D:\Python 3.7.2>python -m pip install <<yourModuleName>>

Upgrade the pip via command prompt ( Python Directory )

D:\Python 3.7.2>python -m pip install --upgrade pip

Now you can install the required Module

D:\Python 3.7.2>python -m pip install <<yourModuleName>>

回答 9

您也可以下载并运行ez_setup.py,尽管SetupTools文档不再建议这样做。最近两周前对我来说还不错。

You can also just download and run ez_setup.py, though the SetupTools documentation no longer suggests this. Worked fine for me as recently as 2 weeks ago.


回答 10

PS D:\simcut>  C:\Python27\Scripts\pip.exe install networkx
Collecting networkx
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:318: SNIMissingWarning: An HTTPS reques
t has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may caus
e the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer ve
rsion of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissi
ngwarning.
  SNIMissingWarning
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SS
LContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL con
nections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.
readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading networkx-1.11-py2.py3-none-any.whl (1.3MB)
    100% |################################| 1.3MB 664kB/s
Collecting decorator>=3.4.0 (from networkx)
  Downloading decorator-4.0.11-py2.py3-none-any.whl
Installing collected packages: decorator, networkx
Successfully installed decorator-4.0.11 networkx-1.11
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SSLContext object i
s not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade
to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplat
formwarning.
  InsecurePlatformWarning

或者只是将目录放在系统路径中的pip可执行文件中。

PS D:\simcut>  C:\Python27\Scripts\pip.exe install networkx
Collecting networkx
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:318: SNIMissingWarning: An HTTPS reques
t has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may caus
e the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer ve
rsion of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissi
ngwarning.
  SNIMissingWarning
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SS
LContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL con
nections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.
readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading networkx-1.11-py2.py3-none-any.whl (1.3MB)
    100% |################################| 1.3MB 664kB/s
Collecting decorator>=3.4.0 (from networkx)
  Downloading decorator-4.0.11-py2.py3-none-any.whl
Installing collected packages: decorator, networkx
Successfully installed decorator-4.0.11 networkx-1.11
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SSLContext object i
s not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade
to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplat
formwarning.
  InsecurePlatformWarning

Or just put the directory to your pip executable in your system path.


回答 11

正如Blauhirn所说,预装2.7点后。如果对您不起作用,则可能需要将其添加到路径中。

但是,如果您运行Windows 10,则无需再打开终端来安装模块。打开Python也是如此。

您可以直接在搜索菜单中输入pip install mechanize,选择命令,它将安装:

如果出了什么问题,它可能会在您读取错误之前关闭,但这仍然是有用的快捷方式。

As mentioned by Blauhirn after 2.7 pip is preinstalled. If it is not working for you it might need to be added to path.

However if you run Windows 10 you no longer have to open a terminal to install a module. The same goes for opening Python as well.

You can type directly into the search menu pip install mechanize, select command and it will install:

If anything goes wrong however it may close before you can read the error but still it’s a useful shortcut.


DistutilsOptionError:必须提供home或prefix / exec-prefix —不能同时提供

问题:DistutilsOptionError:必须提供home或prefix / exec-prefix —不能同时提供

我通常是通过pip安装python软件包的。

对于Google App Engine,我需要将软件包安装到另一个目标目录。

我试过了:

pip install -I flask-restful –target ./lib

但是它失败了:

必须提供home或prefix / exec-prefix-不能同时提供

我怎样才能使它工作?

I’ve been usually installed python packages through pip.

For Google App Engine, I need to install packages to another target directory.

I’ve tried:

pip install -I flask-restful –target ./lib

but it fails with:

must supply either home or prefix/exec-prefix — not both

How can I get this to work?


回答 0

您正在使用OS X和Homebrew吗?Homebrew python页面https://github.com/Homebrew/brew/blob/master/docs/Homebrew-and-Python.md指出了pip的已知问题和解决方法。

为我工作。

通过添加具有以下内容的〜/ .pydistutils.cfg文件,可以将此“空前缀”设置为默认值:

[install]
prefix=

编辑:不要使用此Homebrew建议的选项,它将破坏正常的点操作

Are you using OS X and Homebrew? The Homebrew python page https://github.com/Homebrew/brew/blob/master/docs/Homebrew-and-Python.md calls out a known issue with pip and a work around.

Worked for me.

You can make this “empty prefix” the default by adding a ~/.pydistutils.cfg file with the following contents:

[install]
prefix=

Edit: Do not use this Homebrew recommended option, it will break normal pip operations.


回答 1

我相信有一个更简单的解决方案(在macOS上使用Homebrew的Python),不会破坏您的常规pip操作。

您要做的就是setup.cfg在项目的根目录下创建一个文件,通常在主__init__.py或可执行py文件所在的位置。因此,如果您的项目的根文件夹为:/path/to/my/project/,请setup.cfg在其中创建一个文件,然后在其中放入神奇的单词:

[install]
prefix=  

好的,现在您可以为该文件夹运行pip的命令:

pip install package -t /path/to/my/project/  

该命令仅在该文件夹中正常运行。只需将其复制setup.cfg到您可能拥有的任何其他项目中即可。无需.pydistutils.cfg在主目录上写一个。

安装完模块后,可以将其卸下 setup.cfg

I believe there is a simpler solution to this problem (Homebrew’s Python on macOS) that won’t break your normal pip operations.

All you have to do is to create a setup.cfg file at the root directory of your project, usually where your main __init__.py or executable py file is. So if the root folder of your project is: /path/to/my/project/, create a setup.cfg file in there and put the magic words inside:

[install]
prefix=  

OK, now you sould be able to run pip’s commands for that folder:

pip install package -t /path/to/my/project/  

This command will run gracefully for that folder only. Just copy setup.cfg to whatever other projects you might have. No need to write a .pydistutils.cfg on your home directory.

After you are done installing the modules, you may remove setup.cfg.


回答 2

在OSX(mac)上,假定项目文件夹为/ var / myproject

  1. cd /var/myproject
  2. 创建一个名为的文件setup.cfg并添加 [install] prefix=
  3. pip install <packagename> -t .

On OSX(mac), assuming a project folder called /var/myproject

  1. cd /var/myproject
  2. Create a file called setup.cfg and add [install] prefix=
  3. Run pip install <packagename> -t .

回答 3

针对Homebrew用户的另一种解决方案*仅是使用virtualenv

当然,无论如何,这可能会消除对目标目录的需求-但是即使没有,我发现--target在虚拟环境中时默认情况下也可以工作(例如,无需创建/修改配置文件)。


*我说解决方案;也许这只是精心使用venvs的另一动机…

Another solution* for Homebrew users is simply to use a virtualenv.

Of course, that may remove the need for the target directory anyway – but even if it doesn’t, I’ve found --target works by default (as in, without creating/modifying a config file) when in a virtual environment.


*I say solution; perhaps it’s just another motivation to meticulously use venvs…


回答 4

我在周围的其他建议中遇到了错误--install-option="--prefix=lib"。我发现唯一有效的方法就是PYTHONUSERBASE此处所述使用。

export PYTHONUSERBASE=lib
pip install -I flask-restful --user

这与并不完全相同--target,但是无论如何我都会成功。

I hit errors with the other recommendations around --install-option="--prefix=lib". The only thing I found that worked is using PYTHONUSERBASE as described here.

export PYTHONUSERBASE=lib
pip install -I flask-restful --user

this is not exactly the same as --target, but it does the trick for me in any case.


回答 5

如其他提到的那样,这是与homebrew一起安装的pip和python的已知错误。

如果~/.pydistutils.cfg使用“空前缀”指令创建文件,它将解决此问题,但会破坏正常的点操作。

在正式解决此错误之前,一种选择是创建自己的bash脚本来处理这种情况:

 #!/bin/bash

 name=''
 target=''

 while getopts 'n:t:' flag; do
     case "${flag}" in
         n) name="${OPTARG}" ;;
         t) target="${OPTARG}" ;;
     esac
 done

 if [ -z "$target" ];
 then
     echo "Target parameter must be provided"
     exit 1
 fi

 if [ -z "$name" ];
 then
     echo "Name parameter must be provided"
     exit 1
 fi

 # current workaround for homebrew bug
 file=$HOME'/.pydistutils.cfg'
 touch $file

 /bin/cat <<EOM >$file
 [install]
 prefix=
 EOM
 # end of current workaround for homebrew bug

 pip install -I $name --target $target

 # current workaround for homebrew bug
 rm -rf $file
 # end of current workaround for homebrew bug

该脚本包装了您的命令,并:

  1. 接受名称和目标参数
  2. 检查这些参数是否为空
  3. 创建~/.pydistutils.cfg其中带有“空前缀”指令的文件
  4. 使用提供的参数执行您的pip命令
  5. 删除~/.pydistutils.cfg文件

可以更改此脚本并将其改编为满足您的需求,但您有所想法。而且它使您可以在不制动点的情况下运行命令。希望能帮助到你 :)

As other mentioned, this is known bug with pip & python installed with homebrew.

If you create ~/.pydistutils.cfg file with “empty prefix” instruction it will fix this problem but it will break normal pip operations.

Until this bug is officially addressed, one of the options would be to create your own bash script that would handle this case:

 #!/bin/bash

 name=''
 target=''

 while getopts 'n:t:' flag; do
     case "${flag}" in
         n) name="${OPTARG}" ;;
         t) target="${OPTARG}" ;;
     esac
 done

 if [ -z "$target" ];
 then
     echo "Target parameter must be provided"
     exit 1
 fi

 if [ -z "$name" ];
 then
     echo "Name parameter must be provided"
     exit 1
 fi

 # current workaround for homebrew bug
 file=$HOME'/.pydistutils.cfg'
 touch $file

 /bin/cat <<EOM >$file
 [install]
 prefix=
 EOM
 # end of current workaround for homebrew bug

 pip install -I $name --target $target

 # current workaround for homebrew bug
 rm -rf $file
 # end of current workaround for homebrew bug

This script wraps your command and:

  1. accepts name and target parameters
  2. checks if those parameters are empty
  3. creates ~/.pydistutils.cfg file with “empty prefix” instruction in it
  4. executes your pip command with provided parameters
  5. removes ~/.pydistutils.cfg file

This script can be changed and adapted to address your needs but you get idea. And it allows you to run your command without braking pip. Hope it helps :)


回答 6

如果您使用的是virtualenv *,最好再次检查一下which pip您使用的是哪个。

如果看到类似情况,则说明/usr/local/bin/pip您已脱离环境。重新激活您的virtualenv将解决此问题:

VirtualEnv: $ source bin/activate

虚拟鱼: $ vf activate [environ]

*:我使用virtualfish,但我认为此技巧与两者都有关。

If you’re using virtualenv*, it might be a good idea to double check which pip you’re using.

If you see something like /usr/local/bin/pip you’ve broken out of your environment. Reactivating your virtualenv will fix this:

VirtualEnv: $ source bin/activate

VirtualFish: $ vf activate [environ]

*: I use virtualfish, but I assume this tip is relevant to both.


回答 7

我有一个类似的问题。我用–system标志,以避免错误,因为我粗糙地在这里对其他线程在这里我解释一下我的情况的具体情况。我将其发布在这里,希望可以帮助面临相同问题的任何人。

I have a similar issue. I use the –system flag to avoid the error as I decribe here on other thread where I explain the specific case of my situation. I post this here expecting that can help anyone facing the same problem.


如何在Anaconda(Conda)环境中跟踪点子安装的软件包?

问题:如何在Anaconda(Conda)环境中跟踪点子安装的软件包?

我已经安装并一直在使用Anaconda Python发行版,并且已经开始使用Anaconda(Conda)环境。我可以使用标准conda install...命令将分发包中的软件包放入我的环境中,但要使用其他pip install在活动环境中需要使用的东西(例如Flask-WTF,flask-sqlalchemy和alembic)。但是,当我查看环境的内容时,无论是在目录中还是使用conda list这些pip installed包,都不会显示。

使用pip freezepip list仅列出我曾经安装的每个软件包。

有没有办法跟踪我的每个Anaconda env(安装pipconda安装的)中的物品?

I’ve installed and have been using the Anaconda Python distribution, and I have started using the Anaconda (Conda) environment. I can use the standard conda install... command to put packages from the distribution into my environments, but to use anything outside (i.e. Flask-WTF, flask-sqlalchemy, and alembic) I need to use pip install in the active environment. However, when I look at the contents of the environment, either in the directory, or using conda list these pip installed packages don’t show up.

Using pip freeze and pip list just lists every package I’ve ever installed.

Is there a way to keep track of what is in each of my Anaconda envs (both pip and conda installed)?


回答 0

conda-env现在可以自动执行此操作(如果pip与conda一起安装)。

您可以使用用于迁移环境的导出工具来查看其工作原理:

conda env export -n <env-name> > environment.yml

该文件将列出conda软件包和pip软件包:

name: stats
channels:
  - javascript
dependencies:
  - python=3.4
  - bokeh=0.9.2
  - numpy=1.9.*
  - nodejs=0.10.*
  - flask
  - pip:
    - Flask-Testing

如果您希望继续导出环境,请移至environment.yml新的主机并运行:

conda env create -f path/to/environment.yml

conda-env now does this automatically (if pip was installed with conda).

You can see how this works by using the export tool used for migrating an environment:

conda env export -n <env-name> > environment.yml

The file will list both conda packages and pip packages:

name: stats
channels:
  - javascript
dependencies:
  - python=3.4
  - bokeh=0.9.2
  - numpy=1.9.*
  - nodejs=0.10.*
  - flask
  - pip:
    - Flask-Testing

If you’re looking to follow through with exporting the environment, move environment.yml to the new host machine and run:

conda env create -f path/to/environment.yml

回答 1

conda将仅跟踪其安装的软件包。并pip会为您提供使用pip安装程序本身安装的软件包,或setuptoolssetup.pyconda构建中使用的软件包生成的egg信息。因此,您基本上有三个选择。

  1. 你可以采取的联合conda listpip freeze和管理使用安装的软件包conda(在这个节目conda list用)conda包管理器,并确保安装与个位pip(即秀pip freeze,但不是在conda list)与pip

  2. 仅在和环境中安装pythonpip然后使用distribute打包和管理所有内容pip。(如果您使用的是Windows,那么这并不是一件容易的事…)

  3. 构建自己的conda软件包,并使用进行管理conda

我个人推荐第三个选项,因为它很容易构建conda软件包。在连续体的github帐户上有一个示例食谱的git存储库。但通常可以归结为:

 conda skeleton pypi PACKAGE
 conda build PACKAGE

要不就:

conda pipbuild PACKAGE

同样,一旦构建它们,您就可以将它们上传到https://binstar.org/并从那里安装。

然后,您将使用进行所有管理conda

conda will only keep track of the packages it installed. And pip will give you the packages that were either installed using the pip installer itself or they used setuptools in their setup.py so conda build generated the egg information. So you have basically three options.

  1. You can take the union of the conda list and pip freeze and manage packages that were installed using conda (that show in the conda list) with the conda package manager and the ones that are installed with pip (that show in pip freeze but not in conda list) with pip.

  2. Install in your environment only the python, pip and distribute packages and manage everything with pip. (This is not that trivial if you’re on Windows…)

  3. Build your own conda packages, and manage everything with conda.

I would personally recommend the third option since it’s very easy to build conda packages. There is a git repository of example recipes on the continuum’s github account. But it usually boils down to:

 conda skeleton pypi PACKAGE
 conda build PACKAGE

or just:

conda pipbuild PACKAGE

Also when you have built them once, you can upload them to https://binstar.org/ and just install from there.

Then you’ll have everything managed using conda.


回答 2

有一个conda(new-pypi-install)分支,它可以更好地与pip和PyPI集成。特别是conda列表还将显示pip安装的软件包,conda安装将首先尝试查找conda软件包,如果失败,将使用pip安装软件包。

该分支计划于本周晚些时候合并,以便conda 2.1版将更好地与conda进行点集成。

There is a branch of conda (new-pypi-install) that adds better integration with pip and PyPI. In particular conda list will also show pip installed packages and conda install will first try to find a conda package and failing that will use pip to install the package.

This branch is scheduled to be merged later this week so that version 2.1 of conda will have better pip-integration with conda.


回答 3

我遵循@Viktor Kerkez的回答,并取得了不同的成功。我发现有时候这个食谱

康达骨架pypi包装

康达构建包

看起来一切正常,但我无法成功导入PACKAGE。最近,我在Anaconda用户组上询问了此问题,并从@Travis Oliphant自己那里听说了使用conda构建和管理Anaconda附带的软件包的最佳方法。您可以在此处阅读此主题,但我将在下面描述该方法,以期使OP的问题的答案更加完整…

示例:我将使用conda 2.2.5在Windows上安装出色的prettyplotlib软件包

1a) conda build --build-recipe prettyplotlib

在构建的最后“测试”部分之前,您将看到构建消息看起来都不错。我看到了这个错误

文件“ C:\ Anaconda \ conda-bld \ test-tmp_dir \ run_test.py”,第23行导入None语法错误:无法分配为None测试失败:prettyplotlib-0.1.3-py27_0

1b)进入/ conda-recipes / prettyplotlib并编辑meta.yaml文件。当前,像在步骤1a中一样设置的软件包会导致yaml文件在该test部分中出错。例如,这是我的寻找方式prettyplotlib

test:   # Python imports   imports:
    - 
    - prettyplotlib
    - prettyplotlib

编辑此部分以删除-开头的空白行,并删除多余的prettyplotlib行。在撰写本文时,我发现我需要为使用conda安装的外部软件包编辑这样的大多数meta.yaml文件,这意味着有空白的导入行会导致错误以及给定软件包的冗余导入。

1c)从1a重新运行命令,这一次应该正确完成。在构建结束时,系统会询问您是否要将构建上传到binstar。我输入“否”,然后看到以下消息:

如果您想稍后将此包上传到binstar.org,请键入:

$ binstar上传C:\ Anaconda \ conda-bld \ win-64 \ prettyplotlib-0.1.3-py27_0.tar.bz2

该tar.bz2文件是您现在实际需要安装的构建。

2) conda install C:\Anaconda\conda-bld\win-64\prettyplotlib-0.1.3-py27_0.tar.bz2

按照这些步骤,我已经成功地使用conda安装了Anaconda随附的许多软件包。以前,我已经使用pip安装了其中的一些工具,因此pip uninstall PACKAGE在使用conda安装PACKAGE之前,我已经完成了安装。使用conda,我现在可以通过一种方法来管理(几乎)所有软件包,而无需将conda,pip,easy_install和python setup.py安装混合在一起。

对于上下文,我认为@Travis Oliphant的最新博客文章将对像我这样的人有所帮助,他们不喜欢使用健壮的Python包装的所有内容,但可以肯定当东西“起作用时”。康达似乎是前进的好方法…

I followed @Viktor Kerkez’s answer and have had mixed success. I found that sometimes this recipe of

conda skeleton pypi PACKAGE

conda build PACKAGE

would look like everything worked but I could not successfully import PACKAGE. Recently I asked about this on the Anaconda user group and heard from @Travis Oliphant himself on the best way to use conda to build and manage packages that do not ship with Anaconda. You can read this thread here, but I’ll describe the approach below to hopefully make the answers to the OP’s question more complete…

Example: I am going to install the excellent prettyplotlib package on Windows using conda 2.2.5.

1a) conda build --build-recipe prettyplotlib

You’ll see the build messages all look good until the final TEST section of the build. I saw this error

File “C:\Anaconda\conda-bld\test-tmp_dir\run_test.py”, line 23 import None SyntaxError: cannot assign to None TESTS FAILED: prettyplotlib-0.1.3-py27_0

1b) Go into /conda-recipes/prettyplotlib and edit the meta.yaml file. Presently, the packages being set up like in step 1a result in yaml files that have an error in the test section. For example, here is how mine looked for prettyplotlib

test:   # Python imports   imports:
    - 
    - prettyplotlib
    - prettyplotlib

Edit this section to remove the blank line preceded by the – and also remove the redundant prettyplotlib line. At the time of this writing I have found that I need to edit most meta.yaml files like this for external packages I am installing with conda, meaning that there is a blank import line causing the error along with a redundant import of the given package.

1c) Rerun the command from 1a, which should complete with out error this time. At the end of the build you’ll be asked if you want to upload the build to binstar. I entered No and then saw this message:

If you want to upload this package to binstar.org later, type:

$ binstar upload C:\Anaconda\conda-bld\win-64\prettyplotlib-0.1.3-py27_0.tar.bz2

That tar.bz2 file is the build that you now need to actually install.

2) conda install C:\Anaconda\conda-bld\win-64\prettyplotlib-0.1.3-py27_0.tar.bz2

Following these steps I have successfully used conda to install a number of packages that do not come with Anaconda. Previously, I had installed some of these using pip, so I did pip uninstall PACKAGE prior to installing PACKAGE with conda. Using conda, I can now manage (almost) all of my packages with a single approach rather than having a mix of stuff installed with conda, pip, easy_install, and python setup.py install.

For context, I think this recent blog post by @Travis Oliphant will be helpful for people like me who do not appreciate everything that goes into robust Python packaging but certainly appreciate when stuff “just works”. conda seems like a great way forward…


回答 4

这就是为什么我写Picky的原因:http : //picky.readthedocs.io/

这是一个python软件包,可跟踪在virtualenvs和conda envs中随pip或conda安装的软件包。

This is why I wrote Picky: http://picky.readthedocs.io/

It’s a python package that tracks packages installed with either pip or conda in either virtualenvs and conda envs.


回答 5

我认为这里缺少的是:

>pip install .

要使用setup.py安装本地软件包,它将安装一个对使用相同版本 python的所有 conda env 可见的软件包。注意我正在使用conda版本的pip!

例如,如果我使用的是python2.7,它将本地包放在此处:

/usr/local/anaconda/lib/python2.7/site-packages

如果以后再用python = 2.7(=默认值)创建一个新的conda env:

>conda create --name new

>source activate new

然后执行:

(new)>conda list    // empty - conda is not aware of any packages yet

但是,如果我这样做:

(new)>pip list      // the local package installed above is present

因此,在这种情况下,conda不了解pip包,但是python可以使用该包。

但是,如果我不是安装在本地包(再次使用PIP)后,我已经创建(激活)新康达ENV,现在畅达看到它:

(new)>conda list   // sees that the package is there and was installed by pip

因此,我认为conda和pip之间的交互存在一些问题-即,使用pip从一个conda env中安装本地软件包会使该软件包可用于同一python版本的所有其他conda env(但不能通过conda列表看到)。

I think what’s missing here is that when you do:

>pip install .

to install a local package with a setup.py, it installs a package that is visible to all the conda envs that use the same version of python. Note I am using the conda version of pip!

e.g., if I’m using python2.7 it puts the local package here:

/usr/local/anaconda/lib/python2.7/site-packages

If I then later create a new conda env with python=2.7 (= the default):

>conda create --name new

>source activate new

And then do:

(new)>conda list    // empty - conda is not aware of any packages yet

However, if I do:

(new)>pip list      // the local package installed above is present

So in this case, conda does not know about the pip package, but the package is available to python.

However, If I instead install the local package (again using pip) after I’ve created (and activated) the new conda env, now conda sees it:

(new)>conda list   // sees that the package is there and was installed by pip

So I think the interaction between conda and pip has some issues – ie, using pip to install a local package from within one conda env makes that package available (but not seen via conda list) to all other conda envs of the same python version.


回答 6

conda env export列出环境中的所有conda和pip软件包。conda-env必须安装在conda根目录(conda install -c conda conda-env)中。

编写environment.yml描述当前环境的文件:

conda env export > environment.yml

参考文献:

conda env export lists all conda and pip packages in an environment. conda-env must be installed in the conda root (conda install -c conda conda-env).

To write an environment.yml file describing the current environment:

conda env export > environment.yml

References:


回答 7

我通常会在“ pip”命令之前为要安装软件包的特定环境添加“ bin / pip”文件夹前缀。例如,如果要在环境py34中安装pymc3,则应使用以下命令:

~/anaconda/envs/py34/bin/pip install git+https://github.com/pymc-devs/pymc3 

基本上,您只需要找到环境“ bin / pip”文件夹的正确路径,并将其放在install命令之前即可。

I usually prefix the ‘bin/pip’ folder for the specific environment you want to install the package before the ‘pip’ command. For instance, if you would like to install pymc3 in the environment py34, you should use this command:

~/anaconda/envs/py34/bin/pip install git+https://github.com/pymc-devs/pymc3 

You basically just need to find the right path to your environment ‘bin/pip’ folder and put it before the install command.


回答 8

which pip显示了以下路径:

$ which pip
/home/kmario23/anaconda3/bin/pip

因此,pip install <package-name>使用以下命令导出列表时,无论我安装使用的任何软件包,都必须反映在软件包列表中:

$ conda list --export > conda_list.txt

但是,我没有。因此,我改用了其他一些人建议的以下命令:

# get environment name by
$ conda-env list

# get list of all installed packages by (conda, pip, etc.,)
$ conda-env export -n <my-environment-name> > all_packages.yml
# if you haven't created any specific env, then just use 'root'

现在,我可以看到all-packages.yml文件中的所有软件包。

My which pip shows the following path:

$ which pip
/home/kmario23/anaconda3/bin/pip

So, whatever package I install using pip install <package-name> will have to be reflected in the list of packages when the list is exported using:

$ conda list --export > conda_list.txt

But, I don’t. So, instead I used the following command as suggested by several others:

# get environment name by
$ conda-env list

# get list of all installed packages by (conda, pip, etc.,)
$ conda-env export -n <my-environment-name> > all_packages.yml
# if you haven't created any specific env, then just use 'root'

Now, I can see all the packages in my all-packages.yml file.


回答 9

您可以先在conda环境中安装以下给定命令开始:

conda install pip

然后安装环境中所需的所有pip软件包。

安装所有conda和pip软件包以导出环境后,请使用:

conda env export -n <env-name> > environment.yml

这将在文件夹中创建所需的文件

You can start by installing the below given command in the conda environment:

conda install pip

Followed by installing all pip packages you need in the environment.

After installing all the conda and pip packages to export the environment use:

conda env export -n <env-name> > environment.yml

This will create the required file in the folder


pyenv,virtualenv,anaconda有什么区别?

问题:pyenv,virtualenv,anaconda有什么区别?

我是一个尝试学习python的红宝石程序员。我很喜欢pyenv,因为它就像来自rbenv的复制和粘贴一样。Pyenv帮助在系统中拥有多个版本的python,并且无需隔离系统的敏感部分即可隔离python。

我想每个python安装都带有pip包。我仍然不明白的是,有很多好的python库建议使用此virtualenv和anaconda。我什至可以找到pyenv的virtualenv插件。

现在,我对这两个pyenv和virtualenv的目的感到困惑。更糟糕的是在pyenv内部有一个virtualenv插件。

我的问题是:

  • pyenv和virtualenv有什么区别?
  • 在pyenv和virtualenv中使用pip命令有什么区别吗?
  • pyenv virutalenv做什么?

您的示例解释将不胜感激。

I am a ruby programmer trying to learn python. I am pretty family with pyenv since it is like a copy and paste from rbenv. Pyenv helps allow to have more than one version of python in a system and also to isolate the python without touching sensitive part of system.

I suppose every python installation come with pip package. What I still don’t understand is, there are many good python libs out there that suggest to use this virtualenv and anaconda. I can even find virtualenv plugin for pyenv.

Now I am getting confused with the purpose of these two pyenv and virtualenv. worse inside pyenv there is a virtualenv plugin.

my questions are:

  • what is the difference between pyenv and virtualenv?
  • Is there any difference in using pip command inside both pyenv and virtualenv?
  • what does this pyenv virutalenv do?

your explanation with example will be highly appreciated.


回答 0

编辑:pip这里也值得一提,conda并且pip具有与该主题相关的异同

pip:Python软件包管理器。

  • 您可能将其pip视为ruby gem命令的python等效项
  • pip 默认情况下不包含在python中。
  • 您可以使用homebrew安装Python ,它将自动安装pip:brew install python
  • OSX的最终版本默认不包含pip。要将pip添加到Mac系统的python版本中,您可以sudo easy_install pip
  • 您可以使用PyPI查找和发布python软件包:Python软件包索引
  • requirements.txt文件与ruby相当 gemfile
  • 要创建需求文本文件, pip freeze > requirements.txt
  • 请注意,此时,我们已经在系统上安装了python,并创建了requirements.txt文件,该文件概述了系统上已安装的所有python软件包。

pyenv:Python版本管理器

  • 从文档 pyenv可以轻松在多个版本的Python之间切换。它简单,简单,遵循UNIX的一站式工具的传统,可以很好地完成一件事。该项目是从rbenv和ruby-build分叉的,并针对Python进行了修改。
  • 很多人 不愿使用python3
  • 如果您需要使用其他版本的python,则pyenv可以轻松进行管理。

virtualenv:Python环境管理器。

  • 从文档要解决的基本问题是依赖项和版本之一以及间接权限。假设您有一个需要使用LibFoo版本1的应用程序,但是另一个应用程序需要版本2。如果将所有内容都安装到/usr/lib/python2.7/site-packages(或平台的标准位置是什么)中,那么很容易在无意中升级不应升级的应用程序的情况下结束。
  • 要创建一个virtualenv,只需调用virtualenv ENV,其中ENV是用于放置新虚拟环境的目录。
  • 要初始化virtualenv,您需要source ENV/bin/activate。要停止使用,只需调用deactivate
  • 激活后virtualenv,您可以通过运行pip install -r项目requirements.txt文件来安装工作区的所有软件包要求。

Anaconda:程序包经理+环境经理+其他科学图书馆。

  • 来自文档Anaconda 4.2.0包括易于安装的Python(2.7.12、3.4.5和/或3.5.2),以及100多种经过预先构建和测试的科学和分析Python软件包的更新,其中包括NumPy,Pandas ,SciPy,Matplotlib和IPython,通过一个简单的工具即可提供620多个软件包conda install <packagename>
  • 作为Web开发人员,我没有使用Anaconda。包括所有程序包,容量约为3GB。
  • 有一个精简miniconda版,似乎比使用pip+ 更简单virtualenv,尽管我个人没有使用它的经验。
  • 尽管conda允许您安装软件包,但是这些软件包与PyPI软件包是分开的,因此,根据您需要安装的软件包的类型,您可能仍然需要额外使用pip。

也可以看看:

Edit: It’s worth mentioning pip here as well, as conda and pip have similarities and differences that are relevant to this topic.

pip: the Python Package Manager.

  • You might think of pip as the python equivalent of the ruby gem command
  • pip is not included with python by default.
  • You may install Python using homebrew, which will install pip automatically: brew install python
  • The final version of OSX did not include pip by default. To add pip to your mac system’s version of python, you can sudo easy_install pip
  • You can find and publish python packages using PyPI: The Python Package Index
  • The requirements.txt file is comparable to the ruby gemfile
  • To create a requirements text file, pip freeze > requirements.txt
  • Note, at this point, we have python installed on our system, and we have created a requirements.txt file that outlines all of the python packages that have been installed on your system.

pyenv: Python Version Manager

  • From the docs: pyenv lets you easily switch between multiple versions of Python. It’s simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. This project was forked from rbenv and ruby-build, and modified for Python.
  • Many folks hesitate to use python3.
  • If you need to use different versions of python, pyenv lets you manage this easily.

virtualenv: Python Environment Manager.

  • From the docs: The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.
  • To create a virtualenv, simply invoke virtualenv ENV, where ENV is is a directory to place the new virtual environment.
  • To initialize the virtualenv, you need to source ENV/bin/activate. To stop using, simply call deactivate.
  • Once you activate the virtualenv, you might install all of a workspace’s package requirements by running pip install -r against the project’s requirements.txt file.

Anaconda: Package Manager + Environment Manager + Additional Scientific Libraries.

  • From the docs: Anaconda 4.2.0 includes an easy installation of Python (2.7.12, 3.4.5, and/or 3.5.2) and updates of over 100 pre-built and tested scientific and analytic Python packages that include NumPy, Pandas, SciPy, Matplotlib, and IPython, with over 620 more packages available via a simple conda install <packagename>
  • As a web developer, I haven’t used Anaconda. It’s ~3GB including all the packages.
  • There is a slimmed down miniconda version, which seems like it could be a more simple option than using pip + virtualenv, although I don’t have experience using it personally.
  • While conda allows you to install packages, these packages are separate than PyPI packages, so you may still need to use pip additionally depending on the types of packages you need to install.

See also:


回答 1

简单类比:

  • pyenv〜rbenv
  • 点〜捆绑器
  • 虚拟环境〜rvm中的gemset。可以由捆绑器直接管理,而无需使用gemset。

由于我使用python3,因此我更喜欢名为venv的python3内置虚拟环境。venv简单易用。我建议您阅读其官方文档。该文档简短明了。

在ruby中,我们实际上并不需要虚拟环境,因为捆绑程序会处理它。虚拟环境和捆绑程序都很棒,但是它们的概念不同,但是它们试图解决相同的问题。

Simple analogy:

  • pyenv ~ rbenv
  • pip ~ bundler
  • virtual env ~ gemset in rvm. This can be managed by bundler directly without gemset.

Since I use python3 I prefer the python3 built-in virtual environment named venv. venv is simple and easy to use. I would recommend you to read its official docs. The doc is short and concise.

In ruby, we don’t really need a virtual environment because the bundler takes care of it. Both virtual env and bundler are great, however, they have different solutions to solve the same problem.


找不到满足要求的版本

问题:找不到满足要求的版本

我正在使用以下requirements.txt文件在Ubuntu 12.04中安装几个Python软件包:

numpy>=1.8.2,<2.0.0
matplotlib>=1.3.1,<2.0.0
scipy>=0.14.0,<1.0.0
astroML>=0.2,<1.0
scikit-learn>=0.14.1,<1.0.0
rpy2>=2.4.3,<3.0.0

和这两个命令:

$ pip install --download=/tmp -r requirements.txt
$ pip install --user --no-index --find-links=/tmp -r requirements.txt

(第一个下载软件包,第二个安装软件包)。

该过程经常因错误而停止:

  Could not find a version that satisfies the requirement <package> (from matplotlib<2.0.0,>=1.3.1->-r requirements.txt (line 2)) (from versions: )
No matching distribution found for <package> (from matplotlib<2.0.0,>=1.3.1->-r requirements.txt (line 2))

我用以下方法手动修复:

pip install --user <package>

然后pip install再次运行第二个命令。

但这仅适用于特定程序包。当我pip install再次运行第二个命令时,该过程现在停止,并抱怨另一个必需的程序包,我需要再次重复该过程,即:手动安装新的必需程序包(使用上面的命令),然后运行第二个pip install命令。

到目前为止,我不得不手动安装sixpytznose,现在它在抱怨需要mock

有没有办法告诉pip您自动安装所有需要的依赖项,所以我不必一个个手动地进行安装?

添加:这仅在Ubuntu 12.04 BTW中发生。在Ubuntu 14.04中,pip install应用于requirements.txt文件的命令可以正常工作。

I’m installing several Python packages in Ubuntu 12.04 using the following requirements.txt file:

numpy>=1.8.2,<2.0.0
matplotlib>=1.3.1,<2.0.0
scipy>=0.14.0,<1.0.0
astroML>=0.2,<1.0
scikit-learn>=0.14.1,<1.0.0
rpy2>=2.4.3,<3.0.0

and these two commands:

$ pip install --download=/tmp -r requirements.txt
$ pip install --user --no-index --find-links=/tmp -r requirements.txt

(the first one downloads the packages and the second one installs them).

The process is frequently stopped with the error:

  Could not find a version that satisfies the requirement <package> (from matplotlib<2.0.0,>=1.3.1->-r requirements.txt (line 2)) (from versions: )
No matching distribution found for <package> (from matplotlib<2.0.0,>=1.3.1->-r requirements.txt (line 2))

which I fix manually with:

pip install --user <package>

and then run the second pip install command again.

But that only works for that particular package. When I run the second pip install command again, the process is stopped now complaining about another required package and I need to repeat the process again, ie: install the new required package manually (with the command above) and then run the second pip install command.

So far I’ve had to manually install six, pytz, nose, and now it’s complaining about needing mock.

Is there a way to tell pip to automatically install all needed dependencies so I don’t have to do it manually one by one?

Add: This only happens in Ubuntu 12.04 BTW. In Ubuntu 14.04 the pip install commands applied on the requirements.txt file work without issues.


回答 0

仅当目录包含所有软件包时,此方法(在目录中具有所有依赖项,而不是从索引下载)才有效。因此,该目录应包含所有依赖项,还应包含这些依赖项所依赖的所有包(例如sixpytz等)。

因此,您应该手动将它们包括在其中requirements.txt(以便第一步明确下载它们),或者应该使用PyPI安装所有软件包,然后pip freeze > requirements.txt存储所需的所有软件包的列表。

This approach (having all dependencies in a directory and not downloading from an index) only works when the directory contains all packages. The directory should therefore contain all dependencies but also all packages that those dependencies depend on (e.g., six, pytz etc).

You should therefore manually include these in requirements.txt (so that the first step downloads them explicitly) or you should install all packages using PyPI and then pip freeze > requirements.txt to store the list of all packages needed.


回答 1

我已经安装了python3,但是/ usr / bin / python中的python仍然是旧的2.7版本

这个工作(<pkg>pyserial在我的情况):

python3 -m pip install <pkg>

I had installed python3 but my python in /usr/bin/python was still the old 2.7 version

This worked (<pkg> was pyserial in my case):

python3 -m pip install <pkg>

回答 2

经过2个小时的搜索,我找到了一种只需一行命令即可修复它的方法。您需要知道软件包的版本(只需搜索PACKAGE版本)。

命令:

python3 -m pip install --pre --upgrade PACKAGE==VERSION.VERSION.VERSION

After 2 hours of searching, I found a way to fix it with just one line of command. You need to know the version of the package (Just search up PACKAGE version).

Command:

python3 -m pip install --pre --upgrade PACKAGE==VERSION.VERSION.VERSION

回答 3

下面的命令为我工作-

python -m pip install flask

Below command worked for me –

python -m pip install flask

回答 4

尝试使用以下命令通过Powershell安装flask。

pip install --isolated Flask

这将允许安装以避免环境变量和用户配置。

Try installing flask through the powershell using the following command.

pip install --isolated Flask

This will allow installation to avoide environment variables and user configuration.


回答 5

并非总是如此,但是在某些情况下,该软件包已经存在。例如-getpass。它未在“点列表”中列出,但可以导入和使用:

如果我尝试通过pip install getpass进行安装,则会出现以下错误:“找不到满足要求getpass的版本”

Not always, but in some cases the package already exists. For example – getpass. It is not listed by “pip list” but it can be imported and used:

If I try to pip install getpass I get the following error: “Could not find a version that satisfies the requirement getpass”


回答 6

awscli在Windows 10上的anaconda(python 3.7)中安装时出现此错误。在进行故障排除时,我转到了答案https://stackoverflow.com/a/49991357/6862405,然后转到https://stackoverflow.com/a/54582701/6862405。最后发现,我需要安装库PyOpenSSLcryptographyenum34idnaipaddress。安装完这些(使用简单pip install命令)之后,我就可以安装了awscli

I got this error while installing awscli on Windows 10 in anaconda (python 3.7). While troubleshooting, I went to the answer https://stackoverflow.com/a/49991357/6862405 and then to https://stackoverflow.com/a/54582701/6862405. Finally found that I need to install the libraries PyOpenSSL, cryptography, enum34, idna and ipaddress. After installing these (using simply pip install command), I was able to install awscli.


回答 7

如果您在工作场所遇到此问题。这可能是您的解决方案。

pip install -U <package_name> --user --proxy=<your proxy>

If you facing this issue at the workplace. This might be the solution for you.

pip install -U <package_name> --user --proxy=<your proxy>

回答 8

只需遵循项目页面上列出的要求即可:https : //pypi.org/project/pgmagick/

Just follow the requirements listed on the project’s page: https://pypi.org/project/pgmagick/


回答 9

使用命令提示符,然后选择以管理员身份运行。

升级点子版本

要升级PIP,请键入以下命令,然后按Enter:

python.exe -m pip安装–upgrade pip

返回python路径C:\ Users \ Jack \ AppData \ Local \ Programs \ Python \ Python37 \ Scripts

类型jupyter笔记本

您将被重定向到http:// localhost:8888 / undefined / tree -Jupyter主页

希望能帮助到你 !!!!!!!!!!!

Use Command Prompt, and then select Run as administrator.

Upgrade the pip version

To upgrade PIP, type this command, and then press Enter:-

python.exe -m pip install –upgrade pip

Go Back to python path C:\Users\Jack\AppData\Local\Programs\Python\Python37\Scripts

Type jupyter notebook

You will be redirected to http://localhost:8888/undefined/tree – Jupyter Home Page

Hope it helps !!!!!!!!!!!


回答 10

可能有帮助

sudo pip install wheel == 0.29.0

might help

sudo pip install wheel==0.29.0


配置,以便可以从github进行pip安装

问题:配置,以便可以从github进行pip安装

我们想在github上使用pip将私有软件包安装到我们的生产服务器上。这个问题关系到github存储库中需要什么才能使安装成功。

假设使用以下命令行(可以正常身份验证并尝试安装):

pip install git+ssh://git@github.com/BlahCo/search/tree/prod_release_branch/ProductName

ProductName中需要驻留什么?是使用sdist选项运行setup.py之后,tar文件中通常包含的内容,还是实际的tar.gz文件或其他内容?

我在这里问是因为我尝试了几种变体,但无法使其正常工作。任何帮助表示赞赏。

We’d like to use pip with github to install private packages to our production servers. This question concerns what needs to be in the github repo in order for the install to be successful.

Assuming the following command line (which authenticates just fine and tries to install):

pip install git+ssh://git@github.com/BlahCo/search/tree/prod_release_branch/ProductName

What needs to reside in the ProductName? Is it the contents of what would normally be in the tar file after running setup.py with the sdist option, or is the actual tar.gz file, or something else?

I’m asking here because I’ve tried several variations and can’t make it work. Any help appreciated.


回答 0

您需要整个python软件包,其中包含一个setup.py文件。

名为的软件包为foo

foo # the installable package
├── foo
   ├── __init__.py
   └── bar.py
└── setup.py

然后像这样从github安装:

$ pip install git+https://github.com/myuser/foo.git@v123
or
$ pip install git+https://github.com/myuser/foo.git@newbranch

有关更多信息,访问https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support

You need the whole python package, with a setup.py file in it.

A package named foo would be:

foo # the installable package
├── foo
│   ├── __init__.py
│   └── bar.py
└── setup.py

And install from github like:

$ pip install git+ssh://git@github.com/myuser/foo.git
or
$ pip install git+https://github.com/myuser/foo.git@v123
or
$ pip install git+https://github.com/myuser/foo.git@newbranch

More info at https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support


回答 1

我不得不从github repo安装时遇到了类似的问题,但又不想安装git等。

最简单的方法是使用软件包的zip存档。添加/zipball/master到仓库URL:

    $ pip install https://github.com/hmarr/django-debug-toolbar-mongo/zipball/master
Downloading/unpacking https://github.com/hmarr/django-debug-toolbar-mongo/zipball/master
  Downloading master
  Running setup.py egg_info for package from https://github.com/hmarr/django-debug-toolbar-mongo/zipball/master
Installing collected packages: django-debug-toolbar-mongo
  Running setup.py install for django-debug-toolbar-mongo
Successfully installed django-debug-toolbar-mongo
Cleaning up...

这样,您将使ip可以与github源存储库一起使用。

I had similar issue when I had to install from github repo, but did not want to install git , etc.

The simple way to do it is using zip archive of the package. Add /zipball/master to the repo URL:

    $ pip install https://github.com/hmarr/django-debug-toolbar-mongo/zipball/master
Downloading/unpacking https://github.com/hmarr/django-debug-toolbar-mongo/zipball/master
  Downloading master
  Running setup.py egg_info for package from https://github.com/hmarr/django-debug-toolbar-mongo/zipball/master
Installing collected packages: django-debug-toolbar-mongo
  Running setup.py install for django-debug-toolbar-mongo
Successfully installed django-debug-toolbar-mongo
Cleaning up...

This way you will make pip work with github source repositories.


回答 2

如果您要使用requirements.txt文件,则需要使用git类似下面的条目的名称匿名获取您的中的master分支requirements.txt

对于常规安装:

git+git://github.com/celery/django-celery.git

对于“ 可编辑 ”安装:

-e git://github.com/celery/django-celery.git#egg=django-celery

可编辑模式将项目的源代码下载到./src当前目录中。它允许pip freeze输出包的正确github位置。

If you want to use requirements.txt file, you will need git and something like the entry below to anonymously fetch the master branch in your requirements.txt.

For regular install:

git+git://github.com/celery/django-celery.git

For “editable” install:

-e git://github.com/celery/django-celery.git#egg=django-celery

Editable mode downloads the project’s source code into ./src in the current directory. It allows pip freeze to output the correct github location of the package.


回答 3

克隆目标存储库的方式与克隆任何其他项目相同:

git clone git@github.com:myuser/foo.git

然后以开发模式安装它:

cd foo
pip install -e .

您可以更改不需要的任何内容,使用foo包的每个代码都将使用修改后的代码。

该解决方案有两个好处:

  1. 您可以在主项目目录中安装软件包。
  2. 软件包包括.git目录,因此它是常规的Git存储库。您可以立即将叉子推入。

Clone target repository same way like you cloning any other project:

git clone git@github.com:myuser/foo.git

Then install it in develop mode:

cd foo
pip install -e .

You can change anything you wan’t and every code using foo package will use modified code.

There 2 benefits ot this solution:

  1. You can install package in your home projects directory.
  2. Package includes .git dir, so it’s regular Git repository. You can push to your fork right away.

回答 4

您可以在Colab中尝试这种方式

!git clone https://github.com/UKPLab/sentence-transformers.git
!pip install -e /content/sentence-transformers
import sentence_transformers

you can try this way in Colab

!git clone https://github.com/UKPLab/sentence-transformers.git
!pip install -e /content/sentence-transformers
import sentence_transformers

如何安装没有root访问权限的python模块?

问题:如何安装没有root访问权限的python模块?

我正在上一些大学类,并且得到了“教学帐户”,这是我可以用来从事工作的学校帐户。我想在那台机器上运行需要大量计算的Numpy,matplotlib,scipy代码,但是由于我不是系统管理员,所以无法安装这些模块。

我该如何安装?

I’m taking some university classes and have been given an ‘instructional account’, which is a school account I can ssh into to do work. I want to run my computationally intensive Numpy, matplotlib, scipy code on that machine, but I cannot install these modules because I am not a system administrator.

How can I do the installation?


回答 0

在大多数情况下,最佳解决方案是通过运行以下命令来依赖所谓的“用户站点”位置(有关详细信息,请参阅PEP):

pip install --user package_name

以下是我原始答案提供的一种“更手动”的方法,如果上述解决方案适合您,则无需阅读它。


使用easy_install,您可以执行以下操作:

easy_install --prefix=$HOME/local package_name

它将安装到

$HOME/local/lib/pythonX.Y/site-packages

(“本地”文件夹是许多人常用的典型名称,但是您当然可以指定您有权写入的任何文件夹)。

您将需要手动创建

$HOME/local/lib/pythonX.Y/site-packages

并将其添加到您的PYTHONPATH环境变量中(否则easy_install会抱怨-btw运行上面的命令一次,以找到XY的正确值)。

如果您没有使用easy_install,请寻找一个前缀选项,大多数安装脚本都允许您指定一个。

使用pip可以使用:

pip install --install-option="--prefix=$HOME/local" package_name

In most situations the best solution is to rely on the so-called “user site” location (see the PEP for details) by running:

pip install --user package_name

Below is a more “manual” way from my original answer, you do not need to read it if the above solution works for you.


With easy_install you can do:

easy_install --prefix=$HOME/local package_name

which will install into

$HOME/local/lib/pythonX.Y/site-packages

(the ‘local’ folder is a typical name many people use, but of course you may specify any folder you have permissions to write into).

You will need to manually create

$HOME/local/lib/pythonX.Y/site-packages

and add it to your PYTHONPATH environment variable (otherwise easy_install will complain — btw run the command above once to find the correct value for X.Y).

If you are not using easy_install, look for a prefix option, most install scripts let you specify one.

With pip you can use:

pip install --install-option="--prefix=$HOME/local" package_name

回答 1

没有访问权限或安装权限easy_install

然后,您可以创建一个python virtualenvhttps://pypi.python.org/pypi/virtualenv)并从该虚拟环境中安装该软件包。

在shell中执行4个命令就足够了(为XXX插入当前版本,如16.1.0):

$ curl --location --output virtualenv-X.X.X.tar.gz https://github.com/pypa/virtualenv/tarball/X.X.X
$ tar xvfz virtualenv-X.X.X.tar.gz
$ python pypa-virtualenv-YYYYYY/src/virtualenv.py my_new_env
$ . my_new_env/bin/activate
(my_new_env)$ pip install package_name

来源和更多信息:https : //virtualenv.pypa.io/en/latest/installation/

No permissions to access nor install easy_install?

Then, you can create a python virtualenv (https://pypi.python.org/pypi/virtualenv) and install the package from this virtual environment.

Executing 4 commands in the shell will be enough (insert current release like 16.1.0 for X.X.X):

$ curl --location --output virtualenv-X.X.X.tar.gz https://github.com/pypa/virtualenv/tarball/X.X.X
$ tar xvfz virtualenv-X.X.X.tar.gz
$ python pypa-virtualenv-YYYYYY/src/virtualenv.py my_new_env
$ . my_new_env/bin/activate
(my_new_env)$ pip install package_name

Source and more info: https://virtualenv.pypa.io/en/latest/installation/


回答 2

您可以运行easy_install将Python软件包安装在主目录中,即使没有root访问权限。有一种使用site.USER_BASE的标准方法,默认为$ HOME / .local或$ HOME / Library / Python / 2.7 / bin之类,默认情况下包含在PYTHONPATH中

为此,请在主目录中创建一个.pydistutils.cfg:

cat > $HOME/.pydistutils.cfg <<EOF
[install]
user=1
EOF

现在,您可以在没有root特权的情况下运行easy_install:

easy_install boto

另外,这还可以让您在没有root访问权限的情况下运行pip:

pip install boto

这对我有用。

源自Wesley Tanaka的博客:http : //wtanaka.com/node/8095

You can run easy_install to install python packages in your home directory even without root access. There’s a standard way to do this using site.USER_BASE which defaults to something like $HOME/.local or $HOME/Library/Python/2.7/bin and is included by default on the PYTHONPATH

To do this, create a .pydistutils.cfg in your home directory:

cat > $HOME/.pydistutils.cfg <<EOF
[install]
user=1
EOF

Now you can run easy_install without root privileges:

easy_install boto

Alternatively, this also lets you run pip without root access:

pip install boto

This works for me.

Source from Wesley Tanaka’s blog : http://wtanaka.com/node/8095


回答 3

如果必须使用distutils setup.py脚本,则可以使用一些命令行选项来强制安装目标。请参阅http://docs.python.org/install/index.html#alternate-installation。如果重复出现此问题,则可以设置distutils配置文件,请参阅http://docs.python.org/install/index.html#inst-config-files

设置PYTHONPATH变量在tihos post中有描述。

If you have to use a distutils setup.py script, there are some commandline options for forcing an installation destination. See http://docs.python.org/install/index.html#alternate-installation. If this problem repeats, you can setup a distutils configuration file, see http://docs.python.org/install/index.html#inst-config-files.

Setting the PYTHONPATH variable is described in tihos post.


回答 4

重要问题。我使用的服务器(Ubuntu 12.04)拥有easy_install3但没有pip3。这是我将Pip和其他软件包安装到主文件夹的方式

  1. 要求管理员安装Ubuntu软件包 python3-setuptools

  2. 已安装点

像这样:

 easy_install3 --prefix=$HOME/.local pip
 mkdir -p $HOME/.local/lib/python3.2/site-packages
 easy_install3 --prefix=$HOME/.local pip
  1. 添加Pip(以及其他Python应用程序到路径)

像这样:

PATH="$HOME/.local/bin:$PATH"
echo PATH="$HOME/.local/bin:$PATH" > $HOME/.profile
  1. 安装Python包

像这样

pip3 install --user httpie

# test httpie package
http httpbin.org

Important question. The server I use (Ubuntu 12.04) had easy_install3 but not pip3. This is how I installed Pip and then other packages to my home folder

  1. Asked admin to install Ubuntu package python3-setuptools

  2. Installed pip

Like this:

 easy_install3 --prefix=$HOME/.local pip
 mkdir -p $HOME/.local/lib/python3.2/site-packages
 easy_install3 --prefix=$HOME/.local pip
  1. Add Pip (and other Python apps to path)

Like this:

PATH="$HOME/.local/bin:$PATH"
echo PATH="$HOME/.local/bin:$PATH" > $HOME/.profile
  1. Install Python package

like this

pip3 install --user httpie

# test httpie package
http httpbin.org

回答 5

我使用JuJu,它基本上允许在$ HOME / .juju目录中有一个非常小的linux发行版(仅包含软件包管理器)。

它允许通过proot访问位于主目录中的自定义系统,因此,您可以安装没有root特权的任何软件包。它可以在所有主要的Linux发行版上正常运行,唯一的限制是JuJu可以在最低建议版本2.6.32的linux内核上运行。

例如,在安装JuJu以安装pip之后,只需键入以下内容:

$>juju -f
(juju)$> pacman -S python-pip
(juju)> pip

I use JuJu which basically allows to have a really tiny linux distribution (containing just the package manager) inside your $HOME/.juju directory.

It allows to have your custom system inside the home directory accessible via proot and, therefore, you can install any packages without root privileges. It will run properly to all the major linux distributions, the only limitation is that JuJu can run on linux kernel with minimum reccomended version 2.6.32.

For instance, after installed JuJu to install pip just type the following:

$>juju -f
(juju)$> pacman -S python-pip
(juju)> pip

回答 6

最好和最简单的方法是以下命令:

pip install --user package_name

http://www.lleess.com/2013/05/how-to-install-python-modules-without.html#.WQrgubyGOnc

The best and easiest way is this command:

pip install --user package_name

http://www.lleess.com/2013/05/how-to-install-python-modules-without.html#.WQrgubyGOnc


回答 7

在本地安装virtualenv(说明源):

重要提示:插入XXX的当前版本(如16.1.0)。 检查提取文件的名称,并将其插入YYYYY

$ curl -L -o virtualenv.tar.gz https://github.com/pypa/virtualenv/tarball/X.X.X
$ tar xfz virtualenv.tar.gz
$ python pypa-virtualenv-YYYYY/src/virtualenv.py env

使用安装任何软件包之前,您需要使用source虚拟Python环境env

$ source env/bin/activate

要安装新的python包(例如numpy),请使用:

(env)$ pip install <package>

Install virtualenv locally (source of instructions):

Important: Insert the current release (like 16.1.0) for X.X.X.
Check the name of the extracted file and insert it for YYYYY.

$ curl -L -o virtualenv.tar.gz https://github.com/pypa/virtualenv/tarball/X.X.X
$ tar xfz virtualenv.tar.gz
$ python pypa-virtualenv-YYYYY/src/virtualenv.py env

Before you can use or install any package you need to source your virtual Python environment env:

$ source env/bin/activate

To install new python packages (like numpy), use:

(env)$ pip install <package>