This container provides several versions of Python for creating separated Python environments via virtualenv. This container is particularly well suited to use tox with multiple Python versions.
The following Python versions are installed:
- Python 2.7
- Python 3.4
- Python 3.5
- Python 3.6
- Python 3.7
This container uses Fedora since this distribution allows to install multiple Python versions in a very simple way.
In most cases, you want to run a project with differents Python versions. Your project should be mapped to the /var/project directory of the container:
$ docker run -it --rm -v /path/to/your/project:/var/project lvo9/python-virtualenv bashThe following environments are generated by default:
/var/environments/py27/var/environments/py34/var/environments/py35/var/environments/py36/var/environments/py37
For instance, let's use Python 3.5 environment; according to the virtualenv documentation:
[root@0800a40e232f project]# source /var/environments/py35/bin/activate
(py35) [root@0800a40e232f project]# python --version # will display Python 3.5.6You can now test your project with Python 3.5. To quit current virtual environment:
(py35) [root@0800a40e232f project]# deactivateOf course, you can create as many environments as you need (to work with many versions of a library for instance). For creating another Python 3.5 virtual environment:
[root@0800a40e232f project]# virtualenv -p /usr/bin/python3.5 /var/environments/py35_customWhen creating extra virtual environments (or if you modify the existing ones), you should create a docker volume. If you don't do so, your new and/or customized environments will be lost when you close the container. Let's bind the environments folder to a directory of your host machine:
$ docker run -it --rm -v /path/to/your/project:/var/project -v /path/to/backup/environments:/var/environments lvo9/python-virtualenv bashTox is preinstalled in the container. According to the Python versions installed, you can have the following environment list in your tox.ini:
[tox]
envlist = py27,py34,py35,py36,py37