首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >作为一个不同的用户运行,但非sudo

作为一个不同的用户运行,但非sudo
EN

Stack Overflow用户
提问于 2017-08-03 04:25:32
回答 1查看 207关注 0票数 0

我想做

代码语言:javascript
复制
sudo su - some_user
source virtualenv/bin/activate
pip install psycopg2 gunicorn django-modeltranslation

用布料。

如果我做了

代码语言:javascript
复制
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标志。

之后是一个例外情况

代码语言:javascript
复制
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工作。

EN

回答 1

Stack Overflow用户

发布于 2017-08-03 12:39:41

在shell中,您可以在source之后运行sudo,这是正确的,因为source是一个影响当前环境的shell内置程序。

您必须对fabric进行同样的操作:运行sudo()并在其内部调用source,而不是在外部调用。

当前的fab代码等效于

代码语言:javascript
复制
source virtualenv/bin/activate
sudo su - some_user
pip install psycopg2 gunicorn
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45474811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档