首页 > 解决方案 > 如何使用 pip 单独安装 python 包及其依赖项以允许单独的 pip 选项?

问题描述

我有(一个分支)一个 python 包,需要一个额外的选项才能安装。我发现这可以使用--global-optionpip 选项来完成:

pip install --global-option="cythonize" git+https://github.com/blaiseli/pybedtools.git@fix_missing_headers

但是,此选项会使此软件包的依赖项的安装失败,因为它也适用于它们,并且无法识别。

如何先单独安装依赖项?

类似的东西pip install --only-deps <some package>似乎不存在。


编辑

正如这个答案中所建议的,我尝试在我的包的分支中设置一个别名,以便cythonize在安装之前运行命令:

$ cat setup.cfg 
[wheel]
universal = 1
[nosetests]
detailed-errors = 1
doctest-extension = .pyx .py
[aliases]
install = cythonize install

奇怪的是,该cythonize命令被正确处理:

$ python3.7 setup.py cythonize
running cythonize
Compiling pybedtools/cbedtools.pyx because it changed.
Compiling pybedtools/featurefuncs.pyx because it changed.
[1/2] Cythonizing pybedtools/cbedtools.pyx
/usr/local/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/bli/src/pybedtools/pybedtools/cbedtools.pxd
  tree = Parsing.p_module(s, pxd, full_module_name)
[2/2] Cythonizing pybedtools/featurefuncs.pyx
/usr/local/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/bli/src/pybedtools/pybedtools/featurefuncs.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

但是当它是别名的一部分时无法识别:

$ python3.7 setup.py install
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'cythonize'

标签: pythonpip

解决方案


与您的其他问题相同,我怀疑cythonizesetuptools命令而不是全局选项

如果确实如此,那么您最好在setup.cfg. 如果您运行python setup.py alias install cythonize install,这应该将以下内容添加到您的setup.cfg

[aliases]
install = cythonize install

稍后运行时pip installpip将遵循此别名,并且该cythonize命令将在该install命令之前执行。


推荐阅读