Virtualenv Permission denied when trying python setup.py install

I want to use virtualenv with Python 3 on Ubuntu 18.04. Specifically, I'm using Python 3.6.6 and virtualenv 16.0.0.

  1. I installed virtualenv with sudo as suggested in the answers here: sudo pip3 install --upgrade virtualenv

  2. I created a new virtualenv using python3 -m virtualenv venv. And activated it as usual: source venv/bin/activate.

  3. When I try to install my Python project with python setup.py install I get the following error message:

 running install running bdist_egg running egg_info error: [Errno 13] Permission denied

If I use sudo to create the virtualenv in step 2, then I get a different error message in step 3:

error: can't create or remove files in install directory
The following error occurred while trying to add or remove files in the
installation directory: [Errno 13] Permission denied: '/home/stefan/git-repos/tng-sdk-project/venv/lib/python3.6/site-packages/test-easy-install-3769.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was: /home/stefan/git-repos/tng-sdk-project/venv/lib/python3.6/site-packages/
Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.
For information on other options, you may wish to consult the
documentation at:
Please make the appropriate changes for your system and try again.

I've been googling and trying stuff for hours now and I can't get it to work properly. It seems like whatever I try leads to more, new errors... Any ideas?

Well, sudo python setup.py install works inside the virtualenv, but this can't be the solution.

6

1 Answer

Most probably used sudo for some instructions that create some folder with root ownership.

  1. Deactivate the virtual env.

  2. Try fix owner recursively:

    sudo chown -R stefan:stefan /home/stefan/git-repos/tng-sdk-project/
  3. Activate virtual env and test it.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like