python程序打包

    xiaoxiao2021-12-03  15

    在python程序中,一个.py文件被当作一个模块,在各个模块中定义了不同的函数。当我们要使用某一个模块中的某一个函数时,首先须将这个模块导入,否则就会出现函数未定义的情况. (1) python文件, test.py: def testFunc(): print("test successfully!") testFunc() 引用: from test import testFunc (2) 新建一个 setup.py文件代码如下: from distutils.core import setup setup(  name='test',  #这个是最终打包的文件名  version='1.0.0',  py_modules=['test'], #要打包哪些,.py文件,  ) 运行如下命令: python setup.py sdist 这样在文件夹中就多出了几个文件,在dist文件夹中的,test-1.0.0.tar.gz就是我们的发布包了 (3) 安装包到本地副本中: 解压上面生成的文件,执行下面命令: sudo python setup.py install 路径为:/usr/local/lib/python2.7/dist-packages ,该目录下有py,pyc文件,经过测试是可以删除py文件的。 注意:如果安装了多个python版本,如python2.7和python3,默认的是安装的python3,要安装到python2.7的情况下,要显式指定python2.7的路径: /usr/local/lib/python2.7 setup.py install 卸载: python setup.py uninstall setup函数各参数详解: >>python setup.py --help   --name              包名称   --version (-V)      包版本   --author            程序的作者   --author_email      程序的作者的邮箱地址   --maintainer        维护者   --maintainer_email  维护者的邮箱地址   --url               程序的官网地址   --license           程序的授权信息   --description       程序的简单描述   --long_description  程序的详细描述   --platforms         程序适用的软件平台列表   --classifiers       程序的所属分类列表   --keywords          程序的关键字列表   --packages  需要打包的目录列表   --py_modules  需要打包的python文件列表   --download_url  程序的下载地址   --cmdclass     --data_files  打包时需要打包的数据文件,如图片,配置文件等   --scripts  安装时需要执行的脚步列表 setup.py打包命令各参数详解: >>python setup.py --help-commands   --python setup.py build     # 仅编译不安装   --python setup.py install    #安装到python安装目录的lib下   --python setup.py sdist      #生成压缩包(zip/tar.gz)   --python setup.py bdist_wininst  #生成NT平台安装包(.exe)   --python setup.py bdist_rpm #生成rpm包 或者直接"bdist 包格式",格式如下: #python setup.py bdist --help-formats    --formats=rpm      RPM distribution   --formats=gztar    gzip'ed tar file   --formats=bztar    bzip2'ed tar file   --formats=ztar     compressed tar file   --formats=tar      tar file   --formats=wininst  Windows executable installer   --formats=zip      ZIP file 如: python setup.py bdist --formats=zip  等价于  python setup.py sdist python setup.py sdist cd dist pip install *.tar.gz 使用 pip install automl-0.4.tar.gz --upgrade 来更新 说明:安装到指定python(如python2,python3等),可以配置pip,或者更改环境变量中的python路径。
    转载请注明原文地址: https://ju.6miu.com/read-679918.html

    最新回复(0)