setuptools: [BUG] No module named 'pkg_resources.extern'

setuptools version

setuptools==70.0.0

Python version

3.8.10

OS

Windows 11

Additional environment information

No response

Description

I use PyInstaller and PyArmor to obfuscate my code and create an Executable out of it. On a pipeline of mine, an error started to throw today:

Traceback (most recent call last):
  File "Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgres.py", line 16, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "pkg_resources\__init__.py", line 77, in <module>
ModuleNotFoundError: No module named 'pkg_resources.extern'

Inside this Pipeline I run python -m pip install -U setuptools. I.e., it uses the latest version of it.

I tested it locally and it happens with version 70.0.0 but not with version 69.5.1

Expected behavior

Obfuscated Executable from PyArmor and PyInstaller is created.

How to Reproduce

  1. Create a virtual environment
  2. Install pyinstaller[encryption]==4.* and pyarmor==7.*
  3. pip install tendo==0.2.* (just for the matter of having some import on the main.py file) (for some reason, it works with tendo>=0.3.0)
  4. Create a test.py
    import tendo.singleton
    
    def main():
        print("Hello World!")
    
    if __name__ == "__main__":
        me = tendo.singleton.SingleInstance()
        main()
    
  5. Run pyarmor pack .\test.py -x "--exclude .venv"
  6. Run the test.exe on dist/test/

Output

python -m pip install -U setuptools
pip install -U pyarmor==7.* pyinstaller[encryption]==4.*
pyarmor pack main.py
Traceback (most recent call last):
  File "Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgres.py", line 158, in <module>
  File "Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgres.py", line 36, in _pyi_rthook
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "pkg_resources\__init__.py", line 77, in <module>
ModuleNotFoundError: No module named 'pkg_resources.extern'

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 19 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Should be fixed now. pip install -U pyinstaller then use the --clean flag next time you run pyinstaller.

Anyways, this is likely trivial for Hartmut to fix once they look at the commit.

Harmut’s tolerance ran out a long time ago.

We’ll fix this on our end. Feel free to close this off as PyInstaller’s problem.

PyInstaller having to keep up with changes “like this” is indeed common. FWIW, I went and looked for an issue report against PyInstaller before I cam over here. :]

@abravalheri So, I tested somethings one more time here and adding pkg_resources.extern to PyInstaller’s Hidden Imports fixes the issue.

As @altendky said, it might actually be something that PyInstaller needs to fix upon the changes on SetupTools. Although I wonder what actually changed on SetupTools that made it break on PyInstaller side

The interesting thing about that is that https://github.com/pypa/setuptools/commit/e9995828311c5e0c843622ca2be85e7f09f1ff0d went the other direction. But that commit also went and switched to as _* imports. Anyways, this is likely trivial for Hartmut to fix once they look at the commit.

I’ll file an issue over there, if nobody beats me to it.