0

This question already has an answer here:

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

marked as duplicate by Terrance, Byte Commander, kos, Braiam, Pilot6 May 14 '16 at 6:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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> – Jacob Vlijm Mar 14 '16 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 '16 at 9:37
  • Do it like askubuntu.com/questions/244378/run-python-in-terminal but replace every occurrence of python with python3. – David Foerster Apr 26 '16 at 21:20
5

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.