setuptools: setuptools 45.0.0 may cause PyInstaller 3.3 packaged executable fail to launch
In my specific example where we use PyInstaller 3.3 to package our application into an executable for deployment, the resulting executable cannot be launched after setuptools was updated from 44.0.0 to 45.0.0. This happened right at 9:00PM Pacific Time yesterday.
The error signature is (when launching the executable generated by PyInstaller):
[1072] Failed to execute script pyi_rth_pkgres
Traceback (most recent call last):
File "site-packages/PyInstaller/loader/rthooks/pyi_rth_pkgres.py", line 11, in <module>
File "/<virtualenv-path>/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/pkg_resources/__init__.py", line 86, in <module>
ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
PyInstaller version is 3.3, setuptools is 45.0.0 Working just fine with setuptools 44.0.0
For certain limitations in our Python application, we are stuck with Pyinstaller 3.3, but we are definitely looking into using later versions of PyInstaller.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 45
- Comments: 39 (10 by maintainers)
Links to this issue
Commits related to this issue
- Fix pyinstaller exe error Pin setuptools at 44.0.0 for now. pypa/setuptools#1963 — committed to Septima/malstroem by AsgerPetersen 4 years ago
- Fix pyinstaller exe error Pin setuptools at 44.0.0 for now. pypa/setuptools#1963 — committed to Septima/malstroem by AsgerPetersen 4 years ago
- Add obnoxious warning about Python 2 being unsupported on this release with guidance on how to avoid the warning and what to do if that guidance was ineffective. — committed to pypa/setuptools by jaraco 4 years ago
- Add workaround for https://github.com/pypa/setuptools/issues/1963. — committed to matham/filers2 by matham 4 years ago
- Apply workaround to setuptools version see: https://github.com/pypa/setuptools/issues/1963#issuecomment-574265532 — committed to isogeo/isogeo-2-office by Guts 4 years ago
- PyInstaller: workaround a setuptools issue causing binaries to not run. Reference: https://github.com/pypa/setuptools/issues/1963 — committed to etesync/etesync-dav by tasn 4 years ago
- Add workaround for PyInstaller / setuptools incompatibility. Details https://github.com/pypa/setuptools/issues/1963 Co-authored-by: Pete Wall <pwall@pivotal.io> — committed to cf-platform-eng/tile-generator by mboldt 4 years ago
- Update pyinstaller to 3.6, to work around https://github.com/pypa/setuptools/issues/1963 which is a problem with pyinstaller 3.3 and latest setuptools. — committed to electrumsv/electrumsv by rt121212121 4 years ago
- Update pyinstaller to 3.6, to work around https://github.com/pypa/setuptools/issues/1963 which is a problem with pyinstaller 3.3 and latest setuptools. — committed to electrumsv/electrumsv by rt121212121 4 years ago
- Update pyinstaller to 3.6, to work around https://github.com/pypa/setuptools/issues/1963 which is a problem with pyinstaller 3.3 and latest setuptools. — committed to electrumsv/electrumsv by rt121212121 4 years ago
- Update pyinstaller to 3.6, to work around https://github.com/pypa/setuptools/issues/1963 which is a problem with pyinstaller 3.3 and latest setuptools. — committed to electrumsv/electrumsv by rt121212121 4 years ago
- workaround for bug in setuptools + pyinstaller See: https://github.com/pypa/setuptools/issues/1963 Fixes: https://github.com/overviewer/Minecraft-Overviewer/issues/1724 — committed to overviewer/Overviewer-Web by agrif 4 years ago
- Add `--assume-yes` to doc and fix PyInstaller issue on Linux Put the `-y` flag on `--assume-yes` and refect this in the docstring. Format pyinstaller spec file and add hidden import to fix https://gi... — committed to canonical/microk8s by joedborg 4 years ago
- Add `--assume-yes` to doc and fix PyInstaller issue on Linux (#966) Put the `-y` flag on `--assume-yes` and refect this in the docstring. Format pyinstaller spec file and add hidden import to fix ht... — committed to canonical/microk8s by joedborg 4 years ago
- [python] New setuptools misses dependency https://github.com/pairinteraction/pairinteraction/issues/108 https://github.com/pypa/setuptools/issues/1963 — committed to hmenke/pairinteraction by hmenke 4 years ago
- fix binary builds See https://github.com/pypa/setuptools/issues/1963 for details. — committed to mitmproxy/mitmproxy by mhils 4 years ago
- Fix binary builds (#3840) See https://github.com/pypa/setuptools/issues/1963 for details. — committed to mitmproxy/mitmproxy by mhils 4 years ago
- tox: pin setuptools < 45 to allow installing py27 in virtenv setuptools release 45 broke everyone who installed py27[1]. Fix this by using the previous release. 1. https://github.com/pypa/setuptool... — committed to canonical/curtin by raharper 4 years ago
- Lock setuptools version because of bug https://github.com/pypa/setuptools/issues/1963 — committed to rsre/K40-Whisperer-macOS by rsre 4 years ago
- Updates to use Windows base 1909-amd64. Pin setuptools<45.0.0 due to https://github.com/pypa/setuptools/issues/1963 - will address root cause in future release. — committed to informatics-isi-edu/deriva-client-bundle-docker by mikedarcy 4 years ago
Observed the same behaviour on
Python 3.7.5
withPyInstaller 3.5
andPyInstaller 3.6
. I was able to build again successfully after reverting to previous release ofsetuptools
:Fixed by adding a hidden import:
We ran into the same issue this morning, using PyInstaller 3.6
If you’re using pyinstaller from bash you can use “–hidden-import=‘pkg_resources.py2_warn’” to get rid of this issue. Eg: pyinstaller --hidden-import=‘pkg_resources.py2_warn’ ${package}
I am having the same issue with
Python 3.6.8
andPyinstaller 3.6
. I suspect that it is caused by the recent commit pypa/setuptools@79f1694b05a66cc0fbbbf4e72d63d0a340cf6d84 insetuptools
since it added the line__import__('pkg_resources.py2_warn')
but not a regular import line likeimport pkg_resources.py2_warn
(as done for other__import__
statements inpkg_resources.__init__.py
) and afaikPyinstaller
does not scan for__import__
statements and hence does not freeze the filepkg_resources.py2_warn.py
.You either add this to your
.spec
-file if you use it before theAnalysis
step, or add it as a command-line parameter--hidden-import="pkg_resources.py2_warn"
My hack works whatever the version of setuptools. I’ll see if I have time to do a clean PR in here.
Shall we get a new update today or what is the plan?
Still an issue, got bitten by it with the latest Miniconda3. Fixed it on Windows by typing:
pyinstaller -F -c --hidden-import="pkg_resources.py2_warn" your_script.py
Note the use of double quotes, as single quotes do not work here on Windows.
Just occurred to me - why wait. So 49.1.1 is going out for release now.
In the commit (79f1694b05a66cc0fbbbf4e72d63d0a340cf6d84), a comment was made that this affects cxFreeze also.
The suggestion was made to simply use
import
to import the module, such as is done withpy31compat
. Forpy2warn
, I chose to use__import__
to signal that the side effect is what’s desired (and to avoid linter warnings about an unused bound name, F401 imported but unused). Withpy31compat
, the name is used later in the module; that’s not the case withpy2warn
.As you can see, adjacent to this import, there are very similar import calls in this module that do not import any other names and there’s no comment or other tests preventing this sort of usage. I don’t understand why this import is causing trouble while others are not.
Probably tools like
cxFreeze
andpyInstaller
should honor__import__
calls, especially when they’re at the top of an imported module. I don’t know why they’re not.Even better, these tools should probably consider not relying primarily on runtime inference for module detection but instead rely on package metadata like importlib.metadata and Python Packaging tools like pip or pep517 to assemble these packages more deterministically.
Failing that, these tools should provide a mechanism for a project such as setuptools to advertise its “hidden” imports.
I’m sad to see there are so many workarounds for this issue but no robust solution. I’m happy to work with the maintainers of cxFreeze or PyInstaller to develop a robust solution.
Without a better recommendation, this behavior is working as intended, so I’m closing the ticket, but happy to re-open if there’s an actionable recommendation.
Python 3.7.8 Jun 28 2020, 08:53:46) [MSC v.1916 64 bit (AMD64)] on win32 I updated my python from 3.7.7 (32bit) to 3.7.8 (64bit). I started to get this mistake:
I was helped by a comment from the branch above: https://github.com/pypa/setuptools/issues/1963#issuecomment-574265532
my observation pyinstaller version=3.5 and setuptool 41.2.0 working correctly pynstaller.
我也遇到同樣的問題 對虛擬的環境重新更新pip 在C:\virenv\Scripts\ 目錄下 pip install --upgrade setuptools==44.0.0 就解決了
I’m not aware of any such thing and would guess that these designs just arose organically. I have also reflected that this puts all the work on the pyinstaller devs because you have to update the hooks in the pyinstaller repo, as opposed to updating them directly in each package according to some specified syntax as the package changes. And yeah, it misses imports that are not “standard”. It would be nice if there was a way for package maintainers to declare the various files that may need to be included in a app.
Maybe Python’s discourse would be a good place to bring up these ideas? I know pyinstaller is already struggling with maintainer time, so they may not be in a position to implement these ideas, but someone interested could?
But FYI, there is more complexity here than you may be considering. Bundling a fully functioning app should typically mean that you bundle the minimum modules required to run a package given the way the package is used by the app. E.g. consider a framework that provides some core modules, audio/video, and some other modules. Each of these modules depend on some external packages. E.g. audio/video may require a 100MB gstreamer package. Currently, pyinstaller should be able to tell which framework modules you use in the app and only bundle gstreamer if you actually use the audio/video module. I’m not sure pip style metadata would be able to do this?
Why is this closed if its still an issue?
As far as I understand (and this is not much), you could have reached the same effect with
This would at least have avoided the issue for cx_Freeze (beside being explicit). Anyhow, even if this would be an acceptable recommendation for you, it is “too late” in the sense that cx_Freeze probably needs to be patched to work with setuptools 45.0.0 anyway (see below).
At least in cx_Freeze, there was already a hook for the other similar imports.
The cx_Freeze mechanism is also to provide hooks to advertise the “hidden” import. I’ve opened a corresponding issue https://github.com/anthony-tuininga/cx_Freeze/issues/579 and made a PR proposal there.
The pyinstaller mechanism is to use hooks that describe the hidden imports for each package. Looking at their hooks, it seems it should already be fixed in their master?
https://github.com/pyinstaller/pyinstaller/blob/develop/PyInstaller/hooks/hook-setuptools.py https://github.com/pyinstaller/pyinstaller/blob/develop/PyInstaller/hooks/hook-pkg_resources.py