问题
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
- 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.
来源:https://stackoverflow.com/questions/62017437/pyinstaller-failed-to-execute-script