Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with/after setup_dev: PackageNotFoundError: pdm #404

Closed
1 task done
blueyed opened this issue Apr 23, 2021 · 3 comments · Fixed by #414
Closed
1 task done

Error with/after setup_dev: PackageNotFoundError: pdm #404

blueyed opened this issue Apr 23, 2021 · 3 comments · Fixed by #414
Labels
🐛 bug Something isn't working

Comments

@blueyed
Copy link
Contributor

blueyed commented Apr 23, 2021

  • I have searched the issue tracker and believe that this is not a duplicate.
% python setup_dev.py
Creating a venv using /usr/bin/python at /tmp/pdm/env...
…
Successfully installed SecretStorage-3.3.1 appdirs-1.4.4 attrs-20.3.0 cached-property-1.5.2 cffi-1.14.5 c
lick-7.1.2 colorama-0.4.4 cryptography-3.4.7 distlib-0.3.1 importlib-metadata-4.0.1 jeepney-0.6.0 keyring
-23.0.1 packaging-20.9 pdm-1.5.1 pdm-pep517-0.7.1 pep517-0.10.0 pip-21.0.1 pycparser-2.20 pyparsing-2.4.7
 python-cfonts-1.4.0 python-dotenv-0.17.0 pythonfinder-1.2.6 resolvelib-0.7.0 shellingham-1.4.0 six-1.15.
0 toml-0.10.2 tomlkit-0.7.0 wheel-0.36.2 zipp-3.4.1
Setup project for development...
Using Python interpreter: /usr/bin/python (3.9)
…
Install zipp 3.4.0 successful
Installing the project as an editable package...
Preparing isolated env for PEP 517 build...
Collecting setuptools
  Using cached setuptools-56.0.0-py3-none-any.whl (784 kB)
Installing collected packages: setuptools
Successfully installed setuptools-56.0.0
running egg_info
…
Creating /tmp/pdm/__pypackages__/3.9/lib/pdm.egg-link (link to .)
Adding pdm 1.5.2.dev2+g6baf013 to easy-install.pth file
Installing pdm script to /tmp/pdm/__pypackages__/3.9/bin

Installed /tmp/pdm
Install pdm 1.5.2.dev2+g6baf013 successful

🎉 All complete!

Deleting venv /tmp/pdm/env...
An editable version of pdm is installed at /tmp/pdm/__pypackages__/3.9/bin/pdm, you can create an alias for it for convenience.
…

However:

% /tmp/pdm/__pypackages__/3.9/bin/pdm
Traceback (most recent call last):
  File "/tmp/pdm/__pypackages__/3.9/bin/pdm", line 33, in <module>
    sys.exit(load_entry_point('pdm', 'console_scripts', 'pdm')())
  File "/tmp/pdm/__pypackages__/3.9/bin/pdm", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/lib/python3.9/importlib/metadata.py", line 524, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.9/importlib/metadata.py", line 187, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: pdm

The pdm script looks like this:

#!/usr/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'pdm','console_scripts','pdm'
import re
import sys

# for compatibility with easy_install; see #2198
__requires__ = 'pdm'

try:
    from importlib.metadata import distribution
except ImportError:
    try:
        from importlib_metadata import distribution
    except ImportError:
        from pkg_resources import load_entry_point


def importlib_load_entry_point(spec, group, name):
    dist_name, _, _ = spec.partition('==')
    matches = (
        entry_point
        for entry_point in distribution(dist_name).entry_points
        if entry_point.group == group and entry_point.name == name
    )
    return next(matches).load()


globals().setdefault('load_entry_point', importlib_load_entry_point)


if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(load_entry_point('pdm', 'console_scripts', 'pdm')())
@blueyed blueyed added the 🐛 bug Something isn't working label Apr 23, 2021
@blueyed
Copy link
Contributor Author

blueyed commented Apr 23, 2021

The problem here is that pdb.pep582 is not added to the $PYTHONPATH (to use the sitecustomize.py from there (https://pdm.fming.dev/#for-mac-and-linux-users)).
This can be fixed manually, but I wonder what PDM could provide / do to have it working by default.

@linw1995
Copy link
Member

linw1995 commented Apr 24, 2021

There is a way to execute the pdm command without PEP582 enabled globally is by running python -m pdm. (this way is written in documentation about contributing)

Why python -m pdm works?

The pdm actually is not installed in __pypackages__ due to editable installation. Hence, the change of pdm codes take effect on the pdm command in __pypackages__. So there is no difference to run pdm between via python -m pdm and via ./__pypackages__/3.9/bin/pdm.

And about this issue, the codes of setup_dev.py needs to be updated to recommend using python -m pdm. @frostming


My mistake. python -m pdm doesn't work if PEP582 not enabled globally. It will output this.

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/local/lib/python3.9/runpy.py", line 147, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/local/lib/python3.9/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/pdm/pdm/__init__.py", line 5, in <module>
    from pdm.cli.commands.base import BaseCommand
  File "/pdm/pdm/cli/commands/base.py", line 6, in <module>
    from pdm.cli.utils import PdmFormatter
  File "/pdm/pdm/cli/utils.py", line 10, in <module>
    import cfonts
ModuleNotFoundError: No module named 'cfonts'

@frostming
Copy link
Collaborator

frostming commented Apr 25, 2021

Sorry I didn't update that script. It used to work because the lib path was added to sys.path in the front of the execution script before. This approach was obsoleted in favor of pep582/sitecustomize.py.

I will just update the hint in the script. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants