How to bootstrap Python VirtualEnvs with a specific Python version
This shows how to create a "bootstrap" VirtualEnv, which will allow the creation of (mostly) self-contained VirtualEnvs that are used for projects.
- Install OS dependencies like libsqlite3-dev
- Otherwise you won't be able to import sqlite3
- See Django problem: sqlite error when running"manage.py migrate" for what sort of error this results in
- Build Python from source:
- Download from https://www.python.org/download/releases
- Extract tarball
- cd into directory
- Run "./configure --prefix=/opt/python3"
- Run "make"
- Run "sudo make install"
- Manually grab the latest virtualenv module to avoid dependency problems with the existing Python installation:
- Download virtualenv-X.Y.Z.tar.gz from https://pypi.python.org/pypi/virtualenv#downloads
- Extract into /opt/virtualenv-X.Y.Z
- Create and configure the "bootstrap" VirtualEnv:
- E.g. run "/opt/virtualenv-15.0.3/virtualenv.py -p /opt/python3/bin/python3 lib/py3venv"
- Run "lib/py3venv/bin/pip install virtualenv"
lib/py3venv/bin/virtualenv env_dirThe VirtualEnv directory that is created will contain its own Python executable, but will rely on the global packages in /opt/python3.
See The "Virtual Environments and Packages" section of the Python tutorial for more info.