# Different Python Versions for Different Steps

**URL:** <https://discuss.circleci.com/t/different-python-versions-for-different-steps/5113>\
**Category:** Build Environment\
**Tags:** python\
**Created:** [July 13, 2016, 2:31am UTC](https://discuss.circleci.com/t/different-python-versions-for-different-steps/5113 "2016-07-13T02:31:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![listingmirror](https://avatars.discourse-cdn.com/v4/letter/l/ba8739/32.png) [@listingmirror](https://discuss.circleci.com/u/listingmirror)\
**Post date:** [July 13, 2016, 2:31am UTC](https://discuss.circleci.com/t/different-python-versions-for-different-steps/5113/1 "2016-07-13T02:31:22Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![k0nG](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/k0ng/32/15034_2.png) [@k0nG](https://discuss.circleci.com/u/k0nG)\
**Post date:** [January 4, 2017, 9:38am UTC](https://discuss.circleci.com/t/different-python-versions-for-different-steps/5113/2 "2017-01-04T09:38:28Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![k0nG](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/k0ng/32/15034_2.png) [@k0nG](https://discuss.circleci.com/u/k0nG)\
**Post date:** [January 4, 2017, 12:12pm UTC](https://discuss.circleci.com/t/different-python-versions-for-different-steps/5113/3 "2017-01-04T12:12:26Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:38am UTC](https://discuss.circleci.com/t/different-python-versions-for-different-steps/5113/4 "2018-06-18T11:38:30Z")

</div>

Closed on June 18, 2018, 11:38am UTC


