I create a python3
virtual environment (explicitly avoiding symlinks, with --copies
):
» python3 -m venv --without-pip --copies venv
This is my complete virtual environment now:
» tree venv/
venv/
├── bin
│ ├── activate
│ ├── activate.csh
│ ├── activate.fish
│ ├── python
│ └── python3
├── include
├── lib
│ └── python3.4
│ └── site-packages
├── lib64 -> lib
└── pyvenv.cfg
I disable the PYTHONPATH
, to make sure nothing is leaking from outside:
» PYTHONPATH=""
Activate the venv:
» source venv/bin/activate
Verify that activate
has not polluted my PYTHONPATH
:
» echo $PYTHONPATH
(blank, as expected)
I am using the right python:
» which python
/foo/bar/venv/bin/python
But the system modules are still being accessed:
» python
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import unittest
>>> print(unittest)
<module 'unittest' from '/usr/lib/python3.4/unittest/__init__.py'>
>>>
I would expect the import unittest
statement to fail, since the virtual environment has no such module.
I would like to know:
- Why are system packages accessed when in a virtualenv?
- How can I create a completely self-contained virtual environment?