Manage virtualenv in python 2.7 container

Can anyone point me towards an example configuration for managing/activating the virtualenv in a python 2.7 container? All of the example config files I found online (see snippet below) assume python 3.X and use the ‘venv’ module, which appears to not be available in python 2.7.

jobs:
  build:
    docker:
      - image: circleci/python:2.7
    steps:
      - checkout
      - run:
          name: install dependencies
          command: |
            python3 -m venv venv
            . venv/bin/activate
            pip install -r requirements.txt
      - run:
          name: run tests
          command: |
            . venv/bin/activate
            python manage.py test

Specifically:
‘python3 -m venv venv’ errors with 'python3: command not found’
and when I tried to replace python3 with python:
‘python2 -m venv venv’, errors with ‘No module named venv’

My use case is quite simple. I just need to be able to install some dependencies via pip, cache the virtualenv, and then run tests using those dependencies.

I’m not sure if this is the correct solution or not, but it seems to be working for me at the moment.

- run:
      name: install dependencies
      command: |
        mkdir -p ./venv
        virtualenv ./venv
        . venv/bin/activate
        pip install -r requirements.txt
1 Like