pypa/sampleproject

sample script does not run

bradbell opened this issue · 5 comments

When I try to run an installed version of the sample script I get the error

Traceback (most recent call last):
  File "/home/bradbell/prefix/sampleproject/bin/sample", line 33, in <module>
    sys.exit(load_entry_point('sampleproject==2.0.0', 'console_scripts', 'sample')())
  File "/home/bradbell/prefix/sampleproject/bin/sample", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/lib64/python3.10/importlib/metadata/__init__.py", line 919, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib64/python3.10/importlib/metadata/__init__.py", line 518, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for sampleproject

Steps to reproduce:

  1. git clone https://github.com/pypa/sampleproject/ sampleproject.git
  2. cd sampelproject.git
  3. python setup.py install --prefix=$HOME/prefix/sampleproject
  4. program=$(find $HOME/prefix/sampleproject -name sample)
  5. pylib=$(find $HOME/prefix/sampleproject -name site-packages)
  6. export PYTHONPATH="$pylib:$PYTHONPATH"
  7. $program

That seems like a pretty... unconventional install process.

git clone https://github.com/pypa/sampleproject.git
cd sampleproject/
tox -e py310 --devenv myvenv
myvenv/bin/sample

Or, even more manually:

git clone https://github.com/pypa/sampleproject.git
cd sampleproject/
python3.10 -m venv myvenv
myvenv/bin/python -m pip install .
myvenv/bin/sample

You might be interested in https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html

So what exactly is my mistake above, the error message did not make it clear to me ?
Was it the fact that I executed setup.py directly and if so, why did setup.py not complain when I did so ?

I'm not sure... I'm not very familiar with setup.py install 😕 but you shouldn't need to know about setup.py to build/install the project, fwiw. Does the problem reproduce with either of the steps in my last comment?
What are you trying to do?

The procedure above used to work with the distutils version of setup.py. This has been deprecated and so I am trying to understand how to use the setuptools version of setup.py to replace it for legacy code. I was hoping that the old setup.py program would function the same in the two versions, but perhaps not.

I suppose that I will have to learn to use pip to do my local installs (that I use for testing) as you suggest above. I am busy with other things right now, but will get back to you once I see if I an get pip to do what setup.py used to do.

I'm not sure what exactly caused the error here, maybe it has to do with setuptools having problems installing to custom prefixes that aren't already set up as Python environments? In any case, current versions of setuptools will emit warnings when running setup.py directly, and there's a page on the Packaging User Guide to explain how to replace python setup.py, and there's also no setup.py anymore in this project. Thus, I'm going to close this issue.