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

sudo as user (-u) causes virtualenv to throw permission error #535

Closed
twiggy opened this issue Jan 8, 2014 · 11 comments
Closed

sudo as user (-u) causes virtualenv to throw permission error #535

twiggy opened this issue Jan 8, 2014 · 11 comments
Milestone

Comments

@twiggy
Copy link

twiggy commented Jan 8, 2014

If you run

virtualenv env

as the user you want it to be owned by it works fine.

If you have to do

sudo -u myuser virtualenv it will create the folder and python links fine, but then pip seems to fail with

OSError: [Errno 13] Permission denied: '/root/.distlib'

Full stack is

New python executable in arctic_py/bin/python
Installing setuptools, pip...
Complete output from command /opt/pyenv/arctic_py/bin/python -c "import sys, pip; pip...ll"] + sys.argv[1:])" setuptools pip:
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-1.5-py2.py3-none-any.whl/pip/init.py", line 11, in
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-1.5-py2.py3-none-any.whl/pip/vcs/subversion.py", line 4, in
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-1.5-py2.py3-none-any.whl/pip/index.py", line 16, in
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-1.5-py2.py3-none-any.whl/pip/wheel.py", line 23, in
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-1.5-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 15, in
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-1.5-py2.py3-none-any.whl/pip/_vendor/distlib/resources.py", line 105, in
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-1.5-py2.py3-none-any.whl/pip/_vendor/distlib/resources.py", line 40, in init
File "/usr/local/lib/python2.7/dist-packages/virtualenv_support/pip-1.5-py2.py3-none-any.whl/pip/_vendor/distlib/util.py", line 602, in get_cache_base
File "/opt/pyenv/arctic_py/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)

OSError: [Errno 13] Permission denied: '/root/.distlib'

...Installing setuptools, pip...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 9, in
load_entry_point('virtualenv==1.11', 'console_scripts', 'virtualenv')()
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 820, in main
symlink=options.symlink)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 988, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 956, in install_wheel
'PIP_NO_INDEX': '1'
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 898, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /opt/pyenv/arctic_py/bin/python -c "import sys, pip; pip...ll"] + sys.argv[1:])" setuptools pip failed with error code 1

Works fine if you don't have to use sudo -u. Worked before latest virtualenv.

@pg1671
Copy link

pg1671 commented Jan 8, 2014

+1 .. I am installing using the opscode python cookbook resources on a new Ubuntu 12.04 VM and this is the point where my install is failing as well.

Was working prior to the latest virtualenv update.

@pfmoore
Copy link
Member

pfmoore commented Jan 8, 2014

I'm not a Unix user, but if you do sudo like that, is your home directory set for the user you sudo to (i.e., is $HOME set - I think that's the key thing)? If not, this is probably caused by this distlib bug: https://bitbucket.org/pypa/distlib/issue/39/using-distlib-with-pip-fails-when-user-has

You can check by doing sudo -u myuser python -c 'import os; print(os.expanduser("~"))'. If that doesn't display the correct home directory, then the distlib issue is definitely relevant.

@pg1671
Copy link

pg1671 commented Jan 9, 2014

That makes sense as there is this PR on the opscode python recipe for virtualenv:
poise/python#72

Which sets the $HOME directory whenever it is being used.

Was working fine with all the older virtualenvs though.

Just made the changes suggested in the (amended) PR above and it fixes the problem.

@dstufft
Copy link
Member

dstufft commented Jan 12, 2014

Can you check the upgrade-pip-distlib branch and see if it solves this problem for you?

https://github.com/pypa/virtualenv/tree/upgrade-pip-distlib

@dstufft
Copy link
Member

dstufft commented Jan 14, 2014

I'm reproduced this issue and verified that the distlib in the upgrade-pip-distlib branch fixes this issue. So what we need to actually fix this issue is a new distlib release from @vsajip

@vsajip
Copy link

vsajip commented Jan 14, 2014

Okay. Before doing a release, I'd like to be sure that distlib issues #39 and #40 (relating to vendoring by pip) are resolved. I'll point people to the upgrade-pip-distlib branch to use for testing.

@dstufft
Copy link
Member

dstufft commented Jan 14, 2014

Ok @vsajip Hopefully soon :) we almost have everything taken care of for 1.11.1 and 1.5.1 and we'll want to start the RC process soon.

@dstufft
Copy link
Member

dstufft commented Jan 15, 2014

Hey @vsajip Any ETA on distlib btw? We've cleaned up all the other issues and are now just waiting on a new distlib to fix this issue.

@vsajip
Copy link

vsajip commented Jan 15, 2014

I haven't yet heard from the OP of https://bitbucket.org/pypa/distlib/issue/39#comment-7649881 that his issue (analogous to this) has been resolved, but I plan on doing a distlib release late tomorrow UTC (16 January) unless I hear there's a problem.

@dstufft
Copy link
Member

dstufft commented Jan 15, 2014

Sounds good, thanks.

@dstufft
Copy link
Member

dstufft commented Jan 17, 2014

Solved now in pip, the pip in virtualenv has been upgraded, and 1.11.1rc2 has been released.

@dstufft dstufft closed this as completed Jan 17, 2014
@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants