Pyinstaller 'failed to execute' script

我怕爱的太早我们不能终老 提交于 2021-02-04 16:37:04

问题


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!


回答1:


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

  1. First you need to add pyinstaller into project interpreter.
  2. 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.

  1. Run pyinstaller. You can find your .exe in dist directory.

  2. 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']
  1. And run pyinstaller again, and it should work now.


来源:https://stackoverflow.com/questions/62017437/pyinstaller-failed-to-execute-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!