标签归档:pip

如何使用Python的pip下载并保留打包的压缩文件?

问题:如何使用Python的pip下载并保留打包的压缩文件?

如果我想使用pip命令下载软件包(及其依赖项),但保留所有已下载的压缩文件(例如django-socialregistration.tar.gz)-有没有办法做到这一点?

我尝试了各种命令行选项,但是它似乎总是解压缩并删除 zipfile-或获取zipfile,但适用于原始程序包,而不适用于依赖项。

If I want to use the pip command to download a package (and its dependencies), but keep all of the zipped files that get downloaded (say, django-socialregistration.tar.gz) – is there a way to do that?

I’ve tried various command-line options, but it always seems to unpack and delete the zipfile – or it gets the zipfile, but only for the original package, not the dependencies.


回答 0

pip install --download不推荐使用。从8.0.0版本开始,您应该使用以下pip download命令:

 pip download <package-name>

pip install --download is deprecated. Starting from version 8.0.0 you should use pip download command:

 pip download <package-name>

回答 1

--download-cache选项应执行您想要的操作:

pip install --download-cache="/pth/to/downloaded/files" package

但是,当我对此进行测试时,主程序包可以正常下载,保存和安装,但是依赖项以其完整的URL路径作为名称保存-有点烦人,但是所有tar.gz文件都在那里。

--download选件下载主软件包及其依赖项,并且不安装其中的任何一个。(请注意版本1.1之前的版本--download选项下载依赖项。)

pip install package --download="/pth/to/downloaded/files"

pip文档概述了--download用于快速和本地安装的方法

The --download-cache option should do what you want:

pip install --download-cache="/pth/to/downloaded/files" package

However, when I tested this, the main package downloaded, saved and installed ok, but the the dependencies were saved with their full url path as the name – a bit annoying, but all the tar.gz files were there.

The --download option downloads the main package and its dependencies and does not install any of them. (Note that prior to version 1.1 the --download option did not download dependencies.)

pip install package --download="/pth/to/downloaded/files"

The pip documentation outlines using --download for fast & local installs.


回答 2

我总是这样做来下载软件包:

pip install --download /path/to/download/to_packagename

要么

pip install --download=/path/to/packages/downloaded -r requirements.txt

当我想安装所有我刚刚下载的库时,我这样做:

pip install --no-index --find-links="/path/to/downloaded/dependencies" packagename

要么

pip install --no-index --find-links="/path/to/downloaded/packages" -r requirements.txt


更新资料

另外,要在一个系统上安装所有软件包,可以将它们全部导出到requirement.txt将用于在另一个系统上安装的软件包,我们这样做:

pip freeze > requirement.txt

然后,requirement.txt可以像上面一样使用进行下载,或通过以下步骤进行安装requirement.txt

pip install -r requirement.txt

参考:pip安装程序

I always do this to download the packages:

pip install --download /path/to/download/to_packagename

OR

pip install --download=/path/to/packages/downloaded -r requirements.txt

And when I want to install all of those libraries I just downloaded, I do this:

pip install --no-index --find-links="/path/to/downloaded/dependencies" packagename

OR

pip install --no-index --find-links="/path/to/downloaded/packages" -r requirements.txt


Update

Also, to get all the packages installed on one system, you can export them all to requirement.txt that will be used to intall them on another system, we do this:

pip freeze > requirement.txt

Then, the requirement.txt can be used as above for download, or do this to install them from requirement.txt:

pip install -r requirement.txt

REFERENCE: pip installer


回答 3

在版本7.1.2中,pip使用以下命令下载包的轮子(如果有):

pip install package -d /path/to/downloaded/file

以下下载源分发:

pip install package -d /path/to/downloaded/file --no-binary :all:

如果pip知道依赖项(例如,如果pip show package列出了依赖项),它们也会下载依赖项。


更新资料

正如指出的安东Khodakpip download命令已经从版本8在上述例子中优选的,这意味着/path/to/downloaded/file与选项给出需要-d,所以更换installdownload作品。

In version 7.1.2 pip downloads the wheel of a package (if available) with the following:

pip install package -d /path/to/downloaded/file

The following downloads a source distribution:

pip install package -d /path/to/downloaded/file --no-binary :all:

These download the dependencies as well, if pip is aware of them (e.g., if pip show package lists them).


Update

As noted by Anton Khodak, pip download command is preferred since version 8. In the above examples this means that /path/to/downloaded/file needs to be given with option -d, so replacing install with download works.


回答 4

使用pip download <package1 package2 package n>下载所有的软件包,包括依赖性

使用pip install --no-index --find-links . <package1 package2 package n>安装所有的软件包,包括依赖性。它从中获取所有文件CWD。它不会下载任何东西

Use pip download <package1 package2 package n> to download all the packages including dependencies

Use pip install --no-index --find-links . <package1 package2 package n> to install all the packages including dependencies. It gets all the files from CWD. It will not download anything


回答 5

pip wheel 是您应该考虑的另一种选择:

pip wheel mypackage -w .\outputdir

它将把软件包及其依赖项下载到一个目录(默认为当前工作目录),但是它将执行将所有源软件包转换为wheel的附加步骤。

它方便地支持需求文件:

pip wheel -r requirements.txt -w .\outputdir

--no-deps如果只需要特别要求的软件包,请添加参数:

pip wheel mypackage -w .\outputdir --no-deps

pip wheel is another option you should consider:

pip wheel mypackage -w .\outputdir

It will download packages and their dependencies to a directory (current working directory by default), but it performs the additional step of converting any source packages to wheels.

It conveniently supports requirements files:

pip wheel -r requirements.txt -w .\outputdir

Add the --no-deps argument if you only want the specifically requested packages:

pip wheel mypackage -w .\outputdir --no-deps

回答 6

我希望(RHEL)- pip download package==version --no-deps --no-binary=:all:

I would prefer (RHEL) – pip download package==version --no-deps --no-binary=:all:


回答 7

离线安装python软件包

对于窗户用户:

要将其下载到文件中,请打开您的cmd并遵循以下步骤:

cd <*the file-path where you want to save it*>

pip download <*package name*>

软件包和依赖项将下载到当前工作目录中。

安装当前工作目录:

将您下载的文件夹设置为cwd,然后执行以下操作:

pip install <*the package name which is downloded as .whl*> --no-index --find-links <*the file locaation where the files are downloaded*>

这将在该位置搜索依赖项。

installing python packages offline

For windows users:

To download into a file open your cmd and folow this:

cd <*the file-path where you want to save it*>

pip download <*package name*>

the package and the dependencies will be downloaded in the current working directory.

To install from the current working directory:

set your folder where you downloaded as the cwd then follow these:

pip install <*the package name which is downloded as .whl*> --no-index --find-links <*the file locaation where the files are downloaded*>

this will search for dependencies in that location.


如何查找Python包的依赖项

问题:如何查找Python包的依赖项

如何以编程方式获取Python软件包的依赖关系列表?

标准setup.py已记录了这些内容,但是我找不到 Python或命令行访问它的简便方法。

理想情况下,我正在寻找类似的东西:

$ pip install somepackage --only-list-deps
kombu>=3.0.8
billiard>=3.3.0.13
boto>=2.26

要么:

>>> import package_deps
>>> package = package_deps.find('somepackage')
>>> print package.dependencies
['kombu>=3.0.8', 'billiard>=3.3.0.13', 'boto>=2.26']

注意,我不是在谈论导入包和查找所有引用的模块。尽管这可能找到大多数相关软件包,但无法找到所需的最低版本号。那只存储在setup.py中。

How can you programmatically get a Python package’s list of dependencies?

The standard setup.py has these documented, but I can’t find an easy way to access it from either Python or the command line.

Ideally, I’m looking for something like:

$ pip install somepackage --only-list-deps
kombu>=3.0.8
billiard>=3.3.0.13
boto>=2.26

or:

>>> import package_deps
>>> package = package_deps.find('somepackage')
>>> print package.dependencies
['kombu>=3.0.8', 'billiard>=3.3.0.13', 'boto>=2.26']

Note, I’m not talking about importing a package and finding all referenced modules. While this might find most of the dependent packages, it wouldn’t be able to find the minimum version number required. That’s only stored in the setup.py.


回答 0

除了pip show [package name]命令,还有pipdeptree

做就是了

$ pip install pipdeptree

然后跑

$ pipdeptree

它会以树形形式显示您的依赖关系,例如,

flake8==2.5.0
  - mccabe [required: >=0.2.1,<0.4, installed: 0.3.1]
  - pep8 [required: !=1.6.0,>=1.5.7,!=1.6.1,!=1.6.2, installed: 1.5.7]
  - pyflakes [required: >=0.8.1,<1.1, installed: 1.0.0]
ipdb==0.8
  - ipython [required: >=0.10, installed: 1.1.0]

该项目位于https://github.com/naiquevin/pipdeptree,您还将在其中找到使用信息。

In addition to the pip show [package name] command, there is pipdeptree.

Just do

$ pip install pipdeptree

then run

$ pipdeptree

and it will show you your dependencies in a tree form, e.g.,

