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

inject command uses wrong python interpreter for local packages #956

Closed
lecardozo opened this issue Mar 18, 2023 · 0 comments · Fixed by #957
Closed

inject command uses wrong python interpreter for local packages #956

lecardozo opened this issue Mar 18, 2023 · 0 comments · Fixed by #957

Comments

@lecardozo
Copy link
Contributor

Describe the bug
While trying to pipx inject a local wheel with specific Python version constraints into a compatible environment (i.e. with a valid interpreter for those constraints), I keep getting the following error:

ERROR: Package 'my-local-package' requires a different Python: 3.11.1 not in '<3.11,>=3.8'

Here are the relevant versions and constraints 👇

  • package (to be injected) interpreter constraints: <3.11, >=3.8
  • environment interpreter: 3.8
  • pipx interpreter: 3.11.1

After seeing the error, it became clear that somehow in the middle of the injection process, pipx was trying to install the package with a different interpreter for some reason. After some debugging, I noticed that when the package is a local distribution we need to install it (without its dependencies) into a temporary venv in order to extract its name. However, when we do it, we end up using a default Python interpreter, instead of the one associated with the venv here 👇

# package_spec is anything pip-installable, including package_name, vcs spec,
# zip file, or tar.gz file.
if package_name is None:
package_name = package_name_from_spec(
package_spec, venv.python, pip_args=pip_args, verbose=verbose
)

I locally replaced venv.python (which maps to a default interpreter in this case) with venv.python_path (which maps to venv-specific interpreter) and it worked 😃

How to reproduce

Verbose logs for the inject command

pipx >(_parsed_package_to_package_or_url:128): cleaned package spec: /path/to/my-local-package-1.0.0-py3-none-any.whl
creating virtual environment...
pipx >(run_subprocess:173): running /opt/homebrew/Cellar/pipx/1.1.0/libexec/bin/python3.11 -m venv --without-pip /var/folders/vj/chbx1tms2c93nmnnp2gw4wh80000gq/T/tmpe5g_foll
pipx >(run_subprocess:173): running /var/folders/vj/chbx1tms2c93nmnnp2gw4wh80000gq/T/tmpe5g_foll/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:173): running /Users/me/.local/pipx/shared/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:173): running /var/folders/vj/chbx1tms2c93nmnnp2gw4wh80000gq/T/tmpe5g_foll/bin/python --version
determining package name from '/path/to/my-local-package-1.0.0-py3-none-any.whl'...
pipx >(run_subprocess:173): running /var/folders/vj/chbx1tms2c93nmnnp2gw4wh80000gq/T/tmpe5g_foll/bin/python -m pip list --format=json
pipx >(run_subprocess:173): running /var/folders/vj/chbx1tms2c93nmnnp2gw4wh80000gq/T/tmpe5g_foll/bin/python -m pip install --no-dependencies /path/to/my-local-package-1.0.0-py3-none-any.whl
Looking in indexes: https://pypi.org/simple
Processing /path/to/my-local-package-1.0.0-py3-none-any.whl
ERROR: Package 'my-local-package' requires a different Python: 3.11.1 not in '<3.11,>=3.8'
pipx >(subprocess_post_check:207): '/var/folders/vj/chbx1tms2c93nmnnp2gw4wh80000gq/T/tmpe5g_foll/bin/python -m pip install --no-dependencies /path/to/my-local-package-1.0.0-py3-none-any.whl' failed
Cannot determine package name from spec '/path/to/my-local-package-1.0.0-py3-none-any.whl'. Check package spec for errors.

Expected behavior

pipx should be able to inject dependencies into existing environments if their interpreters are compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant