I have installed virtualenv
with sudo apt-get install virtualenv
. It stands in this tutorial that you need to use your env/bin/
folder's own pip
or pip3
command to install modules in the virtual environment, and it is explicitly stated that you don't use sudo
to do this.
Unfortunately that doesn't work for me, I get a PermissionError
when I try doing that. But using sudo before pip3
will install the module globally, so I won't get to take advantage of having a virtual environment at all.
E.g. when in my env/bin/ folder, I run pip3 install pytest
:
Collecting pytest
Downloading pytest-3.0.7-py2.py3-none-any.whl (172kB)
100% |████████████████████████████████| 174kB 1.2MB/s
Collecting py>=1.4.29 (from pytest)
Downloading py-1.4.33-py2.py3-none-any.whl (83kB)
100% |████████████████████████████████| 92kB 2.1MB/s
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from pytest)
Installing collected packages: py, pytest
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/local/lib/python3.5/dist-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/usr/local/lib/python3.5/dist-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/usr/local/lib/python3.5/dist-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/usr/local/lib/python3.5/dist-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/usr/local/lib/python3.5/dist-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/usr/local/lib/python3.5/dist-packages/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/usr/local/lib/python3.5/dist-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/usr/lib/python3.5/os.py", line 241, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/py-1.4.33.dist-info'
How do I get started using virtualenv
on Ubuntu 16.04 in less painful way?
./activate
, orsudo activate
. Nothing worked.source
it. The command to do that is mentioned in the link you gave:source env/bin/activate
.source
in the section coming after demonstrating the basic usage ofvirtualenv
. That's where I got tripped off.pytest
?