flake8==2.5.0
  - mccabe [required: >=0.2.1,<0.4, installed: 0.3.1]
  - pep8 [required: !=1.6.0,>=1.5.7,!=1.6.1,!=1.6.2, installed: 1.5.7]
  - pyflakes [required: >=0.8.1,<1.1, installed: 1.0.0]
ipdb==0.8
  - ipython [required: >=0.10, installed: 1.1.0]

The project is located at https://github.com/naiquevin/pipdeptree, where you will also find usage information.


回答 1

尝试在中使用show命令pip,例如:

$ pip show tornado
---
Name: tornado
Version: 4.1
Location: *****
Requires: certifi, backports.ssl-match-hostname

更新(检索指定版本的部门):

from pip._vendor import pkg_resources


_package_name = 'somepackage'
_package = pkg_resources.working_set.by_key[_package_name]

print([str(r) for r in _package.requires()])  # retrieve deps from setup.py

Output: ['kombu>=3.0.8', 
         'billiard>=3.3.0.13', 
         'boto>=2.26']

Try to use show command in pip, for example:

$ pip show tornado
---
Name: tornado
Version: 4.1
Location: *****
Requires: certifi, backports.ssl-match-hostname

Update (retrieve deps with specified version):

from pip._vendor import pkg_resources


_package_name = 'somepackage'
_package = pkg_resources.working_set.by_key[_package_name]

print([str(r) for r in _package.requires()])  # retrieve deps from setup.py

Output: ['kombu>=3.0.8', 
         'billiard>=3.3.0.13', 
         'boto>=2.26']

回答 2

这里有很多答案,表明将pip导入以便在程序中使用。pip文档强烈建议不要使用pip

实际上pkg_resources,您可以pkg_resources直接导入并使用相同的逻辑(而不是通过pip导入进行访问)(这实际上是pip docs中链接的建议解决方案之一,适用于希望以编程方式查看程序包元信息的任何人)。

import pkg_resources

_package_name = 'yourpackagename'

def get_dependencies_with_semver_string():
    package = pkg_resources.working_set.by_key[_package_name]
    return [str(r) for r in package.requires()]

如果您在查找确切的软件包名称时遇到麻烦,可以WorkingSet通过pkg_resources.working_setImplements 返回的实例,__iter__以便将它们全部打印出来,并希望在其中找到它们:)

import pkg_resources

def print_all_in_working_set():
    ws = pkg_resources.working_set
    for package_name in ws:
        print(ws)

这适用于python 2和python 3(尽管您需要调整python2的打印语句)

Quite a few answers here show pip being imported for use in programs. The documentation for pip strongly advises against this usage of pip.

Instead of accessing pkg_resources via the pip import, you can actually just import pkg_resources directly and use the same logic (which is actually one of the suggested solutions in the pip docs linked for anyone wanting to see package meta information programmatically) .

import pkg_resources

_package_name = 'yourpackagename'

def get_dependencies_with_semver_string():
    package = pkg_resources.working_set.by_key[_package_name]
    return [str(r) for r in package.requires()]

If you’re having some trouble finding out exactly what your package name is, the WorkingSet instance returned by pkg_resources.working_set implements __iter__ so you can print all of them and hopefully spot yours in there :)

i.e.

import pkg_resources

def print_all_in_working_set():
    ws = pkg_resources.working_set
    for package_name in ws:
        print(ws)

This works with both python 2 and 3 (though you’ll need to adjust the print statements for python2)


回答 3

(这是一个传统的答案,应该避免使用现代PIP版本,并在此引用旧PIP版本)。Alex的回答很好(+1)。在python中:

pip._vendor.pkg_resources.working_set.by_key['twisted'].requires()

应该返回类似

[Requirement.parse('zope.interface>=3.6.0')]

包装的名称在哪里是扭曲的,您可以在字典中找到它:

pip._vendor.pkg_resources.WorkingSet().entry_keys

列出所有:

dict = pip._vendor.pkg_resources.WorkingSet().entry_keys
for key in dict:
    for name in dict[key]:
        req =pip._vendor.pkg_resources.working_set.by_key[name].requires()
        print('pkg {} from {} requires {}'.format(name,
                                                  key,
                                                  req))

应该给你这样的清单:

pkg pyobjc-framework-syncservices from /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC requires [Requirement.parse('pyobjc-core>=2.5.1'), Requirement.parse('pyobjc-framework-Cocoa>=2.5.1'), Requirement.parse('pyobjc-framework-CoreData>=2.5.1')]

(THIS IS A LEGACY ANSWER AND SHOULD BE AVOIDED FOR MODERN PIP VERSIONS AND LEFT HERE FOR REFERENCE TO OLDER PIP VERSIONS ) Alex’s answer is good (+1). In python:

pip._vendor.pkg_resources.working_set.by_key['twisted'].requires()

should return something like

[Requirement.parse('zope.interface>=3.6.0')]

where twisted is the name of the package, which you can find in the dictionary :

pip._vendor.pkg_resources.WorkingSet().entry_keys

to list them all:

dict = pip._vendor.pkg_resources.WorkingSet().entry_keys
for key in dict:
    for name in dict[key]:
        req =pip._vendor.pkg_resources.working_set.by_key[name].requires()
        print('pkg {} from {} requires {}'.format(name,
                                                  key,
                                                  req))

should give you lists like this:

pkg pyobjc-framework-syncservices from /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC requires [Requirement.parse('pyobjc-core>=2.5.1'), Requirement.parse('pyobjc-framework-Cocoa>=2.5.1'), Requirement.parse('pyobjc-framework-CoreData>=2.5.1')]

回答 4

使用https://libraries.io/。在使用pip安装之前,这是探索依赖关系的好地方。

例如。输入google-cloud-storage并搜索,然后您可以找到该库的页面(https://libraries.io/rubygems/google-cloud-storage)。从“发布”中选择要浏览其依赖关系的版本(默认为最新版本),在“依赖关系”下,您可以找到依赖关系列表及其受支持的版本。

Use https://libraries.io/. It is a good place to explore dependencies before installing using pip.

Eg. Type google-cloud-storage and search, then you can find the page for the library (https://libraries.io/rubygems/google-cloud-storage). Select the version for which you want to explore the dependencies from the ‘Releases’ (default is the latest), Under ‘Dependencies’ you can find the dependency list and their supported versions.


回答 5

根据python中的这篇文章尝试以下操作:

import pip 
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
     for i in installed_packages]) 
print(installed_packages_list)

它将显示为:

['behave==1.2.4', 'enum34==1.0', 'flask==0.10.1', 'itsdangerous==0.24', 
 'jinja2==2.7.2', 'jsonschema==2.3.0', 'markupsafe==0.23', 'nose==1.3.3', 
 'parse-type==0.3.4', 'parse==1.6.4', 'prettytable==0.7.2', 'requests==2.3.0',
 'six==1.6.1', 'vioozer-metadata==0.1', 'vioozer-users-server==0.1', 
 'werkzeug==0.9.4']

Try this according to this article in python:

import pip 
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
     for i in installed_packages]) 
print(installed_packages_list)

It will show like:

['behave==1.2.4', 'enum34==1.0', 'flask==0.10.1', 'itsdangerous==0.24', 
 'jinja2==2.7.2', 'jsonschema==2.3.0', 'markupsafe==0.23', 'nose==1.3.3', 
 'parse-type==0.3.4', 'parse==1.6.4', 'prettytable==0.7.2', 'requests==2.3.0',
 'six==1.6.1', 'vioozer-metadata==0.1', 'vioozer-users-server==0.1', 
 'werkzeug==0.9.4']

结合conda environment.yml和pip requirements.txt

问题:结合conda environment.yml和pip requirements.txt

我在conda环境下工作,还需要一些pip包,例如〜gohlke的预编译轮。

目前,我有两个文件: environment.yml对于conda与:

# run: conda env create --file environment.yml
name: test-env
dependencies:
- python>=3.5
- anaconda

requirements.txt用于PIP可以上述环境康达激活后使用:

# run: pip install -i requirements.txt
docx
gooey
http://www.lfd.uci.edu/~gohlke/pythonlibs/bofhrmxk/opencv_python-3.1.0-cp35-none-win_amd64.whl

是否可以将它们合并到一个文件中(用于conda)?

I work with conda environments and need some pip packages as well, e.g. pre-compiled wheels from ~gohlke.

At the moment I have two files: environment.yml for conda with:

# run: conda env create --file environment.yml
name: test-env
dependencies:
- python>=3.5
- anaconda

and requirements.txt for pip which can be used after activating above conda environment:

# run: pip install -i requirements.txt
docx
gooey
http://www.lfd.uci.edu/~gohlke/pythonlibs/bofhrmxk/opencv_python-3.1.0-cp35-none-win_amd64.whl

Is there a possibility to combine them in one file (for conda)?


回答 0

点依赖可以包含在这样的environment.yml文件中(docs):

# run: conda env create --file environment.yml
name: test-env
dependencies:
- python>=3.5
- anaconda
- pip
- pip:
  # works for regular pip packages
  - docx
  - gooey
  # and for wheels
  - http://www.lfd.uci.edu/~gohlke/pythonlibs/bofhrmxk/opencv_python-3.1.0-cp35-none-win_amd64.whl

