Though the conversion from *.py- to a standalone *.exe-file via the command "pyinstaller --onefile filename.py" can be completed successfully, the executable itself failes to run
Traceback (most recent call last): File
"venv\Lib\site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py",
line 13, in File
"c:\users\user01\pycharmprojects\api4trd\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 623, in exec_module
exec(bytecode, module.dict) File "lib\site-packages\pkg_resources__init__.py", line 86, in
ModuleNotFoundError: No module named 'pkg_resources.py2_warn' [13560]
Failed to execute script pyi_rth_pkgres
following packages are used
1) math
2) datetime
3) yfinance
Python version: 3.8.1
pyinstaller version: 3.6
OS:W10
Thank you!
You are missing one hidden import in your pyinstaller command. Although earlier version of Python and Pyinstaller never used to give this error, but nevertheless here is the solution
pyinstaller --onefile --hidden-import=pkg_resources.py2_warn filename.py
Related
I'm trying to use pyinstaller with a simple python program. Creating the windows .exe completes successfully but when I run the .exe program, I get the error
.\dist\myapp\myapp.exe
Traceback (most recent call last):
File "pac_cleaner\myapp.py", line 2, in <module>
import pyreadstat as pr
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "pyreadstat\__init__.py", line 17, in <module>
File "pyreadstat\pyreadstat.pyx", line 1, in init pyreadstat.pyreadstat
ModuleNotFoundError: No module named 'pyreadstat._readstat_writer'
[11460] Failed to execute script 'myapp' due to unhandled exception!
The program itself is
import pyreadstat as pr
import pandas as pd
def hello():
print("Hello")
if __name__ == '__main__':
hello()
and I use pyinstaller as so
pyinstaller .\pac_cleaner\myapp.py --noconfirm --hidden-import=pandas --hidden-import=pyreadstat
any ideas?
Using the --collect-submodules works. I'm posting the answer from the official repo discussion
pyinstaller .\pac_cleaner\myapp.py --noconfirm --collect-submodules pyreadstat
So after I compiled the program I wrote using pyinstaller in one-file mode, The program doesn't seem to function at all.
When I try to execute it, I receive the following Exception in a Window:
Traceback (most recent call last):
File "main.py", line 6, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "pystray\__init__.py", line 48, in <module>
File "pystray\__init__.py", line 44, in backend
ImportError: this platform is not supported: No module named 'pystray._win32'
What could be the issue here? I mean how do I solve this problem?
I'm currently running:
Python 3.9
Windows 10 (the latest version)
Visual Studio Code
Try using the git bash or command prompt. I don't think PyInstaller works with the VSC terminal.
I have a python code that I wanted to turn into an exe.
I used pyinstaller with : pyinstaller --onefile -w script.py
After it finished making the exe file I double clicked the file but I got "Failed to execute script".
I also tried running it from the cmd but it gives the same fatal error.
Stuff to add:
The code imports a couple of files packages including a python code I made, as well as it makes files referenced to it's location.
Is there something I'm doing wrong?
the script has those imports:
import socket
import os
from PIL import ImageGrab
import cv2
import time
import json
import myFile
I ran the code under cmd and it gives this error:
File "script.py", line 3, in <module>
from PIL import ImageGrab
ModuleNotFoundError: No module named 'PIL'
Might be unrelated but now that I tried to do pyinstaller --onefile -w client.py.
After I ran it windows defender found this inside :
after running it in the terminal in pycharm with :
pyinstaller --onefile --hidden-import=PIL --hidden-import=Pillow --hidden-import=pynput client.py
I get this error (note that i moved it from the dist directory to the main one):
Traceback (most recent call last):
File "client.py", line 7, in <module>
import myFile
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "myFile.py", line 1, in <module>
from pynput import mouse, keyboard
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 82, in backend
ImportError
[13364] Failed to execute script client
This may be due to pyinstaller not being able to properly find your dependencies and skipping some packages.
To fix any error like ModuleNotFoundError: No module named 'PIL' just add it as a hidden import:
pyinstaller --onefile --hidden-import=PIL -w script.py
For the second error this is a known issue with pyinstaller and pynput.
Find here some explanation.
The TLDR of it seems to be that you need to add --hidden-import=pynput.mouse._win32 --hidden-import=pynput.keyboard._win32 --hidden-import=pynput._util._win32 and any other sub-packages that give you errors.
I am trying to wrap a Python script into an exe using PyInstaller (development version) for windows.
The script uses Pandas and I have been running into an error when running the exe.
Traceback (most recent call last): File "site-packages\pandas\__init__.py", line 26, in <module> File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__) File "site-packages\pandas\_libs\__init__.py", line 4, in <module> File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname) File "pandas/_libs/tslib.pyx", line 1, in init pandas._libs.tslib ModuleNotFoundError: No module named 'pandas._libs.tslibs.timedeltas'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "G5k Version file Extract (with tkinter).py", line 15, in <module> File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__) File "site-packages\pandas\__init__.py", line 35, in <module> ImportError: C extension: No module named 'pandas._libs.tslibs.timedeltas' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
I have tried doing this for programs without pandas and everything was fine.
This is very similar to another question already solved for Python 2, but I am using Python 3 and that solution does not apply the same way due to the changed .spec file format.
Python 3.6
PyInstaller - version 3.3
Pandas - version 0.20.3
PyInstaller 3.3, Pandas 0.21.0, Python 3.6.1.
I was able to solve this thanks to not-yet published/committed fix to PyInstaller, see this and this. AND keeping the ability to pack it into one executable file.
Basically:
Locate PyInstaller folder..\hooks, e.g. C:\Program Files\Python\Lib\site-packages\PyInstaller\hooks.
Create file hook-pandas.py with contents (or anything similar based on your error):
hiddenimports = ['pandas._libs.tslibs.timedeltas']
Save it + I deleted .spec file, build and dist folders just to be sure.
Run pyinstaller -F my_app.py.
This fix should work as long as you don't upgrade or reinstall PyInstaller. So you don't need to edit .spec file.
Maybe they will include the fix sooner for us! :)
I'm not sure it may help you but following the solution on the post you mention work for me with python 3.6 pyinstaller 3.3 and pandas 0.21.0 on windows 7.
So adding this to the spec file just after analysis :
def get_pandas_path():
import pandas
pandas_path = pandas.__path__[0]
return pandas_path
dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries)
Also my spec file format is the same as the one in the post you mention.
I managed to solve this problem by using the "--hidden-import" flag. Hopefully this can be helpful to someone else that comes across this thread.
pyinstaller --onefile --hidden-import pandas._libs.tslibs.timedeltas myScript.py
If you are using Anaconda, it is highly likely that when you were trying to uninstall some package it has disrupted pandas dependency and unable to get the required script. If you just run conda install pandas you might end up with another error:
module 'pandas' has no attribute 'compat'.
So, try uninstalling and reinstalling pandas conda uninstall pandas, Install it again using conda install pandas this will solve the problem.
On the other hand, if you are not using Anaconda., try doing the same on Command prompt pointing to Python scripts folder pip uninstall pandas & pip install pandas.
Most of the times, this should solve the problem. Just to be cover all the possibilities, don't forget to Launch Spyder from Anaconda after installing pandas.
I have written a Python app which makes use of:
from PIL import Image
I want to distribute a packed version of this application so that whoever uses it does not need to install all the dependencies.
For that I have used pyinstaller, without much success.
I run:
pyinstaller --onefile image_download.py
and it does not complain. However, when I run the application, I get:
Traceback (most recent call last):
File "", line 26, in
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.dict)
File "/home/ic/twitter-project/build/image_download/out00-PYZ.pyz/PIL.PngImagePlugin", line 40, in
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.dict)
File "/home/ic/twitter-project/build/image_download/out00-PYZ.pyz/PIL.Image", line 63, in
ImportError: cannot import name _imaging
I am using:
Ubuntu 14.04
Python 2.7
pyinstaller 2.1
PIL.VERSION 1.1.7 (although I thought I had installed Pillow 2.8.1)
The script works fine running as python image_download.py, but pyinstaller is not being able to import _imaging, for some reason.
Any suggestions?
Finally I could not use pyinstaller for this, since I could not fix the import problem.
I managed to build a standalone executable with Nuitka and bbfreeze, though, so in case anyone runs into the same problem: it is worth trying other tools.