Closed luzfcb closed 8 months ago
Hmm. Strange. In 30 years of using Linux I have never encountered this problem.
After digging some in the sudo manuals, I think possibly your /etc/sudoers have a Defaults !env_reset
line in it, where the default is Defaults env_reset
which should mean that sudo resets the env, including $HOME?
But I'm not sure, it's all a bit unclear, so that's just a guess.
I had this problem multiple times when I was new to Python and didn't understand how pip's cache works. At that time pip did not display a useful error message:
https://github.com/pypa/pip/blob/f5e4ee104e7b171a7cfb2843c9c602abf7a4e346/src/pip/_internal/cli/req_command.py#L220-L226 https://github.com/pypa/pip/blob/f5e4ee104e7b171a7cfb2843c9c602abf7a4e346/src/pip/_internal/cli/base_command.py#L163-L172
At that time, if I run sudo pip install foo-package
and then pip install bar-package
, you may have a permission problem because pip is trying to save some of the dependencies in the pip's cache subdirectory that does not have the same permissions as the current non-root user.
My intention with this pull-request is only to correct the use of sudo
or pip
to avoid introducing permissions problems in the non-root user's HOME pip cache directory
After digging some in the sudo manuals, I think possibly your /etc/sudoers have a Defaults !env_reset line in it, where the default is Defaults env_reset which should mean that sudo resets the env, including $HOME?
Although it may be a solution, I think it is beyond the scope of unoserver
because it is a problem on pip
itself and how it interacts with sudo
, and that problem will not be resolved by pip
at all because is also out of pip scope
That warning doesn't have anything to do with the .cache directory, and in fact pip checks the permissions, and if it encounters the error you have, it warns you, and that has seemingly been the case for 5 years. Pip warns against using sudo for other reasons, and recommends using a virtualenv, but the point of this readme is that a virtualenv will not work with unoserver (although it will work fine for the unoconvert and unocompare commands).
But then again, adding -H doesn't hurt, I guess.
Motivation and Context
Assuming that I am a regular Linux user named
luzfcb
, with the HOME folder located in/home/luzfcb
and the$HOME
environment variable pointing to/home/luzfcb
sudo
without-H
modifier will run the command withroot
permissions, but using the$HOME
environment variable of the current user ( not theroot
)pip
will use the$HOME
environment variable to create a cache directory on/home/luzfcb/.cache/pip/
, but all new files/directories will be created withroot
permission, and root-only read permission; that is, theluzfcb
user has nowrite
orread
permission to some of the directories inside/home/luzfcb/.cache/pip/
.sudo
with the-H
modifier will run the command withroot
permissions and use theroot
user's$HOME
environment variable instead of the current user's$HOME
.So, if we use
sudo
with the-H
modifier to runpip
, thepip
will use the$HOME
environment variable of the root user to create a cache directory on/root/.cache/pip/
, and all future sufferings will be avoided :-) .Another option, to not use
sudo
with-H
, is usepip
with--no-cache-dir
Description
This pull-request adds the
-H
modifier thesudo
when it is used thepip
on the Readme