Python Forum

Full Version: Encountering `importlib_metadata.PackageNotFoundError` trying to run console script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
# Background

I have a pipenv workspace which is structured like this:

|- Pipfile
|- Pipfile.lock
|- assetdb-SNAPSHOT/
   |- setup.py
   |- assetdb/
      |- __init__.py
      |- (other modules)
The Pipfile references the assetdb-SNAPSHOT directory by local path:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[packages]
assetdb = {editable = true, path = 'assetdb-SNAPSHOT'}

[dev-packages]

[requires]
The assetdb-SNAPSHOT/setup.py file declares assetdb to be a console_scripts entrypoint:

from setuptools import setup, find_packages

setup(
    packages=find_packages(),
    entry_points={'console_scripts': ['assetdb=assetdb.porcelain.cli:main']},
    name='assetdb',
    version='0.0.1-SNAPSHOT',
    install_requires=['pyyaml==5.3.1', 'pytest==6.0.2', 'pytest-rng==1.0.0'],
)
# Problem

However, when I attempt to run pipenv run assetdb, I get this error:


Traceback (most recent call last):
  File "/Users/kahlo/.local/share/virtualenvs/pypackages-988kgfpK/bin/assetdb", line 33, in <module>
    sys.exit(load_entry_point('assetdb', 'console_scripts', 'assetdb')())
  File "/Users/kahlo/.local/share/virtualenvs/pypackages-988kgfpK/bin/assetdb", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/Users/kahlo/.local/share/virtualenvs/pypackages-988kgfpK/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 940, in distribution
    return Distribution.from_name(distribution_name)
  File "/Users/kahlo/.local/share/virtualenvs/pypackages-988kgfpK/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 534, in from_name
    raise PackageNotFoundError(name)
importlib_metadata.PackageNotFoundError: No package metadata was found for assetdb
# Diagnostics

I am able to use pipenv to enter a python shell, import the main function, and run it, and it works:

Phoenixs-MacBook-Pro:pypackages kahlo$ pipenv run python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import assetdb.porcelain.cli
>>> assetdb.porcelain.cli.main()
usage:  [-h] [--cwd [CWD]]
        {init,status,upload,add,remove,sync-file-to-hash,sync-hash-to-file,stash,checkout}
        ...
Therefore, the problem lies somewhere in this configuration's ability to locate the entrypoint based on the command.

---

Help much appreciated