使用 pip 安装时会忽略 install_requires 中列出的软件包

时间:2021-03-23 11:56:49

标签: python setup.py install-requires

可能有人在某处询问并回答过,但我搜索了很多,但没有找到在哪里。如有重复,请见谅。

我有一个依赖于 pyyaml 的项目 (https://github.com/PyFPGA/openflow):

setup(
    ...,
    install_requires=['pyyaml']
)

pip3 install -e . 一起安装时,未安装 pyyaml。可以通过以下方式验证:

$ virtualenv venv1 --python=python3
$ venv1/bin/python3 -m pip install -e .

Obtaining file:///home/ram/repos_ram/PyFPGA/openflow
    ERROR: Command errored out with exit status 1:
     command: /home/ram/repos_ram/PyFPGA/openflow/venv1/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/ram/repos_ram/PyFPGA/openflow/setup.py'"'"'; __file__='"'"'/home/ram/repos_ram/PyFPGA/openflow/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-bzc9au74
         cwd: /home/ram/repos_ram/PyFPGA/openflow/
    Complete output (9 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/ram/repos_ram/PyFPGA/openflow/setup.py", line 3, in <module>
        import openflow
      File "/home/ram/repos_ram/PyFPGA/openflow/openflow/__init__.py", line 6, in <module>
        from openflow.configure import ConfigureTools
      File "/home/ram/repos_ram/PyFPGA/openflow/openflow/configure.py", line 25, in <module>
        from yaml import safe_load, dump
    ImportError: No module named 'yaml'
    ----------------------------------------
WARNING: Discarding file:///home/ram/repos_ram/PyFPGA/openflow. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ram@ram-notebook2:~/repos_ram/PyFPGA/openflow$ 
ram@ram-notebook2:~/repos_ram/PyFPGA/openflow$ 
ram@ram-notebook2:~/repos_ram/PyFPGA/openflow$ venv1/bin/python3 -m pip install -e .
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
Obtaining file:///home/ram/repos_ram/PyFPGA/openflow
    ERROR: Command errored out with exit status 1:
     command: /home/ram/repos_ram/PyFPGA/openflow/venv1/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/ram/repos_ram/PyFPGA/openflow/setup.py'"'"'; __file__='"'"'/home/ram/repos_ram/PyFPGA/openflow/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-0r0b115b
         cwd: /home/ram/repos_ram/PyFPGA/openflow/
    Complete output (9 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/ram/repos_ram/PyFPGA/openflow/setup.py", line 3, in <module>
        import openflow
      File "/home/ram/repos_ram/PyFPGA/openflow/openflow/__init__.py", line 6, in <module>
        from openflow.configure import ConfigureTools
      File "/home/ram/repos_ram/PyFPGA/openflow/openflow/configure.py", line 25, in <module>
        from yaml import safe_load, dump
    ImportError: No module named 'yaml'
    ----------------------------------------
WARNING: Discarding file:///home/ram/repos_ram/PyFPGA/openflow. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

它在我的计算机上失败(我知道,python3.5 已弃用),但在使用 ubuntu-latest(使用 Python 3.6、3.7、3.8 和 3.9)的 GitHub 操作 (https://github.com/PyFPGA/openflow/pull/7/checks?check_run_id=2171303843) 中也失败。< /p>

我不想要解决方法。我了解 install_requires 是指定强制依赖项的方法。我错了吗?

提前致谢 罗德里戈

1 个答案:

答案 0 :(得分:0)

我解决了我的问题。它与 install_requires 无关。为了读取我的项目的版本,我导入了导入 yaml(尚未安装)的文件。因此,我避免在 setup.py 中导入我的库。