question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`pdm run myscript.py` results in `ModuleNotFoundError: No module named 'pkg_resources'`

See original GitHub issue
  • I have searched the issue tracker and believe that this is not a duplicate.

Steps to reproduce

The google-cloud-storage package appears to depend on pkg_resources, which is a module of setuptools. setuptools is not one of my project dependencies, but shouldn’t it be installed as part of the Python environment? Regardless, after ensuring it’s installed in the base environment, pdm run ... still fails.

This works: python myscript.py This doesn’t: pdm run python myscript.py (see exception below)

I’m using Pyenv to mange my Python versions, and I ensured that my project is configured to use the correct interpreter. Also, pyenv which python and pdm run pyenv which python yield the same path.

Adding setuptools to the project dependencies will resolve the error, but it’s a dependency of a dependency and it’s installed in the base environment anyway. Something seems buggy.

Actual behavior

Traceback (most recent call last):
  File "/home/knjpythonanywhere/datarobot/powerschool/powerschool_sync/extract.py", line 10, in <module>
    from google.cloud import storage
  File "/home/knjpythonanywhere/datarobot/powerschool/__pypackages__/3.9/lib/google/cloud/storage/__init__.py", line 35, in <module>
    from google.cloud.storage.batch import Batch
  File "/home/knjpythonanywhere/datarobot/powerschool/__pypackages__/3.9/lib/google/cloud/storage/batch.py", line 30, in <module>
    from google.cloud.storage._http import Connection
  File "/home/knjpythonanywhere/datarobot/powerschool/__pypackages__/3.9/lib/google/cloud/storage/_http.py", line 19, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

Expected behavior

pdm run myscript.py should presumably have the same outcome as python myscript.py when I’m running both commands in the same working directory.

Environment Information

PDM version:        1.13.4
Python Interpreter: /home/knjpythonanywhere/.pyenv/versions/3.9.11/bin/python (3.9)
Project Root:       /home/knjpythonanywhere/datarobot/powerschool
Project Packages:   /home/knjpythonanywhere/datarobot/powerschool/__pypackages__/3.9
{
  "implementation_name": "cpython",
  "implementation_version": "3.9.11",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "5.13.0-1017-aws",
  "platform_system": "Linux",
  "platform_version": "#19~20.04.1-Ubuntu SMP Mon Mar 7 12:53:12 UTC 2022",
  "python_full_version": "3.9.11",
  "platform_python_implementation": "CPython",
  "python_version": "3.9",
  "sys_platform": "linux"
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
frostmingcommented, Mar 23, 2022

So google-cloud-storage fails to list setuptools as a dependency, you should add it: pdm add setuptools

0reactions
cbinicommented, Mar 22, 2022

I can confirm that extract-nwk.site_packages = true will solve it. However, it doesn’t seem to work using the global setting key: _.site_packages = true. Should I open a new issue for that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No module named pkg_resources - python - Stack Overflow
This error message is caused by a missing/broken Python setuptools package. Per Matt M.'s comment and setuptools issue #581, the bootstrap script referred...
Read more >
No module named 'pkg_resources' in Python | bobbyhadz
The Python "No module named 'pkg_resources'" occurs when setuptools is not installed in our Python environment. To solve the error, ...
Read more >
No module named 'pkg_resources.py2_warn' - Google Groups
I just updated my python 3.6 version to a more recent one, and suddenly I get the error: ModuleNotFoundError: No module named 'pkg_resources.py2_warn'....
Read more >
pbr VersionInfo: ImportError: No module named pkg_resources
Actual results: version.py:438:_get_version_from_pkg_resources:ImportError: No module named pkg_resources Traceback (most recent call last): File ...
Read more >
ImportError: No module named 'pkg_resources'
You had installed a version of Python under /usr/local . You have now removed part of it. You're trying to use a part...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found