How to install distutils packages using distutils api or setuptools api

◇◆丶佛笑我妖孽 提交于 2019-12-03 20:37:01

You can call a command line program within your Python program using the subprocess module:

import subprocess
subprocess.call('python setup.py install')

However, how much control do you have over the environment that this install will be run? If it is a package that you are distributing, you will likely have issues no matter what solution people propose. How will you handle cases of needing root access (e.g. sudo python setup.py install)?

You may consider looking into Paver since it provides an API that is in some ways an extension of setuptools.

zerokspot.recipe.distutils is fundamentally broken in that it adds a dependency on zc.buildout in it's setup.py, as follows:

  1. setup.py imports get_version from zerokspot.recipe.distutils
  2. All of zerokspot.recipe.distutils is defined in it's __init__.py, including get_version
  3. __init__.py in zerokspot.recipe.distutils imports zc.buildout

Why the author defines get_version is a mystery to me; best practice keeps a simple version string in setup.py itself and lets setuptools deal with dev versions (through setup.cfg), and distutils for version metadata extraction.

Generally it is not a good idea to import the whole package in setup.py as that would require all the package dependencies to be present at install time. Obviously the author of the package has zc.buildout installed as a site-wide package and didn't notice his oversight.

Your best bet is to fork the package on github, remove the get_version dependency, and propose the change to the original author while you use your fork instead.

Are you sure you don't want to just generate a bdist?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!