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

时间:2019-09-07 12:39:02

标签: python windows exe wget pyinstaller

我在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文件中使用外部模块?

2 个答案:

答案 0 :(得分:0)

我不认为这是python问题。尝试更改您的用户配置文件的路径。或以管理员身份运行该应用。

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

答案 1 :(得分:0)

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

将在路径C:\下创建一个文件夹,并且pyinstaller在“ dist”文件夹内创建一个名称为“ test”的文件夹。您可以从C:\ dist \ test \

访问test.exe文件

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

更多选项,请阅读PyInstaller文档