它也适用.whl于同一目录中的文件(请参阅Dengar的answer)以及常见的pip包。

Pip dependencies can be included in the environment.yml file like this (docs):

# run: conda env create --file environment.yml
name: test-env
dependencies:
- python>=3.5
- anaconda
- pip
- pip:
  # works for regular pip packages
  - docx
  - gooey
  # and for wheels
  - http://www.lfd.uci.edu/~gohlke/pythonlibs/bofhrmxk/opencv_python-3.1.0-cp35-none-win_amd64.whl

It also works for .whl files in the same directory (see Dengar’s answer) as well as with common pip packages.


回答 1

也可以requirements.txt直接在YAML中使用。例如,

name: test-env
dependencies:
  - python>=3.5
  - anaconda
  - pip
  - pip:
    - -r file:requirements.txt

基本上,您可以使用的任何选项都可以pip install在YAML中运行。有关其他功能的展示,请参见高级点子示例

One can also use the requirements.txt directly in the YAML. For example,

name: test-env
dependencies:
  - python>=3.5
  - anaconda
  - pip
  - pip:
    - -r file:requirements.txt

Basically, any option you can run with pip install you can run in a YAML. See the Advanced Pip Example for a showcase of other capabilities.


回答 2

只是想补充一点,在目录中添加轮子也可以。使用整个URL时出现此错误:

HTTP error 404 while getting http://www.lfd.uci.edu/~gohlke/pythonlibs/f9r7rmd8/opencv_python-3.1.0-cp35-none-win_amd64.whl

最终下载了转轮,并将其保存到yml文件所在的目录中。

name: test-env
dependencies:
- python>=3.5
- anaconda
- pip
- pip:
  - opencv_python-3.1.0-cp35-none-win_amd64.whl

Just want to add that adding a wheel in the directory also works. I was getting this error when using the entire URL:

HTTP error 404 while getting http://www.lfd.uci.edu/~gohlke/pythonlibs/f9r7rmd8/opencv_python-3.1.0-cp35-none-win_amd64.whl

Ended up downloading the wheel and saving it into the same directory as the yml file.

name: test-env
dependencies:
- python>=3.5
- anaconda
- pip
- pip:
  - opencv_python-3.1.0-cp35-none-win_amd64.whl

如何使用pip从git子目录安装?

问题:如何使用pip从git子目录安装?

我有一个带有许多文件夹的git存储库,其中一个是可通过pip安装的python模块,如下所示:

repo.git/
repo.git/folder1/
repo.git/folder2/
repo.git/mymodule/
repo.git/mymodule/__init__.py
repo.git/mymodule/setup.py
repo.git/mymodule/...

现在,我必须执行以下操作才能安装:

git clone http://server/repo.git
cd repo
pip install mymodule
cd ..
rm -rf repo

是否可以通过pip直接安装模块而无需显式克隆?

我试过了:

pip install git+https://server/repo.git/mymodule/
pip install git+https://server/repo.git:mymodule/

但是我得到:

IOError: [Errno 2] No such file or directory: '/tmp/pip-88tlLm-build/setup.py'

I have a git repository with many folders, one of them being a python module installable with pip, like this:

repo.git/
repo.git/folder1/
repo.git/folder2/
repo.git/mymodule/
repo.git/mymodule/__init__.py
repo.git/mymodule/setup.py
repo.git/mymodule/...

Right now I have to do the following to install:

git clone http://server/repo.git
cd repo
pip install mymodule
cd ..
rm -rf repo

Is it possible to install the module directly with pip without explicitly cloning ?

I tried:

pip install git+https://server/repo.git/mymodule/
pip install git+https://server/repo.git:mymodule/

But I get:

IOError: [Errno 2] No such file or directory: '/tmp/pip-88tlLm-build/setup.py'

回答 0

有一个关于此功能的请求请求,它似乎已经在一个月前合并到了开发分支中。语法如下

pip install -e git+https://git.repo/some_repo.git#egg=version_subpkg&subdirectory=repo # install a python package from a repo subdirectory

我们可能要等一会儿,直到它合并到master并分发。

更新:现在可以在https://pip.readthedocs.io/en/stable/reference/pip_install/#vcs-support上获得和记录,如下所示:

对于setup.py不在项目根目录中的项目,将使用“子目录”组件。“子目录”组件的值应该是从项目根目录到setup.py所在位置的路径。

因此,如果您的存储库布局为:

- pkg_dir/
  - setup.py  # setup.py for package ``pkg``
  - some_module.py
- other_dir/
  - some_file
- some_other_file

您需要使用

pip install -e vcs+protocol://repo_url/#egg=pkg&subdirectory=pkg_dir

注意:在Windows上,必须将URL用双引号引起来,否则会出现错误“无法将’子目录’识别为内部或外部命令”。例如,使用:

pip install -e "vcs+protocol://repo_url#egg=pkg&subdirectory=pkg_dir"

There is a pull request regarding this feature, and it seems to have been merged to develop branch a month ago. The syntax is the following:

pip install -e git+https://git.repo/some_repo.git#egg=version_subpkg&subdirectory=repo # install a python package from a repo subdirectory

We probably have to wait for a while until it gets merged to master and is distributed.

UPDATE: This is now available and documented at https://pip.readthedocs.io/en/stable/reference/pip_install/#vcs-support as follows:

For projects where setup.py is not in the root of project, “subdirectory” component is used. Value of “subdirectory” component should be a path starting from root of the project to where setup.py is located.

So if your repository layout is:

- pkg_dir/
  - setup.py  # setup.py for package ``pkg``
  - some_module.py
- other_dir/
  - some_file
- some_other_file

You’ll need to use

pip install -e vcs+protocol://repo_url/#egg=pkg&subdirectory=pkg_dir

Note: On Windows, you must place the URL in double quotes, or you’ll get an error “‘subdirectory’ is not recognized as an internal or external command”. E.g., use:

pip install -e "vcs+protocol://repo_url#egg=pkg&subdirectory=pkg_dir"

回答 1

已经在正确答案下的注释之一中指出了这一点,但只是为了强调此问题:从Linux命令行执行此命令时,必须逃脱&-character,因为&符告诉命令行在后台运行命令:

git+https://git.repo/some_repo.git#egg=version_subpkg\&subdirectory=repo

注意在“&”号之前的反斜杠。转义行为可能取决于Linux发行版。我不是专家。
如果您忽略此设置,则可能会遇到类似以下的神秘错误:

bash: (...) command not found

It’s been already stated in one of the comments under the correct answer, but just to highlight this issue: when executing this from Linux command line, you must escape the &-character since ampersand is telling the command line to run a command in background:

git+https://git.repo/some_repo.git#egg=version_subpkg\&subdirectory=repo

Notice the backslash before the ampersand. The escaping behaviour might depend on the Linux distro; I’m not an expert.
If you ignore this, you might run into a cryptic error like the following:

bash: (...) command not found

“错误:选项-无法识别单一版本-外部版本管理”表示什么?

问题:“错误:选项-无法识别单一版本-外部版本管理”表示什么?

error: option --single-version-externally-managed not recognized在加入pip installvarions软件包(包括PyObjCastropy)时似乎突然开始遇到错误。我以前从未见过此错误,但现在它也出现在travis-ci构建中,但没有任何更改。

此错误是否表示已过期?还是某些错误指定的选项setup.py?还是完全其他?

I seem to have suddenly started encounter the error error: option --single-version-externally-managed not recognized when pip installing varions packages (including PyObjC and astropy). I’ve never seen this error before, but it’s now also showing up on travis-ci builds for which nothing has changed.

Does this error indicate an out of date distribute? Or some incorrectly specified option in setup.py? Or something else entirely?


回答 0

新更新:

安装最新版本的setuptools。如果仍然出现错误,请wheel同时安装。

pip install -U setuptools
pip install -U wheel

原始答案/更多详细信息:

--single-version-externally-managed 是用于Python软件包的选项,指示setuptools模块创建一个Python软件包,如果需要,可以由主机的软件包管理器轻松地管理它,例如Yum或Apt。

如果您看到此消息,则可能是旧版本的setuptools或Python。尝试使用Distribute,它是setuptools的较新版本,并且向后兼容。这些软件包可能希望您已经拥有它。

https://pypi.python.org/pypi/distribute

编辑:至此,分发已经合并到主setuptools项目中。只需安装最新版本的setuptools。正如@wynemo指出的那样,您可能希望使用该--egg选项,因为它更适合那些不希望创建要分发的系统软件包的手动安装人员。

New Update:

Install the latest version of setuptools. If you still get the error, install wheel as well.

pip install -U setuptools
pip install -U wheel

Original Answer / More Details:

--single-version-externally-managed is an option used for Python packages instructing the setuptools module to create a Python package which can be easily managed by the host’s package manager if needed, like Yum or Apt.

If you’re seeing this message, you may have an old version of setuptools or Python. Try using Distribute, which is a newer version of setuptools and is backwards compatible. These packages may expect that you have it already.

https://pypi.python.org/pypi/distribute

Edit: At this point, distribute has been merged into the main setuptools project. Just install the latest version of setuptools. As @wynemo indicated, you may wish to use the --egg option instead, as it’s more appropriate for those doing manual installations where you’re not intending to create a system package for distribution.


