Skip to main content
 首页 » 编程设计

python之安装工具 : how to use the setup() function within a script (no setup specific command line argument)

2025年05月04日10xxx_UU

我正在编写一个工具来自动从 python 项目生成 .egg 文件。 该工具主要是发现一些属性来猜测设置选项(例如版本号等)。

现在我想调用 setup() 函数,使用上下文 bdist_egg。

我是这样做的:

if __name__ == '__main__' 
    project_dir = _get_dir(sys.argv) 
    os.chdir(project_dir) 
    config = _guess_configuration(project_dir) # returns a dict 
 
    sys.argv = ['', 'bdist_egg'] 
    setup(**config) 

然后我可以调用我的脚本

python make_egg.py /path/to/project 

我想跳过 sys.argv = ['', 'bdist_egg'] 部分。有没有办法将设置命令传递给设置函数?

谢谢

请您参考如下方法:

设置(script_args=['bdist_egg'], **config)