如何生成包含其他python脚本的python脚本的python exe

Rit*_*itz 5 python py2exe

我正在尝试为python脚本"cnss_image_loader.py"生成一个exe,它在同一个文件夹中导入其他python脚本(见下文),现在我尝试使用命令生成"cnss_image_loader.exe" python setup.py py2exe(参见下面的输出)并运行到低于错误,不确定它们是否是真正的问题但运行生成的exe时会抛出下面显示的错误

题:

1.我可以不使用py2exe生成可执行文件吗?

2. 任何人都可以准确指出我所缺少的内容并提供生成exe的指导吗?

3.有更好的方法来生成python可执行文件吗?

错误:-

C:\Dropbox\py2exe\dist>cnss_image_loader.exe
Traceback (most recent call last):
  File "cnss_image_loader.py", line 9, in <module>
  File "android_dl.pyc", line 2, in <module>
  File "pip\__init__.pyc", line 14, in <module>
  File "pip\utils\__init__.pyc", line 22, in <module>
  File "pip\compat\__init__.pyc", line 26, in <module>
ImportError: No module named ipaddr
Run Code Online (Sandbox Code Playgroud)

目录结构: - py2exe

cnss_image_loader.py

from android_dl import *
from alpaca import *
Run Code Online (Sandbox Code Playgroud)

setup.py

from distutils.core import setup
import py2exe 
setup(console=['cnss_image_loader.py'])
Run Code Online (Sandbox Code Playgroud)

python setup.py py2exe

The following modules appear to be missing
['Carbon', 'Carbon.Files', 'ElementC14N', 'OpenSSL.SSL', 'Pyrex.Distutils.build_ext', '_frozen_importlib', '_imp', '_manylinux', '_posixsubprocess', '_scproxy', '_sysconfigdata', 'backports.ssl_match_hostname', 'builtins', 'certifi', 'charade.universaldetector', 'chardet', 'chardet.universaldetector', 'configparser', 'datrie', 'genshi.core', 'html', 'html.entities', 'html.parser', 'http', 'http.client', 'http.cookies', 'importlib.machinery', 'importlib.util', 'ipaddr', 'ipaddress', 'java', 'lxml', 'lxml.etree', 'lzma', 'ndg.httpsclient.ssl_peer_verification', 'ndg.httpsclient.subj_alt_name', 'ordereddict', 'packages.six.moves', 'packages.ssl_match_hostname.CertificateError', 'packages.ssl_match_hostname.match_hostname', 'packages.urllib3.util.Timeout', 'packages.urllib3.util.parse_url', 'pip._vendor.six.moves.urllib', 'pyasn1.codec.der', 'pyasn1.type', 'queue', 'redis', 'reprlib', 'serial', 'serial.tools.list_ports', 'serializer.serialize', 'simplejson', 'sitecustomize', 'socks', 'tree
builders.getTreeBuilder', 'treewalkers.getTreeWalker', 'trie.Trie', 'urllib.error', 'urllib.parse', 'urllib.request', 'urllib3', 'urllib3.packages.backports.makefile', 'usercustomize', 'xmlrpc.client']

*** binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.

Make sure you have the license if you distribute any of them, and
make sure you don't distribute files belonging to the operating system.

   OLEAUT32.dll - C:\WINDOWS\system32\OLEAUT32.dll
   USER32.dll - C:\WINDOWS\system32\USER32.dll
   IMM32.dll - C:\WINDOWS\system32\IMM32.dll
   SHELL32.dll - C:\WINDOWS\system32\SHELL32.dll
   ole32.dll - C:\WINDOWS\system32\ole32.dll
   COMDLG32.dll - C:\WINDOWS\system32\COMDLG32.dll
   COMCTL32.dll - C:\WINDOWS\system32\COMCTL32.dll
   ADVAPI32.dll - C:\WINDOWS\system32\ADVAPI32.dll
   NETAPI32.dll - C:\WINDOWS\system32\NETAPI32.dll
   WS2_32.dll - C:\WINDOWS\system32\WS2_32.dll
   GDI32.dll - C:\WINDOWS\system32\GDI32.dll
   VERSION.dll - C:\WINDOWS\system32\VERSION.dll
   KERNEL32.dll - C:\WINDOWS\system32\KERNEL32.dll
   ntdll.dll - C:\WINDOWS\system32\ntdll.dll
Run Code Online (Sandbox Code Playgroud)

Kam*_*him 0

我个人一直在使用的是 pyinstaller。您可以在 cmd 上使用以下命令为 python 安装它:

pip install pyinstaller
Run Code Online (Sandbox Code Playgroud)

安装后可以通过以下方式使用:

python -m pyinstaller main.py
Run Code Online (Sandbox Code Playgroud)

其中 main.py 是你的 python 模块。--icon您还可以使用以下选项为您的应用程序提供图标文件

python -m pyinstaller --icon=hi.ico main.py
Run Code Online (Sandbox Code Playgroud)

--onefile您还可以使用以下选项创建独立应用程序:

python -m pyinstaller --onefile main.py
Run Code Online (Sandbox Code Playgroud)

您可以在他们的网站https://www.pyinstaller.org或他们的手册https://pyinstaller.readthedocs.io/en/stable/上找到更多信息