2

I created a virtual environment for python3.5 using python3 -m venv --system-site-packages <venv>.

Now when installing packages inside the virtual environment using pip3 I get the following error:

PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.5/site-packages'

Why does pip want to install the packages at /usr/lib/python3.5/site-packages and not at <venv>/lib/python3.5/site-packages?

TylerH
  • 20,799
  • 66
  • 75
  • 101
McLawrence
  • 4,975
  • 7
  • 39
  • 51
  • Have you activated your virtualenv? – eyllanesc May 24 '17 at 13:19
  • yes. its name is in brackets before the bash prompt – McLawrence May 24 '17 at 13:20
  • Install with pip, do not use pip3 – eyllanesc May 24 '17 at 13:21
  • I tried that as well. I can just type `pip install , can I? Or do I have to indicate somehow to use a pip for my virtual environment? – McLawrence May 24 '17 at 13:23
  • It's because you used the option `--system-site-packages`. Based on the [documentation](https://virtualenv.pypa.io/en/stable/userguide/#the-system-site-packages-option), it says, **This can be used if you have control over the global site-packages directory, and you want to depend on the packages there. If you want isolation from the global system, do not use this flag.** – Scratch'N'Purr May 24 '17 at 13:23
  • Yes. I wanted that (and I control the global directory). Just did not want to use `sudo` if not necessary. But I think i fixed it. Using `python -m pip install` istead of `pip install` does not produce the error. – McLawrence May 24 '17 at 13:25
  • 1
    I faced similar kind of problem to solve it I tried to create new virtualenv which didn't solve problem so I reconfigured PATH, pip and created new virtualenv. – Gahan May 24 '17 at 13:28
  • Can you elaborate on what exactly you reconfigured? – McLawrence May 24 '17 at 13:29

1 Answers1

3

If you want pip to install the packages at <venv>/lib/python3.5/site-packages, please create the virtual environment by this way: python3 -m venv <venv>

By the way, I usually create virtual environment as follows: alias venv='virtualenv --python=python3 venv' alias actvenv='source venv/bin/activate' venv actvenv

williezh
  • 917
  • 5
  • 8
  • 1
    ok. so the `system-site-packages` is the cause of the problem? I have verified now that using `python -m pip install` does install in the virtual environment, whereas pip install does not in this case – McLawrence May 24 '17 at 13:48