回答 1

添加--egg选项

pip install --egg SCons

我使用pip1.4.1版

Add --egg option

pip install --egg SCons

I use pip version 1.4.1


回答 2

安装wheel最近解决了这个问题pip(我使用的是8.1.2):

pip install wheel

Installing wheel resolved this issue with recent pip (I used 8.1.2):

pip install wheel

回答 3

尝试像这样升级setuptools:

pip install --upgrade setuptools

Try upgrading setuptools like this:

pip install --upgrade setuptools


回答 4

我有这个问题。原来,我的pip缓存中的文件权限存在问题。

如果您在pip输出的开头看到一条消息,例如

The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

您可能有同样的问题。您可以通过确保对pip缓存具有适当的文件权限(例如chown -R $(whoami) /home/ubuntu/.cache/pip)来解决它,或者,如果您使用的是UNIX,则可以使用XDG_CACHE_HOMEenv var 将pip缓存位置设置为您拥有的某个文件夹。

I was having this problem. It turned out it was a problem with the file permissions on my pip cache.

If you see a message at the very beginning of your pip output like

The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

you might have the same problem. You can resolve it by either ensuring that you have proper file permissions on your pip cache (something like chown -R $(whoami) /home/ubuntu/.cache/pip) or, if you’re on a UNIX, you can set the pip cache location with the XDG_CACHE_HOME env var to some folder you do own.


回答 5

我尝试了上述解决方案。但是,只有执行以下操作,我才能解决该问题:

sudo pip3 install -U pip (对于python3)

I tried the above solutions. However, I only can resolve the problem until I do:

sudo pip3 install -U pip (for python3)


回答 6

当我尝试升级一个python软件包时,我的macbook上也出现此问题。我在OS X中检查了pip版本,它太旧了:1.1。我使用Follow cmd将pip升级到1.5.6

easy_install -U pip

然后,此错误将得到解决。

I have this problem on my macbook also when I try to upgrade one python package. I check pip version in OS X, it’s too old: 1.1. I use follow cmd to upgrade pip to 1.5.6

easy_install -U pip

Then this error is fixed.


安装几乎所有库的pip问题

问题:安装几乎所有库的pip问题

我很难用pip安装几乎所有东西。我是编码的新手,所以我认为这可能是我做错了的事情,因此选择easy_install来完成我需要完成的大部分工作,而这种工作通常是有效的。但是,现在我正在尝试下载nltk库,但都没有完成任务。

我尝试进入

sudo pip install nltk

但得到以下回应:

/Library/Frameworks/Python.framework/Versions/2.7/bin/pip run on Sat May  4 00:15:38 2013
Downloading/unpacking nltk

  Getting page https://pypi.python.org/simple/nltk/
  Could not fetch URL [need more reputation to post link]: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link]/simple/nltk/ when looking for download links for nltk

  Getting page [need more reputation to post link]/simple/
  Could not fetch URL https://pypi.python. org/simple/: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link] when looking for download links for nltk

  Cannot fetch index base URL [need more reputation to post link]

  URLs to search for versions for nltk:
  * [need more reputation to post link]
  Getting page [need more reputation to post link]
  Could not fetch URL [need more reputation to post link]: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link] when looking for download links for nltk

  Could not find any downloads that satisfy the requirement nltk

No distributions at all found for nltk

Exception information:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/basecommand.py", line 139, in main
    status = self.run(options, args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/commands/install.py", line 266, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py", line 1026, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/index.py", line 171, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for nltk

--easy_install installed fragments of the library and the code ran into trouble very quickly upon trying to run it.

对这个问题有什么想法吗?在此期间,我非常感谢您提供一些反馈意见,以帮助我解决问题或解决问题。

I have a difficult time using pip to install almost anything. I’m new to coding, so I thought maybe this is something I’ve been doing wrong and have opted out to easy_install to get most of what I needed done, which has generally worked. However, now I’m trying to download the nltk library, and neither is getting the job done.

I tried entering

sudo pip install nltk

but got the following response:

/Library/Frameworks/Python.framework/Versions/2.7/bin/pip run on Sat May  4 00:15:38 2013
Downloading/unpacking nltk

  Getting page https://pypi.python.org/simple/nltk/
  Could not fetch URL [need more reputation to post link]: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link]/simple/nltk/ when looking for download links for nltk

  Getting page [need more reputation to post link]/simple/
  Could not fetch URL https://pypi.python. org/simple/: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link] when looking for download links for nltk

  Cannot fetch index base URL [need more reputation to post link]

  URLs to search for versions for nltk:
  * [need more reputation to post link]
  Getting page [need more reputation to post link]
  Could not fetch URL [need more reputation to post link]: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link] when looking for download links for nltk

  Could not find any downloads that satisfy the requirement nltk

No distributions at all found for nltk

Exception information:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/basecommand.py", line 139, in main
    status = self.run(options, args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/commands/install.py", line 266, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py", line 1026, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/index.py", line 171, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for nltk

--easy_install installed fragments of the library and the code ran into trouble very quickly upon trying to run it.

Any thoughts on this issue? I’d really appreciate some feedback on how I can either get pip working or something to get around the issue in the meantime.


回答 0

我发现将pypi主机指定为受信任就足够了。例:

pip install --trusted-host pypi.python.org pytest-xdist
pip install --trusted-host pypi.python.org --upgrade pip

这解决了以下错误:

  Could not fetch URL https://pypi.python.org/simple/pytest-cov/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600) - skipping
  Could not find a version that satisfies the requirement pytest-cov (from versions: )
No matching distribution found for pytest-cov

2018年4月更新:对于任何收到TLSV1_ALERT_PROTOCOL_VERSION错误的人:与OP的受信任主机/验证问题或此答案无关。而是TLSV1错误是因为您的解释器不支持TLS v1.2,所以您必须升级您的解释器。例如见https://news.ycombinator.com/item?id=13539034http://pyfound.blogspot.ca/2017/01/time-to-upgrade-your-python-tls-v12.htmlHTTPS ://bugs.python.org/issue17128

2019年2月更新:对于某些更新点子可能就足够了。如果以上错误阻止您执行此操作,请使用get-pip.py。例如在Linux上,

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

有关更多详细信息,参见https://pip.pypa.io/en/stable/installing/

I found it sufficient to specify the pypi host as trusted. Example:

pip install --trusted-host pypi.python.org pytest-xdist
pip install --trusted-host pypi.python.org --upgrade pip

This solved the following error:

  Could not fetch URL https://pypi.python.org/simple/pytest-cov/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600) - skipping
  Could not find a version that satisfies the requirement pytest-cov (from versions: )
No matching distribution found for pytest-cov

Update April 2018: To anyone getting the TLSV1_ALERT_PROTOCOL_VERSION error: it has nothing to do with trusted-host/verification issue of the OP or this answer. Rather the TLSV1 error is because your interpreter does not support TLS v1.2, you must upgrade your interpreter. See for example https://news.ycombinator.com/item?id=13539034, http://pyfound.blogspot.ca/2017/01/time-to-upgrade-your-python-tls-v12.html and https://bugs.python.org/issue17128.

Update Feb 2019: For some it may be sufficient to upgrade pip. If the above error prevents you from doing this, use get-pip.py. E.g. on Linux,

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

More details at https://pip.pypa.io/en/stable/installing/.


回答 1

我使用的是pip版本,9.0.1并且存在相同的问题,以上所有答案都无法解决问题,并且由于其他原因,我无法通过brew安装python / pip。

升级点子即可9.0.3解决问题。而且因为我无法使用pip升级pip,所以我下载了源代码并手动进行了安装。

  1. -从下载PIP的正确版本https://pypi.org/simple/pip/
  2. sudo python3 pip-9.0.3.tar.gz -安装点子

或者您可以使用以下方法安装更新的点子:

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

I used pip version 9.0.1 and had the same issue, all the answers above didn’t solve the problem, and I couldn’t install python / pip with brew for other reasons.

Upgrading pip to 9.0.3 solved the problem. And because I couldn’t upgrade pip with pip I downloaded the source and installed it manually.

  1. Download the correct version of pip from – https://pypi.org/simple/pip/
  2. sudo python3 pip-9.0.3.tar.gz – Install pip

Or you can install newer pip with:

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

回答 2

Pypi删除了对小于1.2的TLS版本的支持

您需要重新安装Pip,然后执行

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

或对于全局Python:

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

Pypi removed support for TLS versions less than 1.2

You need to re-install Pip, do

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

or for global Python:

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

回答 3

我使用的是pip3版本9.0.1,最近无法通过命令安装任何软件包pip3 install

Mac OS版本:EI Captain 10.11.5

python版本: 3.5

我尝试了命令:

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

它对我不起作用。

因此,我10.0.0通过输入以下命令卸载了较旧的pip并安装了最新版本:

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

现在我的问题解决了。如果您使用的是python2,则可以将python3替换为python。我希望它也对您有用。

顺便说一下,对于像我这样的新秀,您必须输入代码: sudo -i

获得根本权利:)祝你好运!

