python 自定义安装脚本并自动安装依赖

自定义安装包

在之前的文章中,我们介绍过如何自定义一个安装包,并制作自己的启动脚本,但是之前的步骤中存在一个问题,就是如果我们自定义了Install脚本,将无法自动安装依赖。

解决方案

自动安装依赖的脚本实际是在Install类中调用了easy_install,我们可以在我们的脚本中调用该方法实现手动安装依赖的效果。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
setup(name='MoYao-Raspberry-Controller',
version=moyao.__version__,
description='Python Distribution Utilities',
author='Kevin Kong',
author_email='kfxw2007@163.com',
license='http://www.apache.org/licenses/LICENSE-2.0.html',
url='',
data_files=data_files,
packages=find_packages(),
package_dir={'%s' % 'moyao': 'moyao'},
include_package_data=True,
python_requires='>=3.5',
install_requires=[
"pywifi",
"autils",
"picamera",
"configparser",
"pyserial",
"pexpect",
"requests",
"pywifi",
"paho-mqtt",
"qiniu"
],
cmdclass={
'install': InstallCommand,
},
)

在Install脚本中执行安装依赖:

1
2
3
4
def run(self):
install.run(self)
install.do_egg_install(self)
...
你的支持我的动力