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

Python pip uses wrong cache path in chroot #4290

Closed
guysoft opened this issue Feb 18, 2017 · 3 comments
Closed

Python pip uses wrong cache path in chroot #4290

guysoft opened this issue Feb 18, 2017 · 3 comments
Labels
auto-locked Outdated issues that have been locked by automation

Comments

@guysoft
Copy link

guysoft commented Feb 18, 2017

  • Pip version: 9.0.1
  • Python version: 2.7
  • Operating system: Hypervisor: Ubuntu 16.10, chroot - Armbian OrangePi PC.

Description:

I am trying to run sudo -u pi /home/pi/oprint/bin/pip install cryptography as part of OctoPi's build, which runs inside a chroot script.

However it seems that this command somehow managed to see beyond the chroot and resolves the cache folder to be /home/pi/.cache/pip. Where guy is the user outside my chroot. I am not sure even how it knows that. But it does, and it breaks the installation.
This happens only in the Ubuntu chroot, not in the Debian Jessie one.

Adding the -H option to the sudo fixes the install, and is the current workaround i am using, but still the cache folder is shows up in this line options.cache_dir variable (if I stick a print line I can see that options.cache_dir is pointing out of the chroot, even with -H flag on.

Two questions:

  1. Is there a way to fix this without using the -H option?
  2. Where is the options.cache_dir variable resolved in pip? Is there a way to fix it?

What I've run:

sudo -u pi /home/pi/oprint/bin/pip install  cryptography

log:

+ sudo -u pi /home/pi/oprint/bin/pip install cryptography
The directory '/home/guy/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/guy/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting cryptography
Exception:
Traceback (most recent call last):
  File "/home/pi/oprint/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/pip/commands/install.py", line 299, in run
    requirement_set.prepare_files(finder)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/pip/req/req_set.py", line 370, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/home/pi/oprint/local/lib/python2.7/site-packages/pip/req/req_set.py", line 522, in _prepare_file
    finder, self.upgrade, require_hashes)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/pip/req/req_install.py", line 271, in populate_link
    self.link = self._wheel_cache.cached_wheel(self.link, self.name)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/pip/wheel.py", line 68, in cached_wheel
    self._cache_dir, link, self._format_control, package_name)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/pip/wheel.py", line 129, in cached_wheel
    wheel_names = os.listdir(root)
OSError: [Errno 13] Permission denied: '/home/guy/.cache/pip/wheels/3e/09/be/ca344cd1e68fd4d4d8872a25287e884a6f73557710efa51019'
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
@dstufft
Copy link
Member

dstufft commented Feb 19, 2017

We're just using os.path.expanduser("~/.cache/pip") which uses the $HOME variable to replace ~ unless that isn't set, then it looks the user's home directory up in the passwd database. The reason sudo -H fixes this, is because by default sudo doesn't change the $HOME directory when you run a command.

@guysoft
Copy link
Author

guysoft commented Feb 23, 2017

Strange, because it finds the home user outside the chroot. It might mean the $HOME variable does not update when executing chroot.
What makes no sense is that all other commands seem to figure it out.
Ideas on testing this are welcome.

@dstufft
Copy link
Member

dstufft commented Mar 31, 2017

This is going to be either an environment bug or a Python bug of some kind. We're just using the standard library APIs. I would see if you get the same behavior just doing python -c "import os.path; print(os.path.expanduser('~'))" and if so, report it upstream to Python itself.

@dstufft dstufft closed this as completed Mar 31, 2017
@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 3, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation
Projects
None yet
Development

No branches or pull requests

2 participants