I used pip3 version 9.0.1 and was unable to install any packages recently via the commandpip3 install.

Mac os version: EI Captain 10.11.5.

python version: 3.5

I tried the command:

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

It didn’t work for me.

So I uninstalled the older pip and installed the newest version10.0.0 by entering this:

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

Now my problem was solved. If you are using the python2, you can substitute the python3 with python. I hope it also works for you.

By the way, for some rookies like me, you have to enter the code: sudo -i

to gain the root right :) Good luck!


回答 4

您可能会看到此错误;也可以在这里看到。

最简单的解决方法是将pip降级为不使用SSL:的点easy_install pip==1.2.1。这会使您失去使用SSL的安全优势。真正的解决方案是使用链接到最新SSL库的Python发行版。

You’re probably seeing this bug; see also here.

The easiest workaround is to downgrade pip to one that doesn’t use SSL: easy_install pip==1.2.1. This loses you the security benefit of using SSL. The real solution is to use a Python distribution linked to a more recent SSL library.


回答 5

SSL错误的另一个原因可能是糟糕的系统时间–如果证书与当前时间相距太远,证书将无法验证。

Another cause of SSL errors can be a bad system time – certificates won’t validate if it’s too far off from the present.


回答 6

对我有用的唯一解决方案是:

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

The only solution that worked for me is:

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


回答 7

我通过添加--trusted-host pypi.python.org选项解决了类似的问题

I solved a similar problem by adding the --trusted-host pypi.python.org option


回答 8

要安装任何其他软件包,我必须使用最新版本的pip,因为9.0.1存在此SSL问题。要通过点子本身升级点子,我必须首先解决此SSL问题。要跳出这个无尽的循环,我发现这是唯一对我有用的方法。

  1. 在此页面中找到最新版本的pip:https//pypi.org/simple/pip/
  2. 下载.whl最新版本的文件。
  3. 使用pip安装最新的pip。(在这里使用您自己的最新版本)

须藤点安装pip-10.0.1-py2.py3-none-any.whl

现在pip是最新版本,可以安装任何东西。

To install any other package I have to use the latest version of pip, since the 9.0.1 has this SSL problem. To upgrade the pip by pip itself, I have to solve this SSL problem first. To jump out of this endless loop, I find this only way that works for me.

  1. Find the latest version of pip in this page: https://pypi.org/simple/pip/
  2. Download the .whl file of the latest version.
  3. Use pip to install the latest pip. (Use your own latest version here)

sudo pip install pip-10.0.1-py2.py3-none-any.whl

Now the pip is the latest version and can install anything.


回答 9

解决方案 -通过标记以下受信任的主机来安装任何软件包

  • pypi.python.org
  • pypi.org
  • files.pythonhosted.org

临时解决方案

pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}

永久解决方案 -将您的PIP(9.0.1版本的问题)更新为最新版本。

pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org pytest-xdist

python -m pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org --upgrade pip

Solution – Install any package by marking below hosts trusted

  • pypi.python.org
  • pypi.org
  • files.pythonhosted.org

Temporary solution

pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}

Permanent solution – Update your PIP(problem with version 9.0.1) to latest.

pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org pytest-xdist

python -m pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org --upgrade pip

回答 10

macOS Sierra 10.12.6。无法通过pip安装任何东西(通过homebrew安装的python)。以上所有答案均无效。

最终,从python 3.5升级到3.6可行。

brew update
brew doctor #(in case you see such suggestion by brew)

然后按照brew的任何其他建议,即覆盖python的链接。

macOS Sierra 10.12.6. Wasn’t able to install anything through pip (python installed through homebrew). All the answers above didn’t work.

Eventually, upgrade from python 3.5 to 3.6 worked.

brew update
brew doctor #(in case you see such suggestion by brew)

then follow any additional suggestions by brew, i.e. overwrite link to python.


回答 11

我有同样的问题。我刚刚将python从2.7.0更新为2.7.15。它解决了这个问题。

您可以在此处下载。

I had the same problem. I just updated the python from 2.7.0 to 2.7.15. It solves the problem.

You can download here.


回答 12

正如blackjar在上面发布的,以下几行对我有用

pip --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org install xxx

您需要同时给出全部三个--trusted-host options。看完答案后,我只尝试了第一个,但那样对我来说并不起作用。

As posted above by blackjar, the below lines worked for me

pip --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org install xxx

You need to give all three --trusted-host options. I was trying with only the first one after looking at the answers but it didn’t work for me like that.


回答 13

您还可以使用conda安装软件包:请参见http://conda.pydata.org

conda install nltk

使用conda的最佳方法是下载Miniconda,但您也可以尝试

pip install conda
conda init
conda install nltk

You can also use conda to install packages: See http://conda.pydata.org

conda install nltk

The best way to use conda is to download Miniconda, but you can also try

pip install conda
conda init
conda install nltk

回答 14

对我来说,最新的pip(1.5.6)可以与不安全的nltk软件包一起使用,如果您只是告诉它不要对安全性如此挑剔的话:

pip install --upgrade --force-reinstall --allow-all-external --allow-unverified ntlk nltk

For me, the latest pip (1.5.6) works fine with the insecure nltk package if you just tell it not to be so picky about security:

pip install --upgrade --force-reinstall --allow-all-external --allow-unverified ntlk nltk

回答 15

试过了

pip --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org install xxx 

最终得出结论,不太了解为什么更改了pypi.python.org域。

tried

pip --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org install xxx 

and finally worked out, not quite understand why the domain pypi.python.org is changed.


回答 16

如果通过代理连接,请执行export https_proxy=<your_proxy>(在Unix或Git Bash上),然后重试安装。

如果您使用的是Windows cmd,则更改为set https_proxy=<your_proxy>

If you’re connecting through a proxy, execute export https_proxy=<your_proxy> (on Unix or Git Bash) and then retry installation.

If you’re using Windows cmd, this changes to set https_proxy=<your_proxy>.


回答 17

为了解决此问题,我在Windows 7上执行了以下操作。

c:\ Program Files \ Python36 \ Scripts> pip install beautifulsoup4 –trusted-host *

–trusted-host似乎可以解决SSL问题,*表示每个主机。

当然这是行不通的,因为您会遇到其他错误,因为没有版本可以满足beautifulsoup4的要求,但是我认为该问题与一般性问题无关。

I did the following on Windows 7 to solve this problem.

c:\Program Files\Python36\Scripts> pip install beautifulsoup4 –trusted-host *

The –trusted-host seems to fix the SSL issue and * means every host.

Of course this does not work because you get other errors since there is no version that satisfies the requirement beautifulsoup4, but I don’t think that issue is related to the general question.


回答 18

只需卸载并重新安装将为您锻炼的pip软件包即可。

Mac OS版本:高Sierra 10.13.6

python版本:3.7

因此,我通过输入以下命令卸载了较旧的pip并安装了最新的版本10.0.0:

python3 -m pip uninstall pip setuptools

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

现在我的问题解决了。如果您使用的是python2,则可以将python3替换为python。我希望它也对您有用。

Just uninstall and reinstall pip packages it will workout for you guys.

Mac os version: high Sierra 10.13.6

python version: 3.7

So I uninstalled the older pip and installed the newest version10.0.0 by entering this:

python3 -m pip uninstall pip setuptools

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

Now my problem was solved. If you are using the python2, you can substitute the python3 with python. I hope it also works for you.


回答 19

如果只是关于nltk,我曾经遇到过类似的问题。尝试按照以下安装指南进行操作。 安装NLTK

如果确定它不能与任何其他模块一起使用,则可能是您安装了不同版本的Python时遇到了问题。

或尝试一下,看是否已安装pip 。:

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

看看是否可行。

If it is only about nltk, I once faced similar problem. Try following guide for installation. Install NLTK

If you are sure it doesn’t work with any other module, you may have problem with different versions of Python installed.

Or Give It a Try to see if it says pip is already installed.:

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

and see if it works.


回答 20

我通过以下步骤解决了此问题(在les 11sp2上)

zypper remove pip
easy_install pip=1.2.1
pip install --upgrade scons

这是puppet中的相同步骤(适用于所有发行版)

  package { 'python-pip':
    ensure => absent,
  }
  exec { 'python-pip':
    command  => '/usr/bin/easy_install pip==1.2.1',
    require  => Package['python-pip'],
  }
  package { 'scons': 
    ensure   => latest,
    provider => pip,
    require  => Exec['python-pip'],
  }

I solved this issue with the following steps (on sles 11sp2)

zypper remove pip
easy_install pip=1.2.1
pip install --upgrade scons

Here are the same steps in puppet (which should work on all distros)

  package { 'python-pip':
    ensure => absent,
  }
  exec { 'python-pip':
    command  => '/usr/bin/easy_install pip==1.2.1',
    require  => Package['python-pip'],
  }
  package { 'scons': 
    ensure   => latest,
    provider => pip,
    require  => Exec['python-pip'],
  }

回答 21

在Mac Python 2.7.15rc1上使用python的最新版本 https://bugs.python.org/issue17128

Use Latest version of python on mac Python 2.7.15rc1 https://bugs.python.org/issue17128


回答 22

我在PyCharm中遇到了这个问题,将点子升级到10.0.1时,出现了“在模块中找不到’main’的错误”点子。

