0

i want to port Python Scripts to python 3. How can i force Ubuntu to use python 3 instead of python 2 which is installed, as well.

Due to the size of the project, i'd prefer not to write something like 'use python3' inside the scripts.
Deinstalling python 2 isn't an option too, because there are to many dependencies.

So, can i remove Python 2 from the path for a while or something, so that python scripts are called with Python 3 by default.

Ubuntu 15.10

3
  • 4
    What you actually say is you won't use a shebang (which defines the version to use). Due to the size of the project??? Seems totally unclear to me. Either use a shebang (script = executable), or call the script with python3 <script> Mar 14, 2016 at 19:12
  • To elaborate, you only need a shebang in the main script that's being called to start the program. All other files that are imported fon't need this. So, like others said, the size of your project doesn't matter.
    – Timo
    Mar 15, 2016 at 9:37
  • Do it like askubuntu.com/questions/244378/run-python-in-terminal but replace every occurrence of python with python3. Apr 26, 2016 at 21:20

1 Answer 1

4

Option 1:

Just put #!/usr/bin/env python3 on top of each script file.

Due to the size of the project, i'd prefer not to write something like 'use python3' inside the scripts.

It's just one line, it can't increase the size of the project much. Writing this is a standard UNIX and Python convention.

Option 2:

Just call the script with python3 instead of python.

Not the answer you're looking for? Browse other questions tagged or ask your own question.