擅长:python、mysql、java
<p>不幸的是,这些文档在设置.py还有皮普,但你应该能做这样的事:</p>
<pre><code>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}
)
</code></pre>
<p>这为您提供了一个使用命令运行任意代码的钩子,还支持各种自定义选项解析(此处未演示)。在</p>
<p>将此文件放入<code>setup.py</code>文件中,然后尝试以下操作:</p>
<p><code>pip install install-option="customcommand" .</code></p>
<p>请注意,此命令是在主安装序列之后执行的,因此根据您正在尝试执行的操作,它可能不起作用。请参阅详细的pip安装输出:</p>
^{pr2}$