我可以通过安装pip 9.0.3来解决此问题,如在其他一些线程中所见。这些是我执行的步骤:

  1. https://pypi.org/simple/pip/下载了9.0.3版本的pip (因为无法使用pip进行安装)。
  2. 从tar.gz安装pip 9.0.3 python -m pip安装pip-9.0.3.tar.gz

此后,一切开始起作用。

I had this with PyCharm and upgrading pip to 10.0.1 broke pip with “‘main’ not found in module” error.

I could solve this problem by installing pip 9.0.3 as seen in some other thread. These are the steps I did:

  1. Downloaded 9.0.3 version of pip from https://pypi.org/simple/pip/ (since pip couldn’t be used to install it).
  2. Install pip 9.0.3 from tar.gz python -m pip install pip-9.0.3.tar.gz

Everything started to work after that.


回答 23

该视频教程对我有用:

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

This video tutorial worked for me:

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

回答 24

我通过在Mac上更新Python3 Virtualenv解决了此问题。我引用了网站https://gist.github.com/pandafulmanda/730a9355e088a9970b18275cb9eadef3
brew install python3
pip3 install virtualenv

I solved this issue by update Python3 Virtualenv on my mac. I reference the site https://gist.github.com/pandafulmanda/730a9355e088a9970b18275cb9eadef3
brew install python3
pip3 install virtualenv


回答 25

我尝试了一些流行的答案,但是仍然无法使用安装任何库/软件包pip install

我的特定错误是'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain使用Windows Miniconda(安装程序Miniconda3-py37_4.8.3-Windows-x86.exe)。

当我这样做时,它终于可以工作了: pip install -r requirements.txt --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org

具体来说,我添加了它以使其工作: --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org

I tried some of the popular answers, but still could not install any libraries/packages using pip install.

My specific error was 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain using Miniconda for Windows (installer Miniconda3-py37_4.8.3-Windows-x86.exe).

It finally works when I did this: pip install -r requirements.txt --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org

Specifically, I added this to make it work: --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org


如何在全球而非本地安装pip软件包?

问题:如何在全球而非本地安装pip软件包?

我正在尝试使用pip3安装flake8软件包,但似乎已拒绝安装,因为它已安装在一个本地位置。

如何强制它在全局(系统级别)安装?

pip3 install flake8
Requirement already satisfied (use --upgrade to upgrade): flake8 in ./.local/lib/python3.4/site-packages

请注意,我更喜欢一种通用解决方案(该解决方案应该在Debian,OS X甚至Windows上都可以使用),该解决方案可以在任何平台上使用,所以我不想自己指定目的地。

出于某种奇怪的原因,它的行为就像我已经指定了--user(在我的情况下我没有指定)。

我能够全局安装软件包的唯一方法是先将其删除,然后再重新安装。如果以某种方式存在,pip(8.1.1)似乎拒绝全局安装软件包。

免责声明:实验期间未使用或损坏任何虚拟环境。

I am trying to install flake8 package using pip3 and it seems that it refuses to install because is already installed in one local location.

How can I force it to install globally (system level)?

pip3 install flake8
Requirement already satisfied (use --upgrade to upgrade): flake8 in ./.local/lib/python3.4/site-packages

Please note that I would prefer a generic solution (that should work on Debian, OS X maybe even Windows), one that should be used on any platform so I don’t want to specify the destination myself.

For some weird reason it behaves like I already specified --user which in my case I didn’t.

The only way I was able to install a package globally was to first remove it and install it again after this. Somehow it seems that pip (8.1.1) refuses to install a package globally if it exists locally.

Disclaimer: No virtual environments were used or harmed during the experiments.


回答 0

您为什么不尝试sudo使用H标志?这应该可以解决问题。

sudo -H pip install flake8

普通人sudo pip install flake8将尝试使用您自己的主目录。该-H指示它使用系统的主目录。有关更多信息,访问https://stackoverflow.com/a/43623102/

Why don’t you try sudo with the H flag? This should do the trick.

sudo -H pip install flake8

A regular sudo pip install flake8 will try to use your own home directory. The -H instructs it to use the system’s home directory. More info at https://stackoverflow.com/a/43623102/


回答 1

也许--force-reinstall会奏效,否则就可以解决问题--ignore-installed

Maybe --force-reinstall would work, otherwise --ignore-installed should do the trick.


回答 2

您正在使用virtualenv吗?如果是,请禁用virtualenv。如果您不使用它,则它已经被广泛安装(系统级别)。尝试升级软件包。

pip install flake8 --upgrade

Are you using virtualenv? If yes, deactivate the virtualenv. If you are not using, it is already installed widely (system level). Try to upgrade package.

pip install flake8 --upgrade

回答 3

我实际上看不到您的问题。全局是python3路径的站点包文件夹中的任何包。

如果要仅在本地使用它,则必须配置virtualenv并在激活的虚拟环境中重新安装软件包。

I actually don‘t see your issue. Globally is any package which is in your python3 path‘s site package folder.

If you want to use it just locally then you must configure a virtualenv and reinstall the packages with an activated virtual environment.


回答 4

python中的pip安装在哪里进行?

我将提供我面临的Windows解决方案,并花了一些时间解决。

首先,在Windows中(如果使用Windows作为操作系统,则将Windows作为操作系统),pip install <package_name>默认情况下,它将全局安装(如果您尚未激活虚拟环境)。激活虚拟环境并进入虚拟环境后,所有pip安装都将在该虚拟环境内。


pip正在安装上述软件包,但是我不能使用它们吗?

