【问题标题】:How to package python script to send to others如何打包python脚本发送给其他人
【发布时间】:2017-06-21 04:11:47
【问题描述】:

我有一个依赖多个脚本的程序,每个脚本使用多个模块。该程序可以自行运行,但如果我将其发送到另一台计算机,除非它们安装了所有依赖项,否则它将失败。

有没有办法以编程方式安装所有必需的模块,以便可以轻松地将其传递给新用户?我试图找到将脚本打包为 exe 文件的教程,但这些教程对我来说太混乱或失败了。

无论哪种方式,我只是在寻找一种简单的方法来分享我的程序,我们将不胜感激!

【问题讨论】:

标签: python package


【解决方案1】:

您必须在 setup.py 文件的 install_requires 键中指定依赖项:

from setuptools import setup

setup(name='funniest',
      version='0.1',
      description='The funniest joke in the world',
      url='http://github.com/storborg/funniest',
      author='Flying Circus',
      author_email='flyingcircus@example.com',
      license='MIT',
      packages=['funniest'],
      install_requires=[
          'markdown',
      ],
      zip_safe=False)

在上面的示例中,它将检查/安装包 markdown。 你可能想看看这个方法:

http://python-packaging.readthedocs.io/en/latest/index.html

【讨论】:

    猜你喜欢
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多