python - pip 没有从requirements.txt 安装包,而是从命令安装包

标签 python pip

我有两个与需求相关的文件。我在调用时收到此错误:

$ pip install -r requirements.txt --no-index --find-links file:///tmp/packages

错误:

Looking in links: file:///tmp/packages
Requirement already satisfied: asgiref==3.2.3 in d:\virtual_envs\scolarte\lib\site-packages (from -r requirements-dev.txt (line 1)) (3.2.3)
Collecting boto3==1.12.0 (from -r requirements-dev.txt (line 2))
  Url 'file:///tmp/packages' is ignored: it is neither a file nor a directory.
  Could not find a version that satisfies the requirement boto3==1.12.0 (from -r requirements-dev.txt (line 2)) (from versions: )
No matching distribution found for boto3==1.12.0 (from -r requirements-dev.txt (line 2))

但是调用时安装的包:

pip install boto3==1.12.0

为什么?

a) 要求.txt:

-r requirements-dev.txt
gunicorn
psycopg2

b) 需求-dev.txt

asgiref==3.2.3
boto3==1.12.0
botocore==1.14.16
defusedxml==0.6.0
diff-match-patch==20181111
dj-database-url==0.5.0
dj-static==0.0.6
Django==3.0.3
django-crispy-forms==1.8.1
django-import-export==2.0.1
django-sendgrid-v5==0.8.1
django-storages==1.9.1
djangorestframework==3.11.0
docutils==0.15.2
et-xmlfile==1.0.1
future==0.18.2
jdcal==1.4.1
jmespath==0.9.4
MarkupPy==1.14
numpy==1.18.1
odfpy==1.4.1
openpyxl==3.0.3
pandas==0.25.3
Pillow==7.0.0
python-dateutil==2.8.1
python-decouple==3.3
python-http-client==3.2.4
pytz==2019.3
PyYAML==5.3
s3transfer==0.3.3
sendgrid==6.1.1
six==1.14.0
sqlparse==0.3.0
static3==0.7.0
tablib==0.14.0
urllib3==1.25.8
xlrd==1.2.0
xlwt==1.3.0

最佳答案

当您使用时

pip install boto3==1.12.0

您正在从 PyPI (The Python Package Index) 安装。而通过使用--no-index选项

pip install -r requirements.txt --no-index --find-links file:///tmp/packages

你明确告诉pip不要在 PyPI 中查找它。

填写PyPI Documentation

--no-index

Ignore package index (only looking at --find-links URLs instead).

-f, --find-links <url>

If a url or path to an html file, then parse for links to archives. If a local path or file:// url that’s a directory, then look for archives in the directory listing.

同时在 how pip finds packages (强调我的)

pip looks for packages in a number of places: on PyPI (if not disabled via --no-index), in the local filesystem, and in any additional repositories specified via --find-links or --index-url. There is no ordering in the locations that are searched. Rather they are all checked, and the “best” match for the requirements (in terms of version number - see PEP 440 for details) is selected.

关于python - pip 没有从requirements.txt 安装包,而是从命令安装包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60241017/

相关文章:

python - Redis - 获取字典 HMGET 中的值

python - pip install mysqlclient 返回 "fatal error C1083: Cannot open file: ' mysql.h' : No such file or directory

python - 调用 type(1/2) 返回整数?

python - 没有 shell 转义序列的 git show/log,用于 python sh

pip - 使用 tox 安装 extra_requires

python - 如何指定python pip的安装顺序?

python - 使用 pip 安装 google-cloud 失败

github - 有没有办法在 Github wiki 中显示来自 requirements.txt 的过时依赖项?

Python 2.7,在字符串的最后两位数字前添加破折号

python - 将 pandas 时间序列数据导入本地主机上的 mysql 数据库时出错