【问题标题】:Pipreqs requirements.txt is not correctPipreqs requirements.txt 不正确
【发布时间】:2021-02-14 04:47:51
【问题描述】:

您好,我在使用 Python 中的 pipreqs 库时遇到问题。它不会生成正确的requirements.txt 文件。我正在使用 Python 虚拟环境,我安装的唯一软件包是 pipreqsselenium with

pip install pipreqs
pip install selenium

项目结构:

MyProject
 |- test.py

test.py只有一行:

from selenium import webdriver

我做的第一件事

pipreqs ./

我收到了错误UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 3474: character maps to <undefined> 我设法通过使用解决了

pipreqs ./ --encoding=utf-8

但是现在生成的requirements.txt 不符合我的预期。在我看来,它应该等于:

selenium==1.341.0

但它等于:

brotli==1.0.9
cryptography==3.2.1
ipaddr==2.2.0
lxml==4.6.1
mock==4.0.2
ordereddict==1.1
protobuf==3.13.0
pyOpenSSL==19.1.0
simplejson==3.17.2

现在,当我尝试克隆此代码并执行 pip install -r requirements.txt 时,它不会安装 selenium 并且代码不会运行。

这里发生了什么?

【问题讨论】:

    标签: python package requirements.txt


    【解决方案1】:

    所以我遇到的问题是我的实际工作空间是:

    MyProject
     |- .venv   // <- My Python Virtual Environment
     |- test.py
    

    我的 Python 虚拟环境在我的项目文件夹中,所以当我运行命令时

    pipreqs ./
    

    它正在查看文件夹中所有文件的所有依赖项(包括我的虚拟环境),这就是为什么它会生成一个奇怪的 requirements.txt 文件。

    为了解决这个问题,我使用了 pipreqs 的选项 --ignore

    pipreqs ./ --ignore .venv
    

    而生成的requirements.txt是:

    selenium==3.141.0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      • 2018-01-10
      • 1970-01-01
      • 2022-12-14
      • 2021-06-12
      相关资源
      最近更新 更多