使用PyInstaller从Python脚本创建exe文件时遇到问题。
当我从VS运行脚本时,脚本运行良好,但是一旦打包到exe文件中,则在尝试运行该应用程序时收到以下消息:
Traceback (most recent call last):
File "final02.py", line 11, in <module>
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_86\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "selenium\webdriver\__init__.py", line 18, in <module>
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_86\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "selenium\webdriver\firefox\webdriver.py", line 29, in <module>
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_86\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "selenium\webdriver\remote\webdriver.py", line 27, in <module>
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_86\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "selenium\webdriver\remote\remote_connection.py", line 24, in <module>
ModuleNotFoundError: No module named 'urllib3'
[16444] Failed to execute script final02
要打包该应用程序,我使用了以下命令:
pyinstaller.exe --onefile --icon=app.ico final02.py
我试图加入
--hidden-import urllib3
但是我没有成功。
另外,值得一提的是,从VS运行时,我已经在脚本中正常安装并成功导入了urllib3模块。