Gab*_*iel 113 python pip requirements.txt
我正在使用以下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
Run Code Online (Sandbox Code Playgroud)
和这两个命令:
$ pip install --download=/tmp -r requirements.txt
$ pip install --user --no-index --find-links=/tmp -r requirements.txt
Run Code Online (Sandbox Code Playgroud)
(第一个下载包,第二个安装它们).
该过程经常因错误而停止:
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))
Run Code Online (Sandbox Code Playgroud)
我手动修复:
pip install --user <package>
Run Code Online (Sandbox Code Playgroud)
然后pip install再次运行第二个命令.
但是,这仅适用于该特定的包.当我pip install再次运行第二个命令时,进程停止现在抱怨另一个必需的包,我需要再次重复该过程,即:手动安装新的所需包(使用上面的命令),然后运行第二个pip install命令.
到目前为止,我不得不手动安装six,pytz,nose,现在它在抱怨需要mock.
有没有办法告诉pip自动安装所有需要的依赖项,所以我不必逐个手动安装?
添加:这只发生在Ubuntu 12.04 BTW中.在Ubuntu 14.04中,pip install应用于requirements.txt文件的命令没有问题.
Chi*_*iel 44
虽然它并没有真正回答这个具体问题。其他人收到了与此错误相同的错误消息。
对于那些谁像我最初忘了-r:使用pip install -r requirements.txt的-r是命令至关重要。
原答案:
Sim*_*ser 39
只有当目录包含所有包时,此方法(在目录中具有所有依赖项而不从索引下载)才有效.因此,该目录应包含所有依赖项,但也包含这些依赖项依赖的所有包(例如six,pytz等).
因此,您应该手动包含这些requirements.txt(以便第一步显式下载它们),或者您应该使用PyPI安装所有包,然后pip freeze > requirements.txt存储所需的所有包的列表.
小智 19
我安装了python3,但我在/ usr/bin/python中的python仍然是旧的2.7版本
这个工作(<pkg>是pyserial在我的情况):
python3 -m pip install <pkg>
小智 7
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
Run Code Online (Sandbox Code Playgroud)
只是提醒谁谷歌这个错误并来到这里。
假设我收到此错误:
$ python3 example.py
Traceback (most recent call last):
File "example.py", line 7, in <module>
import aalib
ModuleNotFoundError: No module named 'aalib'
Run Code Online (Sandbox Code Playgroud)
既然提到了aalib,我就想尝试aalib:
$ python3.8 -m pip install aalib
ERROR: Could not find a version that satisfies the requirement aalib (from versions: none)
ERROR: No matching distribution found for aalib
Run Code Online (Sandbox Code Playgroud)
但它实际上是错误的包名,确保pip search(在撰写本文时服务已禁用),或谷歌,或在pypi 网站上搜索以获取准确的包名:
然后安装成功:
$ python3.8 -m pip install python-aalib
Collecting python-aalib
Downloading python-aalib-0.3.2.tar.gz (14 kB)
...
Run Code Online (Sandbox Code Playgroud)
如前所述pip --help:
$ python3.8 -m pip --help
...
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
Run Code Online (Sandbox Code Playgroud)
为了有系统地找出根本原因而不是依靠运气,您可以附加命令-vvv选项pip以查看详细信息,例如:
$ python3.8 -u -m pip install aalib -vvv
User install by explicit request
Created temporary directory: /tmp/pip-ephem-wheel-cache-b3ghm9eb
Created temporary directory: /tmp/pip-req-tracker-ygwnj94r
Initialized build tracking at /tmp/pip-req-tracker-ygwnj94r
Created build tracker: /tmp/pip-req-tracker-ygwnj94r
Entered build tracker: /tmp/pip-req-tracker-ygwnj94r
Created temporary directory: /tmp/pip-install-jfurrdbb
1 location(s) to search for versions of aalib:
* https://pypi.org/simple/aalib/
Fetching project page and analyzing links: https://pypi.org/simple/aalib/
Getting page https://pypi.org/simple/aalib/
Found index url https://pypi.org/simple
Getting credentials from keyring for https://pypi.org/simple
Getting credentials from keyring for pypi.org
Looking up "https://pypi.org/simple/aalib/" in the cache
Request header has "max_age" as 0, cache bypassed
Starting new HTTPS connection (1): pypi.org:443
https://pypi.org:443 "GET /simple/aalib/ HTTP/1.1" 404 13
[hole] Status code 404 not in (200, 203, 300, 301)
Could not fetch URL https://pypi.org/simple/aalib/: 404 Client Error: Not Found for url: https://pypi.org/simple/aalib/ - skipping
Given no hashes to check 0 links for project 'aalib': discarding no candidates
ERROR: Could not find a version that satisfies the requirement aalib (from versions: none)
Cleaning up...
Removed build tracker: '/tmp/pip-req-tracker-ygwnj94r'
ERROR: No matching distribution found for aalib
Exception information:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py", line 186, in _main
status = self.run(options, args)
File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 357, in run
resolver.resolve(requirement_set)
File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 177, in resolve
discovered_reqs.extend(self._resolve_one(requirement_set, req))
File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 333, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 281, in _get_abstract_dist_for
req.populate_link(self.finder, upgrade_allowed, require_hashes)
File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 249, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 926, in find_requirement
raise DistributionNotFound(
pip._internal.exceptions.DistributionNotFound: No matching distribution found for aalib
Run Code Online (Sandbox Code Playgroud)
从上面的日志中,很明显https://pypi.org/simple/aalib/没有找到URL 404。然后你就可以猜出导致404的可能原因,即错误的包名。另一件事是我可以修改pip模块的相关python文件以使用上述日志进一步调试。要编辑.whl文件,您可以使用wheel命令 tounpack和pack。
并非总是如此,但在某些情况下,该包已经存在。例如 - getpass。它没有被“pip list”列出,但可以导入和使用:
如果我尝试 pip install getpass,我会收到以下错误:“找不到满足 getpass 要求的版本”
| 归档时间: |
|
| 查看次数: |
550755 次 |
| 最近记录: |