Specify Python Version for Virtualenv in Requirements.txt

Viewed 23338

I'm using virtualenv to develop a django application with a team. The server we're deploying on is running python 2.6, but the default for our machines is 2.7.3. Is there any way to specify python version in the requirements.txt file, or something similar, within the code base?

I know requirements.txt is a pip thing, and python version is a virtualenv thing, but it would be really convenient not to have to tell every new person joining the team how to set up their virtualenv.

5 Answers

You can't put that in requirements.txt, but you can add this code at the top of the script:

import sys
if sys.version_info[0:2] != (2, 6):
    raise Exception('Requires python 2.6')

You can also specify the default Python by this command:

sudo update-alternatives  --set python /usr/bin/python3.7
Related