日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python打包工具哪个好用_python打包工具比较

發布時間:2023/12/18 python 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python打包工具哪个好用_python打包工具比较 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前一段用python寫了點小工具,希望能給同事用,這里總結一下python的打包以及構建的方法。

首先是一些需要安裝依賴包的方法,這也是比較推薦的正統的方法。

1.setuptools or pip

在setup.py文件中寫明依賴的庫和版本,注意需要提前安裝setuptools,然后運行

python setup.py install

文件大致如下,這里是selenium的安裝文件:

import sys

from distutils.command.install import INSTALL_SCHEMES

from os.path import dirname, join, isfile, abspath

from setuptools import setup

from setuptools.command.install import install

from shutil import copy

for scheme in INSTALL_SCHEMES.values():

scheme['data'] = scheme['purelib']

setup_args = {

'cmdclass': {'install': install},

'name': 'selenium',

'version': "2.52.0",

'description': 'Python bindings for Selenium',

'long_description': open(join(abspath(dirname(__file__)), "py", "README.rst")).read(),

'url': 'https://github.com/SeleniumHQ/selenium/',

'classifiers': ['Development Status :: 5 - Production/Stable',

'Intended Audience :: Developers',

'License :: OSI Approved :: Apache Software License',

'Operating System :: POSIX',

'Operating System :: Microsoft :: Windows',

'Operating System :: MacOS :: MacOS X',

'Topic :: Software Development :: Testing',

'Topic :: Software Development :: Libraries',

'Programming Language :: Python',

'Programming Language :: Python :: 2.6',

'Programming Language :: Python :: 2.7',

'Programming Language :: Python :: 3.2',

'Programming Language :: Python :: 3.3',

'Programming Language :: Python :: 3.4'],

'package_dir': {

'selenium': 'py/selenium',

'selenium.common': 'py/selenium/common',

'selenium.webdriver': 'py/selenium/webdriver',

},

'packages': ['selenium',

'selenium.common',

'selenium.webdriver',

'selenium.webdriver.android',

'selenium.webdriver.chrome',

'selenium.webdriver.common',

'selenium.webdriver.common.html5',

'selenium.webdriver.support',

'selenium.webdriver.firefox',

'selenium.webdriver.ie',

'selenium.webdriver.edge',

'selenium.webdriver.opera',

'selenium.webdriver.phantomjs',

'selenium.webdriver.remote',

'selenium.webdriver.support', ],

'package_data': {

'selenium.webdriver.firefox': ['*.xpi', 'webdriver_prefs.json'],

},

'data_files': [('selenium/webdriver/firefox/x86', ['py/selenium/webdriver/firefox/x86/x_ignore_nofocus.so']),

('selenium/webdriver/firefox/amd64', ['py/selenium/webdriver/firefox/amd64/x_ignore_nofocus.so'])],

'include_package_data': True,

'zip_safe': False

}

setup(**setup_args)

如果雙方都有pip工具,直接使用命令導出依賴并安裝即可

$pip freeze > requirements.txt

$pip install -r requirements.txt

2.pyintaller or cx_Freeze

pyintaller現在已經支持Python 2.7, 3.3–3.5。工具可以自動搜索依賴,并將文件打包成單獨的exe。命令也非常簡單,當然還有自己可以選擇的一些命令,例如生成目錄還是單個文件,生成路徑等等:

具體的安裝和使用參考

https://pyinstaller.readthedocs.io/en/stable/

最簡單的使用如下:

pyinstaller myscript.py

PS:如果在linux下使用,需要root權限,因為會涉及到文件的創建,讀寫等等。同時,這個打包工具使用動態依賴庫,需要打包方和使用方是相同的操作系統。

cx_freeze類似,這里不贅述。

3.zip

如果依賴的第三方庫是純python實現,python2.6+/python3支持直接運行zip文件。這里參考了知乎的回答。

首先子啊zip文件根目錄建立一個main.py 文件,一個required目錄。

把依賴的非標準模塊從你自己的開發環境下的site-packages下拷貝到zip目錄的required下

在main.py中利用 file 變量拿到執行路徑,拼接出 site-packages 的絕對路徑,添加到 sys.path 中,方法大致如下:

import sys

import os

path =os.path.realpath(__file__)

path = os.path.dirname(path)

path +=os.sep+"required"+os.sep+"site-packages"

sys.path.append(path)

然后加載非標準模塊,執行原來的代碼即可。   這里有個限制:有一些操作不能執行,例如不能有操作文件的指令,因為文件還在zip里沒有解壓。      PSS:最后提一個docker,因為沒有使用過,這里暫且不講了。

總結

以上是生活随笔為你收集整理的python打包工具哪个好用_python打包工具比较的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。