【问题标题】:python3 requirements.txt file shows unwanted packagespython3 requirements.txt 文件显示不需要的包
【发布时间】:2018-12-22 13:58:26
【问题描述】:

我使用 python3 -m venv . 创建了一个虚拟环境 然后我使用命令pip freeze requirements.txt 来获取包列表。

下面是文件 requirements.txt 的内容

apsw==3.16.2.post1
asn1crypto==0.24.0
beautifulsoup4==4.6.0
chardet==3.0.4
CherryPy==8.9.1
configparser==3.5.0
cryptography==2.1.4
cssselect==1.0.3
cssutils==1.0.2
dnspython==1.15.0
enum34==1.1.6
feedparser==5.2.1
flake8==3.5.0
html5-parser==0.4.4
html5lib==0.999999999
idna==2.6
ipaddress==1.0.17
jedi==0.11.1
keyring==10.6.0
keyrings.alt==3.0
lxml==4.2.1
Markdown==2.6.9
mccabe==0.6.1
mechanize==0.2.5
msgpack==0.5.6
mysql-connector-python==8.0.6
mysql-utilities==1.6.4
netifaces==0.10.4
numpy==1.14.5
olefile==0.45.1
paramiko==2.0.0
parso==0.1.1
pep8==1.7.1
pexpect==4.2.1
Pillow==5.1.0
pyasn1==0.4.2
pycodestyle==2.3.1
pycrypto==2.6.1
pyflakes==1.6.0
Pygments==2.2.0
pygobject==3.26.1
pyodbc==4.0.17
pyOpenSSL==17.5.0
pyparsing==2.2.0
pysqlite==2.7.0
python-dateutil==2.6.1
pyxdg==0.25
PyYAML==3.12
regex==2017.12.12
repoze.lru==0.7
Routes==2.4.1
SecretStorage==2.3.1
simplejson==3.13.2
six==1.11.0
unity-lens-photos==1.0
uTidylib==0.3
virtualenv==15.2.0
webencodings==0.5
WebOb==1.7.3

我不确定该项目需要哪些软件包。该项目似乎不需要许多软件包。为什么 requirements.txt 显示了这么多包?如何解决这个问题,以便 requirements.txt 显示特定项目所需的包列表?(我可以手动删除它们,但为什么它们首先显示在 requirements.txt 中?)

注意:以前我使用sudo apt-get install python3-package-name 安装软件包。 这是否导致软件包的永久安装并在通过python -m venv . 创建的虚拟环境中重复?或者这些是默认包和强制包?

操作系统:ubuntu 18.04, 蟒蛇版本:3.6.5, 点子版本:9.0.1

【问题讨论】:

  • pip freeze 只是转储当前 virtualenv 中安装的所有软件包的列表(如果没有 virtualenv 处于活动状态,则转储系统范围)。没有魔法或聪明的行为。

标签: python python-3.x pip requirements.txt python-venv


【解决方案1】:

我们可以使用“-l”参数仅列出本地安装的包。 $ pip freeze -l

参考:https://pip.pypa.io/en/stable/reference/pip_freeze/

【讨论】:

    【解决方案2】:

    这是使用 pip 和 requirements.txt 管理包的典型问题。新的Pipenv 项目通过制作一个“lockfile”来解决这个问题,其中包含从开发角度来看您实际使用的包的所有依赖项。这在 Bundler 和 npm 等其他语言的包管理器中很常见。

    所以,如果这个 requirements.txt 变得难以管理,我建议迁移到 Pipenv。

    【讨论】:

      猜你喜欢
      • 2020-11-04
      • 1970-01-01
      • 2021-04-15
      • 2019-03-08
      • 2012-03-29
      • 1970-01-01
      • 2018-07-15
      • 2021-09-08
      • 1970-01-01
      相关资源
      最近更新 更多