-
Notifications
You must be signed in to change notification settings - Fork 476
Closed
Description
Describe the bug
It looks like since #1168 pipx is no longer able to create a virtual environment when passing --python
(at least on linux and with pyenv managed versions). It still works fine if a venv already exists.
From my tests I assume it's caused by how os.path.realpath
creates the file path to the python executable provided. I've only tested this with python versions being managed by pyenv.
which python3.9
-> /home/robert/.pyenv/shims/python3.9 # This is fine
python3.9 -c "import sys; print(sys.executable)"
-> /home/robert/.pyenv/versions/3.9.18/bin/python3.9 # This is fine
python3.9 -c "import os;print(os.path.realpath('python3.9'));"
-> /home/robert/private/code/pipx/python3.9 # This is wrong!
How to reproduce
pipx run --python=python3.11 pycowsay moo
(develop-3-12) ➜ pipx git:(main) ✗ pipx run --python=python3.9 --verbose pycowsay moo
pipx >(setup:853): pipx version is 0.1.dev661+g7d82745.d20240106
pipx >(setup:854): Default python interpreter is '/home/robert/private/code/pipx/.nox/develop-3-12/bin/python'
pipx >(run_package:156): venv location is /home/robert/.local/pipx/.cache/7c9b64e6b834c48
pipx >(package_name_from_spec:370): Determined package name: pycowsay
pipx >(package_name_from_spec:371): Package name determined in 0.0s
creating virtual environment...
pipx >(run_subprocess:168): running python3.9 -m venv --without-pip /home/robert/.local/pipx/.cache/7c9b64e6b834c48
Traceback (most recent call last):
File "/home/robert/private/code/pipx/.nox/develop-3-12/bin/pipx", line 8, in <module>
sys.exit(cli())
^^^^^
File "/home/robert/private/code/pipx/src/pipx/main.py", line 914, in cli
return run_pipx_command(parsed_pipx_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/robert/private/code/pipx/src/pipx/main.py", line 197, in run_pipx_command
commands.run(
File "/home/robert/private/code/pipx/src/pipx/commands/run.py", line 200, in run
run_package(
File "/home/robert/private/code/pipx/src/pipx/commands/run.py", line 157, in run_package
_download_and_run(
File "/home/robert/private/code/pipx/src/pipx/commands/run.py", line 234, in _download_and_run
venv.create_venv(venv_args, pip_args, override_shared)
File "/home/robert/private/code/pipx/src/pipx/venv.py", line 160, in create_venv
venv_process = run_subprocess(cmd + venv_args + [str(self.root)])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/robert/private/code/pipx/src/pipx/util.py", line 179, in run_subprocess
completed_process = subprocess.run(
^^^^^^^^^^^^^^^
File "/home/robert/.pyenv/versions/3.12.1/lib/python3.12/subprocess.py", line 548, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/robert/.pyenv/versions/3.12.1/lib/python3.12/subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/home/robert/.pyenv/versions/3.12.1/lib/python3.12/subprocess.py", line 1950, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/robert/private/code/pipx/python3.9'
Expected behavior
Creating a venv and then printing pycowsay.
danyeaw, almahdi404 and ewjoachim
Metadata
Metadata
Assignees
Labels
No labels