1

I am having two code bases build_2.x and build_3.x which were coded in python 2.x and python 3.x respectively.

I have a Linux machine in which Python 2.x is installed, but for my project purpose I need to execute both builds in same machine.

  1. How to run build_2.x and build_3.x separately?
  2. Do I run the the build_2.x first, then should I update Pthon to 3.x after I need to run build_3.x?

And also what is the function of virtualenv in this case?

karel
  • 114,770

2 Answers2

1

There are two programs to translate Python code to/from Python 2 and Python 3, 2to3 and python3-3to2. 2to3 is installed by default and python3-3to2 can be installed by the following command:

sudo apt install python3-3to2

To convert a file named example.py run the following commands:

2to3 -w example.py # translates Python 2 code to Python 3 code 

or

3to2 -w example.py # translates Python 3 code to Python 2 code

Usage
  Automated Python 2 to 3 code translation – Python documentation

karel
  • 114,770
0

One off possible solution pyenv + virtualenv. This allow temporary switch from Python2 to Python3 (per project). Good step by step instruction is here: https://askubuntu.com/a/865644/429130 or here http://akbaribrahim.com/managing-python-virtual-environments-with-pyenv-virtualenv/. Good explanation of role of virtualenv is here :https://stackoverflow.com/questions/29950300/what-is-the-relationship-between-virtualenv-and-pyenv

Ova
  • 466
  • 2
  • 5