pypa / pipx

Install and Run Python Applications in Isolated Environments
https://pipx.pypa.io
MIT License
10.33k stars 411 forks source link

Pipx upgrade fails (macOS Catalina) #595

Closed chrisfinazzo closed 3 years ago

chrisfinazzo commented 3 years ago

Describe the bug

As described here, while using pipx to use or upgrade the Standard Ebooks tools, the following error occurs:

    File "/usr/local/Cellar/pipx/0.15.6.0/libexec/bin/pipx", line 33, in <module>
sys.exit(load_entry_point('pipx==0.15.6.0', 'console_scripts', 'pipx')())
    File "/usr/local/Cellar/pipx/0.15.6.0/libexec/lib/python3.9/site-packages/pipx/main.py", line 609, in cli
return run_pipx_command(parsed_pipx_args)
    File "/usr/local/Cellar/pipx/0.15.6.0/libexec/lib/python3.9/site-packages/pipx/main.py", line 186, in run_pipx_command
return commands.upgrade(
    File "/usr/local/Cellar/pipx/0.15.6.0/libexec/lib/python3.9/site-packages/pipx/commands/upgrade.py", line 53, in upgrade
venv.upgrade_package(
    File "/usr/local/Cellar/pipx/0.15.6.0/libexec/lib/python3.9/site-packages/pipx/venv.py", line 363, in upgrade_package
self._run_pip(["install"] + pip_args + ["--upgrade", package_or_url])
    File "/usr/local/Cellar/pipx/0.15.6.0/libexec/lib/python3.9/site-packages/pipx/venv.py", line 379, in _run_pip
return run(cmd)
    File "/usr/local/Cellar/pipx/0.15.6.0/libexec/lib/python3.9/site-packages/pipx/util.py", line 129, in run
returncode = run_subprocess(
    File "/usr/local/Cellar/pipx/0.15.6.0/libexec/lib/python3.9/site-packages/pipx/util.py", line 116, in run_subprocess
return subprocess.run(
    File "/usr/local/Cellar/python@3.9/3.9.1_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 501, in run
with Popen(*popenargs, **kwargs) as process:
    File "/usr/local/Cellar/python@3.9/3.9.1_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
    File "/usr/local/Cellar/python@3.9/3.9.1_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1819, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
    FileNotFoundError: [Errno 2] No such file or directory: '/Users/Chris/.local/pipx/venvs/standardebooks/bin/python'

(For those who are unfamilar with the project, their install process is at the following URL.)

The SE maintainers believe this to be an upstream bug in pipx, but I am also not sure my setup is entirely correct either.

How to reproduce Install the Tools, then run pipx upgrade

Expected behavior pipx should download and install the latest version of the Tools.

uranusjr commented 3 years ago

This is a common issue if you pip install things against Homebrew’s python formula. The FoundNotFoundError message is slightly misleading—it is not the python command in the venv cannot be found, but the actual executable it points to (python is a symlink). Homebrew deletes old installations when upgrading a formula, so when it upgrades python, all things installed against it break.

There is really not much pipx can do; the best is to emit a better error message when this happens. Without Homebrew fixing this (extremely unlikely; this is the one most complained Homebrew issue for years at this point), the best advice I can provide is to not use Homebrew’s python formula at all. Use pyenv or an installer from python.org instead.

itsayellow commented 3 years ago

For the record, the typical fix for pipx venvs suffering after an upgraded Homebrew python is just to execute:

pipx reinstall-all

Then you should be able to continue as normal.

chrisfinazzo commented 3 years ago

@itsayellow, good to know. Was not aware of this.

I actually ripped out pipx for pipenv (and pipenv-virtualenv) so I don't have to deal with the craziness of trying to get Homebrew and the various Python package managers to play nicely together - see @uranusjr's comment - it's been a thorn in the side of the Brew maintainers for a long time.

I have used rbenv extensively on other projects, so this is likely a better fit and I'm not flying blind about what's going on.