Different Python Versions for Different Steps

My build has 2 basic steps.

  1. Run unit tests. This must be done with python3

  2. Deploy using ansible. THis must be done with python2.

Not seeing a way to make this happen in circleci.

I set up my machine like:

machine:
python:
version: 3.5.1

So my tests use python3 and everything passes. Great. Now I am trying to hack python2 into my deployment

deployment:
production:
branch: master
commands:
- pyenv global 2.7.10
- pip install ansible
- ansible-playbook -v ./deploy.yml

Not so good, further into my scripts I get errors telling me my deployment is indeed using python3

Traceback (most recent call last):
  File "./inventory/gce.py", line 92, in <module>
    import ConfigParser
ImportError: No module named 'ConfigParser'

Any tips?

pyenv global 2.7.10

Seems to be doing nothing…

Hi,

I’m also getting this issue. I’ve even tried adding a deactivate step before pyenv global 2.7.10 to make sure the script exits the virtualenv. I also noticed that Circle was automatically installing fabric during the dependencies step, so I’ve overridden that.

Oddly if I do the steps manually via ssh debug everything works fine. I’m not sure why.

Here’s my full circle.yml:

machine:
  timezone:
    Europe/London
  python:
    version: 3.4.3

dependencies:
  override:
    - pip install -r requirements.txt

test:
  override:
    - flake8 .
    - python3 ./manage.py test --settings=settings.ci

deployment:
  master:
    branch: master
    commands:
      - deactivate
      - pyenv global 2.7.10
      - pip install fabric fabtools
      - fab production deploy

I think I’ve found the route of my issue.

if you’re defining Python in you Machine config CirlcCI runs every line in your yml inside a virtualenv. So if you want to install something outside of the virtualenv you need to add a deactivate on the same line as your pip install like so:

- deactivate; pip install fabric fabtools