安装程序: 现在,对于其中一个额外(我们称之为extra1
),我需要调用一个非python库的二进制文件X
。
问题1:如何make
使用setuptools / distutils在包的构建过程中运行终端命令(即我的情况)?
问题2:如何确保只有extra1
在安装过程中指定相应的终端命令时才执行这样的终端命令?
例:
pip install my_package
,则不会发生这种附加的图库编辑X
。pip install my_package [extra1]
,模块X
需要编译,所以相应的二进制文件将被创建并在目标机器上可用。发布于 2018-03-15 21:27:29
这些文档在setup.py和pip之间的交互过程中非常稀少,但是你应该能够做到这样:
import subprocess
from setuptools import Command
from setuptools import setup
class CustomInstall(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
subprocess.call(
['touch',
'/home/{{YOUR_USERNAME}}/'
'and_thats_why_you_should_never_run_pip_as_sudo']
)
setup(
name='hack',
version='0.1',
cmdclass={'customcommand': CustomInstall}
)
该命令是在主要安装序列之后执行的,因此根据您尝试执行的操作,可能无法正常工作。请参阅详细的pip安装输出:
(.venv) ayoon:tmp$ pip install -vvv --install-option="customcommand" .
/home/ayoon/tmp/.venv/lib/python3.6/site-packages/pip/commands/install.py:194: UserWarning: Disabling all use of wheels due to the use of --build-options / -
-global-options / --install-options.
cmdoptions.check_install_build_global(options)
Processing /home/ayoon/tmp
Running setup.py (path:/tmp/pip-j57ovc7i-build/setup.py) egg_info for package from file:///home/ayoon/tmp
Running command python setup.py egg_info
running egg_info
creating pip-egg-info/hack.egg-info
writing pip-egg-info/hack.egg-info/PKG-INFO
writing dependency_links to pip-egg-info/hack.egg-info/dependency_links.txt
writing top-level names to pip-egg-info/hack.egg-info/top_level.txt
writing manifest file 'pip-egg-info/hack.egg-info/SOURCES.txt'
reading manifest file 'pip-egg-info/hack.egg-info/SOURCES.txt'
writing manifest file 'pip-egg-info/hack.egg-info/SOURCES.txt'
Source in /tmp/pip-j57ovc7i-build has version 0.1, which satisfies requirement hack==0.1 from file:///home/ayoon/tmp
Could not parse version from link: file:///home/ayoon/tmp
Installing collected packages: hack
Running setup.py install for hack ... Running command /home/ayoon/tmp/.venv/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-j57ovc7
i-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --
record /tmp/pip-_8hbltc6-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ayoon/tmp/.venv/include/site/python3
.6/hack customcommand
running install
running build
running install_egg_info
running egg_info
writing hack.egg-info/PKG-INFO
writing dependency_links to hack.egg-info/dependency_links.txt
writing top-level names to hack.egg-info/top_level.txt
reading manifest file 'hack.egg-info/SOURCES.txt'
writing manifest file 'hack.egg-info/SOURCES.txt'
Copying hack.egg-info to /home/ayoon/tmp/.venv/lib/python3.6/site-packages/hack-0.1-py3.6.egg-info
running install_scripts
writing list of installed files to '/tmp/pip-_8hbltc6-record/install-record.txt'
running customcommand
done
Removing source in /tmp/pip-j57ovc7i-build
Successfully installed hack-0.1
https://stackoverflow.com/questions/-100005260
复制相似问题