Python - 将 python 模块添加到 py Installer 在 Windows 编译的 .exe 文件中

Python - Adding python modules to .exe file compiled by py Installer on Windows

我在 Linux 机器上写了一个简单的 Python 脚本:

#!/bin/python

import wget

wget.download("<url>","/tmp)

并且此代码运行良好,从 apache2 服务器下载文件并将其保存到 /tmp 文件夹

接下来我将位置从“/tmp”更改为 "C:/"。我在 Windows 机器 Python 上安装了 pip、pyInstaller 和 wget 模块。现在通过 pyInstaller 我想制作 .exe 文件,它从服务器下载文件并将其保存到光盘 C:/。 我 运行 cmd 作为管理员:

pyInstaller "test.py"

输出:

70 INFO: PyInstaller: 3.5
70 INFO: Python: 3.7.4
70 INFO: Platform: Windows-10-10.0.18362-SP0
70 INFO: wrote C:\test.spec
70 INFO: UPX is not available.
70 INFO: Extending PYTHONPATH with paths
['C:\', 'C:\']
70 INFO: checking Analysis
70 INFO: Building Analysis because Analysis-00.toc is non existent
70 INFO: Initializing module dependency graph...
91 INFO: Initializing module graph hooks...
184 INFO: Analyzing base_library.zip ...
7545 INFO: running Analysis Analysis-00.toc
7559 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\tester\appdata\local\programs\python\python37-32\python.exe
7919 INFO: Caching module hooks...
8039 INFO: Analyzing C:\test.py
8620 INFO: Loading module hooks...
8620 INFO: Loading module hook "hook-encodings.py"...
8774 INFO: Loading module hook "hook-pydoc.py"...
8807 INFO: Loading module hook "hook-xml.py"...
8983 INFO: Looking for ctypes DLLs
8983 INFO: Analyzing run-time hooks ...
8996 INFO: Looking for dynamic libraries
9720 INFO: Looking for eggs
9720 INFO: Using Python library c:\users\tester\appdata\local\programs\python\python37-32\python37.dll
9720 INFO: Found binding redirects:
[]
9728 INFO: Warnings written to C:\build\test\warn-test.txt
9794 INFO: Graph cross-reference written to C:\build\test\xref-test.html
9855 INFO: checking PYZ
9855 INFO: Building PYZ because PYZ-00.toc is non existent
9855 INFO: Building PYZ (ZlibArchive) C:\build\test\PYZ-00.pyz
10478 INFO: Building PYZ (ZlibArchive) C:\build\test\PYZ-00.pyz completed successfully.
10511 INFO: checking PKG
10511 INFO: Building PKG because PKG-00.toc is non existent
10511 INFO: Building PKG (CArchive) PKG-00.pkg
10531 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
10543 INFO: Bootloader c:\users\tester\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
10543 INFO: checking EXE
10543 INFO: Building EXE because EXE-00.toc is non existent
10543 INFO: Building EXE from EXE-00.toc
10543 INFO: Appending archive to EXE C:\build\test\test.exe
10616 INFO: Building EXE from EXE-00.toc completed successfully.
10616 INFO: checking COLLECT
10636 INFO: Building COLLECT because COLLECT-00.toc is non existent
10636 INFO: Building COLLECT COLLECT-00.toc
11835 INFO: Building COLLECT COLLECT-00.toc completed successfully.

当我运行编译脚本时,C:/

中什么也没有出现

问题是:我是漏掉了什么还是做错了什么?我应该手动将 wget 模块添加到 pyInstaller 命令吗?或者我只是不理解 pyInstaller 文档并且无法在 Windows .exe 文件中使用外部模块?

我认为这不是 python 问题。尝试更改用户配置文件的路径。或者 运行 作为管理员的应用程序。

我不建议保存到 c:\,除非你有充分的理由。

.py文件成功转换为.exe文件,文件位于C:\dist\

将在路径 C:\ 中创建一个文件夹,pyinstaller 在 "dist" 文件夹中创建一个名为 "test" 的文件夹。您可以从 C:\dist\test\

访问 test.exe 文件

如果你想让你在单个文件中执行文件,那么在cmd中输入命令pyinstaller --onefile test.py(test.py是需要转换为.exe的文件)

有关更多选项,请阅读 PyInstaller 的文档