Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downgrade virtualenv to 2.7 from 3.5.3

My virtualenv is currently configured to python 3.5.0 while the package I need to use only supports 2.7. I need a way of downgrading my python runtime to 2.7 within my virtualenv.

I do have both versions available to use: First one is in my virtualenv, second is computer-wide.

(project) me-Air:element me$ python -V
Python 3.5.0

me-Air:element me$ python -V
Python 2.7.10
like image 945
qarthandso Avatar asked Feb 05 '23 02:02

qarthandso


2 Answers

You cannot "downgrade" virtualenv.

You will have to create a new one, you don't necessarily need to delete your current one unless you want the virtualenv to have the same name as your current one.

virtualenv -p /usr/bin/python2.7 <path/to/new/virtualenv/>

Since your problem requires them to be integrated there are many ways to do it, use subprocess to do whatever you need to with the Python 2.7 code and transfer the output back to your Python 3 code.

You could also use Rabbit MQ Queues to transfer data to and from the programs running different versions of Python.

like image 51
Meghdeep Ray Avatar answered Feb 08 '23 16:02

Meghdeep Ray


Another method of pinning a virtualenv to a specific Python version is to run it via the -m flag on the Python executable. E.g.

python2 -m virtualenv ./venv

Likewise, if you wanted a Python 3 virtualenv, you'd run this:

python3 -m virtualenv ./venv
like image 40
dwlz Avatar answered Feb 08 '23 16:02

dwlz