2017-08-03 68 views
0

我想用織物做面料 - 運行爲不同的用戶,但非須藤

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作品。

+0

是你能夠在不晶圓廠運行在服務器中的第一組命令的? –

+0

是的,我能夠通過SSH在服務器上運行第一組命令。 – Howdedo

回答

0

在shell中,在sudo之後運行source這是正確的,因爲source是影響當前環境的shell內建函數。

您必須對面料進行相同操作:運行sudo()並在其中調用source,而不是在外面。

您當前的工廠代碼相當於

source virtualenv/bin/activate 
sudo su - some_user 
pip install psycopg2 gunicorn 
相關問題