4

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:

  https://setuptools.readthedocs.io/en/latest/easy_install.html

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.

  • you have python3.6, try python3 setup.py install – abu-ahmed al-khatiri Sep 27 '18 at 13:21
  • Same error message. Since I installed the virtualenv with python3, python --version gives me 3.6.6 inside the virtualenv. So there shouldn't be a difference. – CGFoX Sep 27 '18 at 13:24
  • try to sudo chmod 755 /home/stefan/git-repos/tng-sdk-project/venv/lib/python3.6/site-packages/ and run python3 setup.py install again – abu-ahmed al-khatiri Sep 27 '18 at 13:52
  • Same error message (2nd one): error: can't create or remove files in install directory – CGFoX Sep 27 '18 at 14:00
  • I even tried reinstalling python3 and python3-pip. But without success. – CGFoX Sep 27 '18 at 14:05

Your Answer

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

Browse other questions tagged or ask your own question.