mattloper / chumpy

MIT License
195 stars 118 forks source link

chumpy `setup.py` improperly imports pip causing installation failure when using PEP 517 #56

Open kpeez opened 6 months ago

kpeez commented 6 months ago

Issue Description

The chumpy package's setup.py file currently attempts to import pip during the installation process, as shown in the following lines:

try:
    from pip._internal import main as pip_main
except ImportError:
    from pip import main as pip_main

There are a couple of problems with this approach:

  1. Violation of PEP 517: When using the --use-pep517 flag with pip (which will become the default behavior in the future), or when using other PEP 517-compliant build tools, the installation process fails with a ModuleNotFoundError: No module named 'pip' error. This is because pip is not guaranteed to be available during the installation process when PEP 517 is used.
  2. Assumption of pip availability: Even without using PEP 517, the assumption that pip is installed and available during the package installation process is incorrect. Some package managers or environments may not include pip by default, leading to the same ModuleNotFoundError.

Steps to reproduce

  1. Create a new virtual environment and install chumpy using pip with the --use-pep517 flag:
python -m venv myenv
source myenv/bin/activate
pip install chumpy --use-pep517
  1. The installation will fail with the following error:
Traceback (most recent call last):
  File "<string>", line 9, in <module>
ModuleNotFoundError: No module named 'pip'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  ...
  File "<string>", line 11, in <module>
ModuleNotFoundError: No module named 'pip'
elisa-aleman commented 5 months ago

I had the same issue, as a workaround I used poetry to make a PEP517 compliant whl.

git clone --depth 1 https://github.com/mattloper/chumpy.git && \
    cd chumpy && \
    poetry init \
        --name "chumpy" \
        --description "chumpy (poetry build)" \
        --author "Matthew Loper" \
        --license "MIT" \
        --no-interaction && \
    poetry version $(python -c 'import runpy;print(runpy.run_path("./chumpy/version.py")["version"])') && \
    poetry add numpy@* scipy@* six@* && \
    poetry build

This generates a PEP 517 compliant pyproject.toml which could be used to update this package by the author.

chenzhekl commented 2 weeks ago

This makes installation with pixi failed, too