Pyinstaller“无法执行"脚本 [英] Pyinstaller 'failed to execute' script
问题描述
我是编程新手.我制作了一个python脚本.它在 pycharm 中运行没有错误.使用 pyinstaller 我试图制作一个 exe.当我在 build 或 dist 文件夹或什至通过命令提示符运行 exe 时,它给我错误无法执行脚本主"
我附上警告文件链接:
脚本名称:python 脚本的路径
工作路径:项目所在地
保留图像中的解释器选项.
运行pyinstaller.您可以在 dist 目录中找到您的 .exe.
如果找不到模块"错误仍然存在.您可以添加一个隐藏的导入钩子并指定缺失模块的名称.导航到 Project Path\venv\Lib\site-packages\PyInstaller\hooks 并创建一个新的hook-pandas.py"(hook-modulename.py) 脚本并制作一个隐藏导入模块的列表,如下所示:
hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
- 再次运行 pyinstaller,它现在应该可以工作了.
I am new to programming. I have made a python script. It runs without errors in pycharm. Using pyinstaller i tried to make an exe. When i run the exe in build or dist folder or even through command prompt, it gives me the error 'Failed to execute Script Main'
I am attaching the warnings file link:
https://drive.google.com/open?id=1cDQ2KGId0B8K9Qi1bWPIhL55hQO0dM-z
Kindly help!
There is one pip script for each virtual environment. So when you install a python module it get installed into the projectname\venv\Lib\site-packages directory.
When you run pyinstaller from terminal to make the executable, pyinstaller checks for dependencies in Sys.path . But that path does not include the projectname\venv\Lib\site-packages directory. Therefore pyinstaller cannot find those particular dependencies. In such cases it gives you warnings.Those warning can be found in 'warnname.txt' near your executable file.
How to Configure pycharm to run pyinstaller
- First you need to add pyinstaller into project interpreter.
- Then you need to setup running configurations.
Script name: path to your python script
working path: Project location
Leave interpreter options as it is in the image.
Run pyinstaller. You can find your .exe in dist directory.
If the "Module not found" error still persists. You can add a hidden import hook and specify the names of the missing modules.Navigate to Project Path\venv\Lib\site-packages\PyInstaller\hooks and create a new "hook-pandas.py"(hook-modulename.py) script and make a list of hidden import modules like this:
hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
- And run pyinstaller again, and it should work now.
这篇关于Pyinstaller“无法执行"脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!