Pip Requirements.txt --global-option 导致其他软件包安装错误。 "option not recognized"

Pip Requirements.txt --global-option causing installation errors with other packages. "option not recognized"

我在 requirements.txt 文件的 --global-option 和 --install-option 设置方面遇到困难。为一个库指定选项导致其他库安装失败。

我正在尝试安装 Python 库 "grab" 和 "pycurl"。我需要指定使用选项安装 pycurl:“--with-nss”。我可以在完全干净的虚拟环境中复制错误。

在 requirements.txt 的新虚拟环境中包含:

grab==0.6.25
pycurl==7.43.0 --install-option='--with-nss'

然后安装:

pip install -r requirements.txt

会出现以下错误。

Installing collected packages: lxml, pycurl, pytils, six, user-agent, weblib, selection, grab
  Running setup.py install for lxml ... done
  Running setup.py install for pycurl ... done
  Running setup.py install for pytils ... error
    Complete output from command /home/ec2-user/test/env/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-8GvFzA/pytils/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n
'), __file__, 'exec'))" install --record /tmp/pip-BCG3Wl-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ec2-user/test/env/include/site/python2.7/pytils --with-nss:
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: option --with-nss not recognized

    ----------------------------------------
Command "/home/ec2-user/test/env/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-8GvFzA/pytils/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))"
install --record /tmp/pip-BCG3Wl-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ec2-user/test/env/include/site/python2.7/pytils --with-nss" failed with error code 1 in /tmp/pip-build-8GvF
zA/pytils/

我对根本原因的最佳猜测是选项“--with-nss”被传递给所有需要 pycurl 的库,并阻止了安装。尽管 pycurl 安装工作正常,但 pytils 安装失败。

有没有办法只将安装选项传递给一个库?

我在 Amazon Elastic Beanstalk 实例上进行设置,因此无法手动 运行 requirements.txt 文件的每一行 - 整个安装得到 运行在应用程序启动时。

--global-option 和--install-option 的来源(我认为不应该这样做): How to maintain pip install options in requirements file made by pip freeze? https://github.com/pypa/pip/blob/develop/docs/reference/pip_install.rst#id28

您的问题是因为 EC2 上带有 EB 的 PIP 版本太旧,无法理解您的选择。

  1. 使用 EB 命令将 pip 库更新到最新可用版本:

project_dir/.ebextensions/02-python.config:

...
commands:
  01_upgrade_pip_for_venv:
    command: "/opt/python/run/venv/bin/pip install --upgrade pip"
...
  1. 现在您可以在 requirement.txt 中保留选项,因为新版本的 pip 可以使用它。

project_dir/requirements.txt:

...
pycurl==7.43.0 --global-option="--with-nss"
...
  1. (这可能是多余的)在 EB 控制台用户界面中或通过 eb CLI 使用命令设置选项:

    eb setenv PYCURL_SSL_LIBRARY=nss

  2. 将更改推送到存储库并重建。您可能会遇到错误,因为执行是从外部范围控制的,并且是从旧版本的 PIP 开始的。执行的入口点在 EC2 实例上的应用程序之外,所以我不确定如何在第一次部署时引入可以在挂钩范围内工作的解决方案......但你所要做的就是再次部署,它将使用正确的PIP 的版本,所以它会从现在开始工作,直到下一次重建...