我想做
sudo su - some_user
source virtualenv/bin/activate
pip install psycopg2 gunicorn django-modeltranslation用布料。
如果我做了
with sudo_settings(sudo_user="some_user"):
with prefix("source virtualenv/bin/activate"):
sudo("pip install psycopg2 gunicorn django-modeltranslation")我得到了
目录'/home/coby/. cache /pip/http‘或其父目录不属于当前用户,缓存已被禁用。请检查该目录的权限和所有者。如果使用sudo执行pip,则可能需要sudo的-H标志。
之后是一个例外情况
Traceback (most recent call last):
File "/<home>/some_user/virtualenv/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/<home>/some_user/virtualenv/lib/python3.5/site-packages/pip/commands/install.py", line 324, in run
requirement_set.prepare_files(finder)
File "/<home>/some_user/virtualenv/lib/python3.5/site-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/<home>/some_user/virtualenv/lib/python3.5/site-packages/pip/req/req_set.py", line 554, in _prepare_file
require_hashes
File "/<home>/some_user/virtualenv/lib/python3.5/site-packages/pip/req/req_install.py", line 281, in populate_link
self.link = self._wheel_cache.cached_wheel(self.link, self.name)
File "/<home>/some_user/virtualenv/lib/python3.5/site-packages/pip/wheel.py", line 68, in cached_wheel
self._cache_dir, link, self._format_control, package_name)
File "/<home>/some_user/virtualenv/lib/python3.5/site-packages/pip/wheel.py", line 129, in cached_wheel
wheel_names = os.listdir(root)
PermissionError: [Errno 13] Permission denied: '/<home>/<sudo_user>/.cache/pip/wheels/cd/07/05/fa31adf8c1d71f5979e4329601d36c883f063ed0e99e5e29fa'UPD: pip install psycopg2 gunicorn --no-cache-dir工作。
发布于 2017-08-03 12:39:41
在shell中,您可以在source之后运行sudo,这是正确的,因为source是一个影响当前环境的shell内置程序。
您必须对fabric进行同样的操作:运行sudo()并在其内部调用source,而不是在外部调用。
当前的fab代码等效于
source virtualenv/bin/activate
sudo su - some_user
pip install psycopg2 gunicornhttps://stackoverflow.com/questions/45474811
复制相似问题