pypa / pipx

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

Installation instructions don't work (pyenv problems) #208

Closed anentropic closed 11 months ago

anentropic commented 5 years ago
 ~ $ python3 -m pip install --user pipx
Collecting pipx
  Downloading https://files.pythonhosted.org/packages/bd/16/4dd481c913d748928df79a78dfbf6ce3f42ec5382b630d78f3fd0ef0d8bd/pipx-0.14.0.0-py3-none-any.whl
Collecting userpath (from pipx)
  Downloading https://files.pythonhosted.org/packages/8c/71/72611cc9aed89374326645a4069787328db573c842e4e37b78c022b18146/userpath-1.2.0-py2.py3-none-any.whl
Collecting argcomplete<2.0,>=1.9.4 (from pipx)
  Downloading https://files.pythonhosted.org/packages/4d/82/f44c9661e479207348a979b1f6f063625d11dc4ca6256af053719bbb0124/argcomplete-1.10.0-py2.py3-none-any.whl
Collecting distro (from userpath->pipx)
  Downloading https://files.pythonhosted.org/packages/ea/35/82f79b92fa4d937146c660a6482cee4f3dfa1f97ff3d2a6f3ecba33e712e/distro-1.4.0-py2.py3-none-any.whl
Collecting click (from userpath->pipx)
  Using cached https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl
Installing collected packages: distro, click, userpath, argcomplete, pipx
  WARNING: The script distro is installed in '/Users/anentropic/Library/Python/3.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script userpath is installed in '/Users/anentropic/Library/Python/3.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script pipx is installed in '/Users/anentropic/Library/Python/3.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed argcomplete-1.10.0 click-7.0 distro-1.4.0 pipx-0.14.0.0 userpath-1.2.0
 ~ $ python3 -m pipx ensurepath
The directory `/Users/anentropic/.local/bin` is already in PATH. If you are sure you want to proceed, try again with the '--force' flag.

Otherwise pipx is ready to go! ✨ 🌟 ✨
 ~ $ pipx run https://raw.githubusercontent.com/pipxproject/pipx/master/scripts/migrate_pipsi_to_pipx.py
-bash: pipx: command not found

I guess this is some kind of unanticipated interaction with pyenv

This fixed it:

$ pip uninstall pipx
$ pyenv shell 3.7.4
$ pip install pipx

it was the pyenv shell specifically which seemed to be out of sync, before setting that it had installed pipx to one of my other python 3s which was not currently on the PATH

anentropic commented 5 years ago

maybe I'm supposed to install it to the non-pyenv system python3 though?

there are problems with completions as I have it currently

$ source ~/.bashrc
pyenv: register-python-argcomplete: command not found

The `register-python-argcomplete' command exists in these Python versions:
  3.7.4
frapbod commented 5 years ago

I was running into the exact same problem, at least with the command not found issue.

I'd have the command not found after starting the shell but i'd be able to run the eval afterwards and it would work, my problem was that I had the eval "$(register-python-argcomplete pipx)" before I sourced the pyenv completion.

Seeing as how yours still doesn't find the command afterwards I'd look into seeing if you have pyenv completions set up in your ~/.bashrc at all.

anentropic commented 4 years ago

I come here to ask how to get pipx working when you already have pyenv installed... and I find I already asked 6 months ago, with no resolution.

I really want to follow the installation instructions https://pipxproject.github.io/pipx/installation/ rather than have a weird hacked together set up...

But they don't work if you already have pyenv installed.

Firstly:

$ python3 -m pip install --user pipx
pyenv: python3: command not found
$ brew install python
Warning: python 3.7.6_1 is already installed, it's just not linked
You can use `brew link python` to link this version.

$ brew link python
Linking /usr/local/Cellar/python/3.7.6_1...
Error: Could not symlink Frameworks/Python.framework/Headers
Target /usr/local/Frameworks/Python.framework/Headers
is a symlink belonging to python@2. You can unlink it:
  brew unlink python@2

To force the link and overwrite all conflicting files:
  brew link --overwrite python

To list all files that would be deleted:
  brew link --overwrite --dry-run python

$ brew link --overwrite python
Linking /usr/local/Cellar/python/3.7.6_1... 28 symlinks created

$ python3
Python 3.7.6 (default, Dec 30 2019, 19:38:28)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

ok I guess we're ready to try again...

python3 -m pip install --user pipx
Collecting pipx
  Downloading https://files.pythonhosted.org/packages/c3/63/b461c6996147fe72f7af6a1e108c817a8fa41d9bd744863b4993c8788553/pipx-0.15.1.3-py3-none-any.whl
Requirement already satisfied: argcomplete<2.0,>=1.9.4 in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from pipx) (1.10.0)
Requirement already satisfied: userpath in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from pipx) (1.2.0)
Requirement already satisfied: click in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from userpath->pipx) (7.0)
Requirement already satisfied: distro in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from userpath->pipx) (1.4.0)
Installing collected packages: pipx
  WARNING: The script pipx is installed in '/Users/anentropic/Library/Python/3.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pipx-0.15.1.3

$ python3 -m pipx ensurepath
The directory `/Users/anentropic/.local/bin` is already in PATH. If you are sure you want to proceed, try again with the '--force' flag.

Otherwise pipx is ready to go! ✨ 🌟 ✨

Cool, let's try the next step:

$ pipx completions
pyenv: pipx: command not found

The `pipx' command exists in these Python versions:
  3.7.4

