Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no module named pkg_resources.py2_warn pyinstaller

I'm trying to make an executable file (.exe file for windows) for the code here. The main file to run is src/GUI.py. I found that pyinstaller is a better option to create the exe file.

I tried both one folder and single executable file options. I tried creating the exe from root directory and as well as in src directory.

pyinstaller src/GUI.py
pyinstaller src/GUI.py -F
cd src
pyinstaller GUI.py
pyinstaller GUI.py -F

GUI.exe gets created with all the above methods. But whenever I tried to run the GUI.exe file, I get the error no module named pkg_resources.py2_warn pyinstaller. I tried running GUI.exe in the dist directory where it is created, in the root directory and in the src directory as well. Everywhere, I get the same error. How can I fix this?

PS: Ideally I would like to have a single .exe file which I can distribute and they can run it standalone, without any need to install dependencies or recreating the folder structure. But I got to know that pyinstaller only packages the code files and I've to share the images separately and when running the exe file, the same structure has to be recreated. I'm okay with this as well. I'm even okay to share the one folder exe as well. I just want to share a file or a folder, which users can run without installing any dependencies. Is it possible at all?

PPS: I'm open to using tools other than pyinstaller as well.

like image 994
Nagabhushan S N Avatar asked May 03 '20 13:05

Nagabhushan S N


People also ask

How to fix modulenotfounderror in pyinstaller?

Use PyInstaller --hidden-import=pkg_resources.py2_warn my_script.py to fix this. Same applies to most ModuleNotFoundError s.

What causes modulenotfounderror [24514]?

ModuleNotFoundError: No module named 'pkg_resources.py2_warn' [24514] Failed to execute script pyi_rth_pkgres This discussiondescribes it as being caused by the setuptools update around 45.0.0

How do I fix the hidden module in Setuptools?

That hidden module was added in setuptools version 45.0.0 and removed in 49.0.0 so either downgrading below or upgrading above will also fix it. Please do not fix this by putting import pkg_resources.py2_warn at the top of your code as others have done as this will obviously break if you change your setuptools version to be outside the above range.


4 Answers

As of 7/16/2020, upgrading setuptools now resolves this error. Downgrading setuptools like the other answers prescribe is not necessary anymore. See this discussion

On Win10, upgrade with

pip3 install setuptools --upgrade

However as Vikramaditya said, downgrading below ver 45.0.0 works too.

like image 100
rfii Avatar answered Oct 17 '22 09:10

rfii


This is an issue with setuptools as explained in this github ticket. Consider downgrading your setuptools to 44.0 or below with the command

pip install --upgrade 'setuptools<45.0.0'
like image 26
Vikramaditya Gaonkar Avatar answered Oct 17 '22 10:10

Vikramaditya Gaonkar


Use PyInstaller --hidden-import=pkg_resources.py2_warn my_script.py to fix this. Same applies to most ModuleNotFoundErrors.

That hidden module was added in setuptools version 45.0.0 and removed in 49.0.0 so either downgrading below or upgrading above will also fix it.

Please do not fix this by putting import pkg_resources.py2_warn at the top of your code as others have done as this will obviously break if you change your setuptools version to be outside the above range.

This issue will be fixed permanently in version 4.0 of PyInstaller once we eventually get round to releasing it.

like image 10
pullmyteeth Avatar answered Oct 17 '22 09:10

pullmyteeth


Uninstall setuptools before you downgrade tips: Some functions may be affected

like image 1
123wyf Avatar answered Oct 17 '22 10:10

123wyf