对于这个pip,可能会警告您,pip可执行文件(例如pip3.exepip.exe不在您的path变量上。为此,您可以将此路径(通常为- C:\Users\<your_username>\AppData\Roaming\Programs\Python\)添加到环境变量中。重新启动后cmd,现在尝试使用已安装的python软件包。现在应该可以工作了。

Where does pip installations happen in python?

I will give a windows solution which I was facing and took a while to solve.

First of all, in windows (I will be taking Windows as the OS here), if you do pip install <package_name>, it will be by default installed globally (if you have not activated a virtual enviroment). Once you activate a virtual enviroment and you are inside it, all pip installations will be inside that virtual enviroment.


pip is installing the said packages but not I cannot use them?

For this pip might be giving you a warning that the pip executables like pip3.exe, pip.exe are not on your path variable. For this you might add this path ( usually – C:\Users\<your_username>\AppData\Roaming\Programs\Python\ ) to your enviromental variables. After this restart your cmd, and now try to use your installed python package. It should work now.


有没有办法列出点子的依赖关系/要求?

问题:有没有办法列出点子的依赖关系/要求?

在不进行安装的情况下,我想快速查看pip install将要安装的所有软件包。

Without going through with the installation, I want to quickly see all the packages that pip install would install.


回答 0

接受的答案不再与最新版本的pip有关,并且在不仔细阅读多个注释的情况下也不会立即给出答案,因此我提供了更新的答案。

这与PIP测试版本8.1.29.0.110.0.118.1

要在Linux上不干扰当前目录的情况下获取输出,请使用

pip download [package] -d /tmp --no-binary :all: -v

-d 告诉pip下载应该放置文件的目录。

更好的方法是,仅使用以下脚本,并使用参数作为包名称来仅获取依赖项作为输出:

#!/bin/sh

PACKAGE=$1
pip download $PACKAGE -d /tmp --no-binary :all:-v 2>&1 \
| grep Collecting \
| cut -d' ' -f2 \
| grep -Ev "$PACKAGE(~|=|\!|>|<|$)"

也可以在这里

The accepted answer is no longer relevant for more current versions of pip and does not give an immediate answer without perusing multiple comments so I am providing an updated answer.

This was tested with pip versions 8.1.2, 9.0.1, 10.0.1, and 18.1.

To get the output without cluttering your current directory on Linux use

pip download [package] -d /tmp --no-binary :all: -v

-d tells pip the directory that download should put files in.

Better, just use this script with the argument being the package name to get only the dependencies as output:

#!/bin/sh

PACKAGE=$1
pip download $PACKAGE -d /tmp --no-binary :all:-v 2>&1 \
| grep Collecting \
| cut -d' ' -f2 \
| grep -Ev "$PACKAGE(~|=|\!|>|<|$)"

Also available here.


回答 1

看看我的项目johnnydep

安装:

pip install johnnydep

用法示例:

$ johnnydep requests
name                       summary
-------------------------  ----------------------------------------------------------------------
requests                   Python HTTP for Humans.
├── certifi>=2017.4.17     Python package for providing Mozilla's CA Bundle.
├── chardet<3.1.0,>=3.0.2  Universal encoding detector for Python 2 and 3
├── idna<2.7,>=2.5         Internationalized Domain Names in Applications (IDNA)
└── urllib3<1.23,>=1.21.1  HTTP library with thread-safe connection pooling, file post, and more.

更复杂的树:

$ johnnydep ipython 
name                              summary
--------------------------------  -----------------------------------------------------------------------------
ipython                           IPython: Productive Interactive Computing
├── appnope                       Disable App Nap on OS X 10.9
├── decorator                     Better living through Python with decorators
├── jedi>=0.10                    An autocompletion tool for Python that can be used for text editors.
│   └── parso==0.1.1              A Python Parser
├── pexpect                       Pexpect allows easy control of interactive console applications.
│   └── ptyprocess>=0.5           Run a subprocess in a pseudo terminal
├── pickleshare                   Tiny 'shelve'-like database with concurrency support
├── prompt-toolkit<2.0.0,>=1.0.4  Library for building powerful interactive command lines in Python
│   ├── six>=1.9.0                Python 2 and 3 compatibility utilities
│   └── wcwidth                   Measures number of Terminal column cells of wide-character codes
├── pygments                      Pygments is a syntax highlighting package written in Python.
├── setuptools>=18.5              Easily download, build, install, upgrade, and uninstall Python packages
├── simplegeneric>0.8             Simple generic functions (similar to Python's own len(), pickle.dump(), etc.)
└── traitlets>=4.2                Traitlets Python config system
    ├── decorator                 Better living through Python with decorators
    ├── ipython-genutils          Vestigial utilities from IPython
    └── six                       Python 2 and 3 compatibility utilities

Check out my project johnnydep!

Installation:

pip install johnnydep

Usage example:

$ johnnydep requests
name                       summary
-------------------------  ----------------------------------------------------------------------
requests                   Python HTTP for Humans.
├── certifi>=2017.4.17     Python package for providing Mozilla's CA Bundle.
├── chardet<3.1.0,>=3.0.2  Universal encoding detector for Python 2 and 3
├── idna<2.7,>=2.5         Internationalized Domain Names in Applications (IDNA)
└── urllib3<1.23,>=1.21.1  HTTP library with thread-safe connection pooling, file post, and more.

A more complex tree:

$ johnnydep ipython 
name                              summary
--------------------------------  -----------------------------------------------------------------------------
ipython                           IPython: Productive Interactive Computing
├── appnope                       Disable App Nap on OS X 10.9
├── decorator                     Better living through Python with decorators
├── jedi>=0.10                    An autocompletion tool for Python that can be used for text editors.
│   └── parso==0.1.1              A Python Parser
├── pexpect                       Pexpect allows easy control of interactive console applications.
│   └── ptyprocess>=0.5           Run a subprocess in a pseudo terminal
├── pickleshare                   Tiny 'shelve'-like database with concurrency support
├── prompt-toolkit<2.0.0,>=1.0.4  Library for building powerful interactive command lines in Python
│   ├── six>=1.9.0                Python 2 and 3 compatibility utilities
│   └── wcwidth                   Measures number of Terminal column cells of wide-character codes
├── pygments                      Pygments is a syntax highlighting package written in Python.
├── setuptools>=18.5              Easily download, build, install, upgrade, and uninstall Python packages
├── simplegeneric>0.8             Simple generic functions (similar to Python's own len(), pickle.dump(), etc.)
└── traitlets>=4.2                Traitlets Python config system
    ├── decorator                 Better living through Python with decorators
    ├── ipython-genutils          Vestigial utilities from IPython
    └── six                       Python 2 and 3 compatibility utilities

回答 2

仅当软件包已安装时,您才可以使用pip show <package>Requires:在输出末尾查找字段。显然,这违反了您的要求,但可能仍然有用。

例如:

$ pip --version
pip 7.1.0 [...]
$ pip show pytest
---
Metadata-Version: 2.0
Name: pytest
Version: 2.7.2
Summary: pytest: simple powerful testing with Python
Home-page: http://pytest.org
Author: Holger Krekel, Benjamin Peterson, Ronny Pfannschmidt, Floris Bruynooghe and others
Author-email: holger at merlinux.eu
License: MIT license
Location: /home/usr/.tox/develop/lib/python2.7/site-packages
Requires: py

If and only if the package is install, you can use pip show <package>. Look for the Requires: filed at the end of the output. Clearly, this breaks your requirement but might be useful nonetheless.

For example:

$ pip --version
pip 7.1.0 [...]
$ pip show pytest
---
Metadata-Version: 2.0
Name: pytest
Version: 2.7.2
Summary: pytest: simple powerful testing with Python
Home-page: http://pytest.org
Author: Holger Krekel, Benjamin Peterson, Ronny Pfannschmidt, Floris Bruynooghe and others
Author-email: holger at merlinux.eu
License: MIT license
Location: /home/usr/.tox/develop/lib/python2.7/site-packages
Requires: py

回答 3

注意:此答案中使用的功能于2014弃用,于2015删除。请参阅适用于现代语言的其他答案pip

您可以直接通过pip获得最接近的--no-install参数:

pip install --no-install <package>

例如,这是安装Celery时的输出:

Downloading/unpacking celery                                                                                   
  Downloading celery-2.5.5.tar.gz (945Kb): 945Kb downloaded
  Running setup.py egg_info for package celery

    no previously-included directories found matching 'tests/*.pyc'
    no previously-included directories found matching 'docs/*.pyc'
    no previously-included directories found matching 'contrib/*.pyc'
    no previously-included directories found matching 'celery/*.pyc'
    no previously-included directories found matching 'examples/*.pyc'
    no previously-included directories found matching 'bin/*.pyc'
    no previously-included directories found matching 'docs/.build'
    no previously-included directories found matching 'docs/graffles'
    no previously-included directories found matching '.tox/*'
Downloading/unpacking anyjson>=0.3.1 (from celery)
  Downloading anyjson-0.3.3.tar.gz
  Running setup.py egg_info for package anyjson

Downloading/unpacking kombu>=2.1.8,<2.2.0 (from celery)
  Downloading kombu-2.1.8.tar.gz (273Kb): 273Kb downloaded
  Running setup.py egg_info for package kombu

Downloading/unpacking python-dateutil>=1.5,<2.0 (from celery)
  Downloading python-dateutil-1.5.tar.gz (233Kb): 233Kb downloaded
  Running setup.py egg_info for package python-dateutil

Downloading/unpacking amqplib>=1.0 (from kombu>=2.1.8,<2.2.0->celery)
  Downloading amqplib-1.0.2.tgz (58Kb): 58Kb downloaded
  Running setup.py egg_info for package amqplib

Successfully downloaded celery anyjson kombu python-dateutil amqplib

诚然,这确实以临时文件的形式留下了一些麻烦,但是确实实现了目标。如果使用virtualenv(应该如此)执行此操作,则清除就像删除<virtualenv root>/build目录一样容易。

Note: the feature used in this answer was deprecated in 2014 and removed in 2015. Please see other answers that apply to modern pip.

The closest you can get with pip directly is by using the --no-install argument:

pip install --no-install <package>

For example, this is the output when installing celery:

Downloading/unpacking celery                                                                                   
  Downloading celery-2.5.5.tar.gz (945Kb): 945Kb downloaded
  Running setup.py egg_info for package celery

    no previously-included directories found matching 'tests/*.pyc'
    no previously-included directories found matching 'docs/*.pyc'
    no previously-included directories found matching 'contrib/*.pyc'
    no previously-included directories found matching 'celery/*.pyc'
    no previously-included directories found matching 'examples/*.pyc'
    no previously-included directories found matching 'bin/*.pyc'
    no previously-included directories found matching 'docs/.build'
    no previously-included directories found matching 'docs/graffles'
    no previously-included directories found matching '.tox/*'
Downloading/unpacking anyjson>=0.3.1 (from celery)
  Downloading anyjson-0.3.3.tar.gz
  Running setup.py egg_info for package anyjson

Downloading/unpacking kombu>=2.1.8,<2.2.0 (from celery)
  Downloading kombu-2.1.8.tar.gz (273Kb): 273Kb downloaded
  Running setup.py egg_info for package kombu

Downloading/unpacking python-dateutil>=1.5,<2.0 (from celery)
  Downloading python-dateutil-1.5.tar.gz (233Kb): 233Kb downloaded
  Running setup.py egg_info for package python-dateutil

Downloading/unpacking amqplib>=1.0 (from kombu>=2.1.8,<2.2.0->celery)
  Downloading amqplib-1.0.2.tgz (58Kb): 58Kb downloaded
  Running setup.py egg_info for package amqplib

Successfully downloaded celery anyjson kombu python-dateutil amqplib

Admittedly, this does leave some cruft around in the form of temporary files, but it does accomplish the goal. If you’re doing this with virtualenv (which you should be), the cleanup is as easy as removing the <virtualenv root>/build directory.


回答 4

该命令pip install <package> --download <path>应当使用,如通过在@radtek评论提到的,由于作为7.0.0(2015年5月21日),–no安装被除去pip。这会将所需的依赖项下载到中<path>

The command pip install <package> --download <path> should be used, as mentioned in comments by @radtek, since as of 7.0.0 (2015-05-21), –no-install is removed from pip. This will download the dependencies needed into <path>.


回答 5

另一种选择是使用类似于脚本的帮助程序脚本,脚本使用pip.req.parse_requirementsAPI来解析requirements.txt文件,并使用distutils.core.setup替换脚本来解析setup.py文件。

Another option is to use a helper script similar to this one which uses the pip.req.parse_requirements API to parse requirements.txt files and a distutils.core.setup replacement to parse setup.py files.


回答 6

我引用@onnovalkering替代解决方案

PyPi为JSON端点提供了包元数据:

>>> import requests
>>> url = 'https://pypi.org/pypi/{}/json'
>>> json = requests.get(url.format('pandas')).json()
>>> json['info']['requires_dist']
['numpy (>=1.9.0)', 'pytz (>=2011k)', 'python-dateutil (>=2.5.0)']
>>> json['info']['requires_python']
'>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*'

对于特定的软件包版本,请在URL中添加一个附加的版本段:

https://pypi.org/pypi/pandas/0.22.0/json

另外,如果您使用的是conda如@ShpielMeister所建议),则可以使用:

conda info package==X.X.X

显示信息,包括特定版本的依存关系,或:

conda info package

显示信息,包括有关该软件包所有受支持版本的依赖性。

I quote an alternative solution from @onnovalkering:

PyPi provides a JSON endpoint with package metadata:

>>> import requests
>>> url = 'https://pypi.org/pypi/{}/json'
>>> json = requests.get(url.format('pandas')).json()
>>> json['info']['requires_dist']
['numpy (>=1.9.0)', 'pytz (>=2011k)', 'python-dateutil (>=2.5.0)']
>>> json['info']['requires_python']
'>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*'

For a specific package version, add an additional version segment to the URL:

https://pypi.org/pypi/pandas/0.22.0/json

Also if you are using conda (as suggested by @ShpielMeister), you can use:

conda info package==X.X.X

to display information, including dependencies for a particular version or:

conda info package

to display information, including dependencies about all supported versions of that package.


如何知道点子本身的版本

问题:如何知道点子本身的版本

哪个shell命令可以提供我pip正在使用的实际版本?

pip提供pip show已安装但不包含的所有模块版本。

Which shell command gives me the actual version of pip I am using?

pip gives with pip show all version of modules that are installed but excludes itself.


回答 0

你可以这样做:

pip -V

要么:

pip --version

You can do this:

pip -V

or:

pip --version

回答 1

仅出于完整性考虑:

pip -V

pip --version

pip list 在列表中,您还会发现其版本。

Just for completeness:

pip -V

pip --version

pip list and inside the list you’ll find also pip with its version.


回答 2

对于Windows:

import pip

help(pip) 

在帮助文件末尾显示版本。

For windows:

import pip

help(pip) 

shows the version at the end of the help file.


回答 3

对于Windows,只需键入:

python -m pip --version

For windows just type:

python -m pip --version

回答 4

在RHEL上,“ pip -V”有效:

$ pip -V
pip 6.1.1 from /usr/lib/python2.6/site-packages (python 2.6)

On RHEL “pip -V” works :

$ pip -V
pip 6.1.1 from /usr/lib/python2.6/site-packages (python 2.6)

回答 5

以下任何一项都可以工作

pip --version
# pip 19.0.3 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)

要么

pip -V       
# pip 19.0.3 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)

要么

pip3 -V      
# pip 19.0.3 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)

Any of the following should work

pip --version
# pip 19.0.3 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)

or

pip -V       
# pip 19.0.3 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)

or

pip3 -V      
# pip 19.0.3 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)

回答 6

许多人同时使用2.X和3.X python。您可以pip -V用来显示默认的点子版本。
如果您有许多python版本,并且想通过不同的pip安装一些软件包,我建议您这样做:

sudo python2.X -m pip install some-package==0.16

Many people use both 2.X and 3.X python. You can use pip -V to show default pip version.
If you have many python versions, and you want to install some packages through different pip, I advise this way:

sudo python2.X -m pip install some-package==0.16

回答 7

启动Python并输入import pip pip.__version__适用于所有python软件包的类型。

Start Python and type import pip pip.__version__ which works for all python packages.


回答 8

对于Windows计算机,请转到命令提示符并键入。

pip -V 

For Windows machine go to command prompt and type.

pip -V 

回答 9

检查两件事

pip2 --version   

pip3 --version

因为默认点可能是其中的任何一个,所以最好同时检查两者。

check two things

pip2 --version   

and

pip3 --version

because the default pip may be anyone of this so it is always better to check both.


回答 10

首先,打开命令提示符,然后键入以下命令。

轻松检查版本本身:

窗体Windows:

点安装:

pip install pip

pip版本检查:

pip --version 

First, open a command prompt After type a bellow commands.

check a version itself Easily :

Form Windows:

pip installation :

pip install pip

pip Version check:

pip --version 

回答 11

`pip -v` or `pip --v` 

但是请注意,如果您使用的MacOS Catelina具有zsh(z外壳),则可能会给您很多帮助,因此最好的选择是尝试安装该版本或以 -- pip3

`pip -v` or `pip --v` 

However note, if you are using macos catelina which has the zsh (z shell) it might give you a whole bunch of things, so the best option is to try install the version or start as -- pip3


如何使用pip更新/升级软件包?

问题:如何使用pip更新/升级软件包?

使用pip更新软件包的方式是什么?那些不起作用:

pip update
pip upgrade

我知道这是一个简单的问题,但由于不是那么容易找到它,所以它是必需的(pip 文档不会弹出,并且堆栈溢出中的其他问题是相关的,但并不完全与此相关)

What is the way to update a package using pip? those do not work:

pip update
pip upgrade

I know this is a simple question but it is needed as it is not so easy to find (pip documentation doesn’t pop up and other questions from stack overflow are relevant but are not exactly about that)


回答 0

方式是

sudo pip install [package_name] --upgrade

或总之

sudo pip install [package_name] -U

sudo 会要求输入您的root密码以确认操作。

如果您没有root密码(如果您不是管理员),则可能应该使用virtualenv,然后删除sudo

pip install [package_name] --upgrade

The way is

pip install [package_name] --upgrade

or in short

pip install [package_name] -U

Using sudo will ask to enter your root password to confirm the action, but although common, is considered unsafe.

If you do not have a root password (if you are not the admin) you should probably work with virtualenv.

You can also use the user flag to install it on this user only.

pip install [package_name] --upgrade --user

回答 1

对于非特定软件包和更通用的解决方案,您可以签出pip-review,该工具检查可以/应该更新哪些软件包。

$ pip-review --interactive
requests==0.14.0 is available (you have 0.13.2)
Upgrade now? [Y]es, [N]o, [A]ll, [Q]uit y

For a non-specific package and a more general solution you can check out pip-review, a tool that checks what packages could/should be updated.

$ pip-review --interactive
requests==0.14.0 is available (you have 0.13.2)
Upgrade now? [Y]es, [N]o, [A]ll, [Q]uit y

回答 2

tl; dr脚本更新所有已安装的软件包

如果只想升级一个软件包,请参考@borgr的答案。我经常觉得有必要,或者至少是令人愉快的,一次升级我的所有软件包。目前,pip本身不支持该操作,但是使用sh脚本已足够简单。您使用pip listawk(或cuttail)和命令替换。我通常的单线是:

for i in $(pip list -o | awk 'NR > 2 {print $1}'); do sudo pip install -U $i; done

这将要求输入root密码。如果您没有访问权限,则--user可以考虑使用pipor或virtualenv选项。

tl;dr script to update all installed packages

If you only want to upgrade one package, refer to @borgr’s answer. I often find it necessary, or at least pleasing, to upgrade all my packages at once. Currently, pip doesn’t natively support that action, but with sh scripting it is simple enough. You use pip list, awk (or cut and tail), and command substitution. My normal one-liner is:

for i in $(pip list -o | awk 'NR > 2 {print $1}'); do sudo pip install -U $i; done

This will ask for the root password. If you do not have access to that, the --user option of pip or virtualenv may be something to look into.


回答 3

import subprocess as sbp
import pip
pkgs = eval(str(sbp.run("pip3 list -o --format=json", shell=True,
                         stdout=sbp.PIPE).stdout, encoding='utf-8'))
for pkg in pkgs:
    sbp.run("pip3 install --upgrade " + pkg['name'], shell=True)

另存为xx.py
然后运行Python3 xx.py
环境:python3.5 + pip10.0 +

import subprocess as sbp
import pip
pkgs = eval(str(sbp.run("pip3 list -o --format=json", shell=True,
                         stdout=sbp.PIPE).stdout, encoding='utf-8'))
for pkg in pkgs:
    sbp.run("pip3 install --upgrade " + pkg['name'], shell=True)

Save as xx.py
Then run Python3 xx.py
Environment: python3.5+ pip10.0+


回答 4

要为Python3.4 +升级pip,您必须使用pip3,如下所示:

sudo pip3 install pip --upgrade

这将升级位于/usr/local/lib/python3.X/dist-packages的pip

否则,要为Python2.7升级pip,请按以下方式使用pip:

sudo pip install pip --upgrade

这将升级位于以下位置的pip:/usr/local/lib/python2.7/dist-packages

To upgrade pip for Python3.4+, you must use pip3 as follows:

sudo pip3 install pip --upgrade

This will upgrade pip located at: /usr/local/lib/python3.X/dist-packages

Otherwise, to upgrade pip for Python2.7, you would use pip as follows:

sudo pip install pip --upgrade

This will upgrade pip located at: /usr/local/lib/python2.7/dist-packages