$ which pipx
/Users/anentropic/.pyenv/shims/pipx

Ugh.

Let's get rid of this pipx I installed under a pyenv version previously...

$ pyenv shell 3.7.4

$ pip uninstall pipx
Uninstalling pipx-0.14.0.0:
  Would remove:
    /Users/anentropic/.pyenv/versions/3.7.4/bin/pipx
    /Users/anentropic/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipx-0.14.0.0.dist-info/*
    /Users/anentropic/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pipx/*
Proceed (y/n)? y
  Successfully uninstalled pipx-0.14.0.0

$ pyenv version
3.7.4 (set by /Users/anentropic/.pyenv/version)

$ rm /Users/anentropic/.pyenv/version

$ pyenv version
system (set by /Users/anentropic/.pyenv/version)

$ python3
Python 3.7.6 (default, Dec 30 2019, 19:38:28)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

$ pipx
-bash: /Users/anentropic/.pyenv/shims/pipx: No such file or directory

Ok we're clean, let's install it again under system Python 3.7.6?

$ python3 -m pip install --user pipx
Requirement already satisfied: pipx in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (0.15.1.3)
Requirement already satisfied: argcomplete<2.0,>=1.9.4 in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from pipx) (1.10.0)
Requirement already satisfied: userpath in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from pipx) (1.2.0)
Requirement already satisfied: click in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from userpath->pipx) (7.0)
Requirement already satisfied: distro in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from userpath->pipx) (1.4.0)

$ python3 -m pipx ensurepath
The directory `/Users/anentropic/.local/bin` is already in PATH. If you are sure you want to proceed, try again with the '--force' flag.

Otherwise pipx is ready to go! ✨ 🌟 ✨

$ source ~/.bashrc

$ pipx
-bash: pipx: command not found

FFS

anentropic commented 4 years ago

after reading https://github.com/standardebooks/tools/issues/188 I can report that installing without --user flag as suggested there works (after all of the above):

$ python3 -m pip uninstall pipx
Uninstalling pipx-0.15.1.3:
  Would remove:
    /Users/anentropic/Library/Python/3.7/bin/pipx
    /Users/anentropic/Library/Python/3.7/lib/python/site-packages/pipx-0.15.1.3.dist-info/*
    /Users/anentropic/Library/Python/3.7/lib/python/site-packages/pipx/*
Proceed (y/n)? y
  Successfully uninstalled pipx-0.15.1.3

$ python3 -m pip install pipx
Collecting pipx
  Using cached https://files.pythonhosted.org/packages/c3/63/b461c6996147fe72f7af6a1e108c817a8fa41d9bd744863b4993c8788553/pipx-0.15.1.3-py3-none-any.whl
Requirement already satisfied: argcomplete<2.0,>=1.9.4 in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from pipx) (1.10.0)
Requirement already satisfied: userpath in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from pipx) (1.2.0)
Requirement already satisfied: distro in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from userpath->pipx) (1.4.0)
Requirement already satisfied: click in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from userpath->pipx) (7.0)
Installing collected packages: pipx
Successfully installed pipx-0.15.1.3

$ pipx --version
0.15.1.3

🎉 🎉 🎉

anentropic commented 4 years ago

the bash completions need an extra step to work (due to a dependency was previously installed with --user)...

$ source ~/.bashrc
pyenv: register-python-argcomplete: command not found

The `register-python-argcomplete' command exists in these Python versions:
  3.7.4

to fix this we do the same uninstall and reinstall as above:

$ python3 -m pip uninstall argcomplete
  Successfully uninstalled argcomplete-1.10.0

$ python3 -m pip install argcomplete

$ pipx
--help         -h             ensurepath     install        reinstall-all  runpip         uninstall-all  upgrade-all
--version      completions    inject         list           run            uninstall      upgrade

🎉 🎉 🎉

itsayellow commented 4 years ago

The current instructions for macOS (which I assume you're using because you're using Homebrew are (from the README.md at https://github.com/pipxproject/pipx):

On macOS:

brew install pipx
pipx ensurepath

I think the key here is that https://pipxproject.github.io/pipx/installation/ does not have the OS-specific installation instructions that README.md does. We need to fix that.

Another thing to note is that when you install using pip install --user pipx the pipx binary is put in a specific directory that depends on which python you are using. This may or may not already be in your PATH if you're using a non-standard python (like one of the pyenv versions.) The pipx ensurepath step only puts the binary directory for your pipx packages in your path. I suppose we could look at ensuring that pipx is in your path also at this step.

cs01 commented 4 years ago

I suppose we could look at ensuring that pipx is in your path also at this step.

We ran into this before and updated the instructions, which currently have this

Assuming you have pip installed for python3, run:

python3 -m pip install --user pipx
python3 -m pipx ensurepath
itsayellow commented 4 years ago

That works for the purpose of running pipx ensurepath, but as far as I understand it, that subcommand doesn't actually check if pipx itself is in the user's path.

rolep commented 4 years ago

The way I install pipx while using pyenv:

desired outcome is to have pipx available globally for the user without poisoning pyenv python versions - keep them pristine: install pipx into separate environment aka pipx install pipx

sergenti commented 3 years ago

after reading standardebooks/tools#188 I can report that installing without --user flag as suggested there works (after all of the above):

$ python3 -m pip uninstall pipx
Uninstalling pipx-0.15.1.3:
  Would remove:
    /Users/anentropic/Library/Python/3.7/bin/pipx
    /Users/anentropic/Library/Python/3.7/lib/python/site-packages/pipx-0.15.1.3.dist-info/*
    /Users/anentropic/Library/Python/3.7/lib/python/site-packages/pipx/*
Proceed (y/n)? y
  Successfully uninstalled pipx-0.15.1.3

$ python3 -m pip install pipx
Collecting pipx
  Using cached https://files.pythonhosted.org/packages/c3/63/b461c6996147fe72f7af6a1e108c817a8fa41d9bd744863b4993c8788553/pipx-0.15.1.3-py3-none-any.whl
Requirement already satisfied: argcomplete<2.0,>=1.9.4 in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from pipx) (1.10.0)
Requirement already satisfied: userpath in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from pipx) (1.2.0)
Requirement already satisfied: distro in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from userpath->pipx) (1.4.0)
Requirement already satisfied: click in /Users/anentropic/Library/Python/3.7/lib/python/site-packages (from userpath->pipx) (7.0)
Installing collected packages: pipx
Successfully installed pipx-0.15.1.3

$ pipx --version
0.15.1.3

🎉 🎉 🎉

this worked for me, thanks!

bjf5201 commented 6 days ago

The way I install pipx while using pyenv:

desired outcome is to have pipx available globally for the user without poisoning pyenv python versions - keep them pristine: install pipx into separate environment aka pipx install pipx

  • install pyenv-virtualenv pyenv plugin (i.e. clone it into ${PYENV_ROOT}/plugins)
  • create separate virtualenv just for pipx (so regular pyenv's python version stays pristine): pyenv virtualenv 3.7.7 pipx specifying python version to be used for pipx env.
  • install pipx inside new virtualenv

    pyenv activate pipx
    pip install pipx
    pyenv deactivate

    Now, pipx is available in ${PYENV_ROOT}/shims. If you are using pyenv - this directory should already be in your PATH (added by eval "$(pyenv init - )").

  • in order to always run pipx from within its virtualenv, not from active pyenv python, add PYENV_VERSION=pipx to pipx command (pyenv virtualenv name used in venv creation step) which we preserve in .bashrc:

    alias pipx='PYENV_VERSION=pipx pipx'
    
    # pipx completion, place after pyenv init
    if command -v pipx 1>/dev/null 2>&1; then
    eval "$(PYENV_VERSION=pipx register-python-argcomplete pipx)"
    fi

This worked for me after I tried anentropic's suggestion of uninstalling pipx and then reinstalling it without the --user flag. I am using WSL2, Ubuntu 22.04 Bash shell on a Windows 10.

I was having the issue where even though reinstalling pipx without the --user flag (via python3 -m pip install pipx) would install the pipx binary to /home/bethany/.pyenv directory, it would assume that it didn't need to install its dependencies because they were still available inside the /home/bethany/.local directory. So, I tried manually removing the /home/bethany/.local directory using sudo rm -rf /home/bethany/.local . (Note: I ensured that I only had the recently installed pipx dependencies inside this folder before removing it!)

This still was ineffective because even though the python3 -m pip install pipx command would install pipx and its dependencies inside the /home/bethany/.pyenv directory, when I ran pipx inside my shell it would complain that there was no pipx command found inside of the /home/bethany/.local directory.

However, after following the above instructions everything works just fine! After running:

$ pyenv virtual env pipx 3.13.0
$ pyenv activate pipx
$ pip3 install pipx
Installing collective packages: platformdirs, packaging, argcomplete, click, userpath, pipx
Successfully installed argcomplete-3.5.1, click-8.1.7, packaging-24.1, pipx-1.7.1, platformdirs-4.3.6, userpath-1.9.2
$ pyenv deactivate
$ echo "alias pipx=`PYENV_VERSION=pipx pipx`" >> ~/.bashrc
$ pipx --version
pipx-1.7.1
$ which pipx
pipx is aliased to `PYENV_VERSION=pipx pipx`
pipx is /home/bethany/.pyenv/shims/pipx

Everything is working great! I actually didn't even have to manually install pyenv-virtualenv, I guess with the most recent pyenv I had installed (pyenv-2.4.16) the pyenv-virtualenv plugin is installed automatically along with pyenv.