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

[docs]: sudo pipx does not work when pipx is installed with pip --user #1560

Open
Lordfirespeed opened this issue Oct 11, 2024 · 1 comment

Comments

@Lordfirespeed
Copy link

Lordfirespeed commented Oct 11, 2024

$ sudo pipx
sudo: pipx: command not found

This is a documentation issue (in my opinion) - having tried a few ways, I couldn't find a convenient command to call a --user installation of pipx as root.

Therefore, the remedial steps I would take here are

  • add a clause to the existing "pip --user" installation example in the README making clarifying that --user installations won't work for installing applications system-wide
  • add a "pip -H (not recommended)" installation example to the README
  • provide instructions for manually creating a 'managed by pipx'-like environment for pipx
@Lordfirespeed Lordfirespeed changed the title sudo pipx does not work when pipx is installed with pip --user [docs]: sudo pipx does not work when pipx is installed with pip --user Oct 11, 2024
@Lordfirespeed
Copy link
Author

Lordfirespeed commented Oct 11, 2024

Here's what I did to install pipx system-wide on a generic linux machine.

I chose to create a user for it because I wanted to use pipenv to simplify the update process, but one could just as easily skip that whole bit and install pipx into the venv with pip with /opt/pipx-cli owned by root.

  1. sudo adduser pipx-cli --group --system --disabled-password --home /opt/pipx-cli --shell /bin/bash - create
    a new user pipx-cli to manage pipx-cli
  2. export GLOBIGNORE=".:.." to ignore the special names ., .. from Bash glob results
  3. sudo cp /etc/skel/.* /opt/pipx-cli - /etc/skel is not used for system users, we have to do this ourselves
  4. sudo chown -R pipx-cli:pipx-cli /opt/pipx-cli/ - files copied from /etc/skel are still owned by root
  5. sudo chmod o+rx /opt/pipx-cli to enable read and execute perms to 'others' on pipx-cli's homedir
  6. sudo -u pipx-cli -i - start a login shell as user pipx-cli
  7. python3 -m pip install --user pipenv - install pipenv for pipx-cli
  8. source ~/.profile to add newly created directory containing the pipenv executable to $PATH
  9. mkdir .venv && pipenv install pipx - create a new virtualenv, .venv, using pipenv which contains pipx
  10. nano pipx-cli - create a new script named pipx-cli. Provide the contents:
    #!/bin/bash
    
    # https://stackoverflow.com/a/77663806/11045433
    DIRNAME=$(dirname $( readlink -f "${BASH_SOURCE[0]:-"$(command -v -- "$0")"}" ))
    
    source $DIRNAME/.venv/bin/activate
    pipx $@
    Press ctrl+x, then y, then Enter to save the file.
  11. chmod a+x pipx-cli - for all users (a), add (+) the permission to execute (x) pipx-cli
  12. Press ctrl+d to end the session as pipx-cli
  13. sudo ln -s /opt/pipx-cli/pipx-cli /usr/local/bin/pipx - make a command, pipx, available system-wide that invokes
    the pipx-cli script

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