简体   繁体   中英

Pyinstaller 'failed to execute' script

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

  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.

I know I write this 10 months after but i run into the same problem and i know the solution. so, maybe some people who have the same problem could get help.

If your script has any additional files such as db,csv,png etc. you should add this files same directory. in this way you could solve the problem i guess. at least my problem was solved this way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM