pipx icon indicating copy to clipboard operation
pipx copied to clipboard

pipx install [pkg] - PermissionError: [Errno 13] Permission denied

Open guyjacks opened this issue 4 years ago • 8 comments

FYI https://pipxproject.github.io/pipx/troubleshooting/ gives a 404 error

MacOS Big Sur 11.1

$ pipx install pipenv

Traceback (most recent call last): File "/usr/local/Cellar/pipx/0.15.6.0/libexec/bin/pipx", line 33, in 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 156, in run_pipx_command return commands.install( File "/usr/local/Cellar/pipx/0.15.6.0/libexec/lib/python3.9/site-packages/pipx/commands/install.py", line 64, in install run_post_install_actions( File "/usr/local/Cellar/pipx/0.15.6.0/libexec/lib/python3.9/site-packages/pipx/commands/common.py", line 321, in run_post_install_actions expose_apps_globally( File "/usr/local/Cellar/pipx/0.15.6.0/libexec/lib/python3.9/site-packages/pipx/commands/common.py", line 29, in expose_apps_globally _symlink_package_apps(local_bin_dir, app_paths, force=force, suffix=suffix) File "/usr/local/Cellar/pipx/0.15.6.0/libexec/lib/python3.9/site-packages/pipx/commands/common.py", line 110, in _symlink_package_apps symlink_path.symlink_to(app_path) File "/usr/local/Cellar/[email protected]/3.9.1_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pathlib.py", line 1398, in symlink_to self._accessor.symlink(target, self, target_is_directory) File "/usr/local/Cellar/[email protected]/3.9.1_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/pathlib.py", line 445, in symlink return os.symlink(a, b) PermissionError: [Errno 13] Permission denied: '/Users/guyjacks/.local/pipx/venvs/pipenv/bin/pipenv' -> '/Users/guyjacks/.local/bin/pipenv'

guyjacks avatar Dec 23 '20 05:12 guyjacks

I also tried installing cowsay and got the same problem.

guyjacks avatar Dec 23 '20 05:12 guyjacks

It looks like somehow you don't have write permission to the /Users/guyjacks/.local/bin directory. I'm guessing that either /Users/guyjacks/.local/bin is read-only, or that it shows up as owned by a different user than the one you are using to execute pipx install pipenv.

What is the output if you execute

ls -l /Users/guyjacks/.local

Does it work if you try to create a file in that directory, like:

touch /Users/guyjacks/.local/bin/testfile

If it is read-only (i.e. the above ls -l command shows the bin subdirectory as dr-xr-xr-x) then to fix you could do:

chmod -R u+w /Users/guyjacks/.local/bin

itsayellow avatar Dec 23 '20 05:12 itsayellow

Thanks @itsayellow.

I tried setting those permissions and it didn't work. I think the problem is that the user for the bin directory is root instead of me. I'm not certain if its safe to change the user for those files to me. It does seem odd to me that anything in "~/.local" would require the root user.

How is the output of "ls -l"

$ ls -l total 0 drwxr-xr-x 29 root staff 928 Aug 3 2017 bin drwx------ 3 root staff 96 Aug 3 2017 lib drwxr-xr-x 5 guyjacks staff 160 Dec 23 00:09 pipx drwxr-xr-x 5 guyjacks staff 160 Aug 11 2019 share

guyjacks avatar Dec 23 '20 06:12 guyjacks

You could sudo chown -R guyjacks /Users/guyjacks/.local/bin, but I’d first check why those directories belong to root. Are there existing files there? How did they get there?

uranusjr avatar Dec 23 '20 06:12 uranusjr

Yeah there are. I'm guessing that aws cli put a bunch of stuff in there. I have no idea if its safe to change the user on those files. Can pipx use a different directory?

-rwxr-xr-x 1 root staff 850 Aug 3 2017 aws -rwxr-xr-x 1 root staff 1432 Aug 3 2017 aws.cmd -rwxr-xr-x 1 root staff 204 Aug 3 2017 aws_bash_completer -rwxr-xr-x 1 root staff 1171 Aug 3 2017 aws_completer -rwxr-xr-x 1 root staff 1807 Aug 3 2017 aws_zsh_completer.sh -rwxr-xr-x 1 root staff 1710 Aug 3 2017 jp.py -rwxr-xr-x 1 root staff 250 Aug 3 2017 pyrsa-decrypt -rwxr-xr-x 1 root staff 266 Aug 3 2017 pyrsa-decrypt-bigfile -rwxr-xr-x 1 root staff 250 Aug 3 2017 pyrsa-encrypt -rwxr-xr-x 1 root staff 266 Aug 3 2017 pyrsa-encrypt-bigfile -rwxr-xr-x 1 root staff 248 Aug 3 2017 pyrsa-keygen -rwxr-xr-x 1 root staff 271 Aug 3 2017 pyrsa-priv2pub -rwxr-xr-x 1 root staff 244 Aug 3 2017 pyrsa-sign -rwxr-xr-x 1 root staff 248 Aug 3 2017 pyrsa-verify -rwxr-xr-x 1 root staff 629 Aug 3 2017 rst2html.py -rwxr-xr-x 1 root staff 749 Aug 3 2017 rst2html4.py -rwxr-xr-x 1 root staff 1174 Aug 3 2017 rst2html5.py -rwxr-xr-x 1 root staff 826 Aug 3 2017 rst2latex.py -rwxr-xr-x 1 root staff 635 Aug 3 2017 rst2man.py -rwxr-xr-x 1 root staff 799 Aug 3 2017 rst2odt.py -rwxr-xr-x 1 root staff 1733 Aug 3 2017 rst2odt_prepstyles.py -rwxr-xr-x 1 root staff 636 Aug 3 2017 rst2pseudoxml.py -rwxr-xr-x 1 root staff 672 Aug 3 2017 rst2s5.py -rwxr-xr-x 1 root staff 906 Aug 3 2017 rst2xetex.py -rwxr-xr-x 1 root staff 637 Aug 3 2017 rst2xml.py -rwxr-xr-x 1 root staff 705 Aug 3 2017 rstpep2html.py

guyjacks avatar Dec 23 '20 06:12 guyjacks

You can set the PIPX_BIN_DIR environment variable to customise it. Remember to add whatever you set to your PATH.

uranusjr avatar Dec 23 '20 09:12 uranusjr

I think it would also allow pipx to use that directory if you only changed the ownership of the directory itself, i.e. if you omit the -R in @uranusjr 's example like this:

sudo chown guyjacks /Users/guyjacks/.local/bin

...if you wanted another option that would not touch the ownership of the aws files inside of /Users/guyjacks/.local/bin, but would still change the ownership of /Users/guyjacks/.local/bin itself.

itsayellow avatar Dec 23 '20 23:12 itsayellow

A slight tangent, but I suppose we should do a check on the directory to make sure permissions are available, and give a more user-friendly error if it fails. We shouldn't ever be showing a stack trace to the user if we can avoid it.

cs01 avatar Dec 24 '20 04:12 cs01

i resolve issue by simply creating 2 folders in /Users/$(whoami)/.local/. On my side these two folder were not created before.

sudo mkdir /Users/$(whoami)/.local/bin
sudo mkdir /Users/$(whoami)/.local/pipx

When i rerun pipx ensurepath i got :

⚠️  All pipx binary directories have been added to PATH. If you are sure you want to proceed, try again with the '--force' flag.

Otherwise pipx is ready to go! ✨ 🌟 ✨

ThePredators avatar Sep 04 '23 10:09 ThePredators