1

I have a python script that needs to be started with the -3 option to check for python 3 incompatibilities. I managed to do so using the following hashtag:

#!/usr/bin/python -3

But because I need to run the script in a virtualenv environment, I cannot use an absolute path in the shebang, so I use

#!/usr/bin/env python 

which works fine, except the option '-3' is missing (because it is not possible to use it in this context anymore)!

Is there a way to 'activate' this option in the code itself? To enable the 2to3 warnings during the run of the code?

Alex
  • 41,580
  • 88
  • 260
  • 469
  • Hrm, unfortunately, most systems don't allow you to do this, indeed. – Martijn Pieters Jun 25 '13 at 11:00
  • possible duplicate of [Cannot pass an argument to python with "#!/usr/bin/env python"](http://stackoverflow.com/questions/3306518/cannot-pass-an-argument-to-python-with-usr-bin-env-python) – Martijn Pieters Jun 25 '13 at 11:02
  • 1
    No its not a duplicate. I do not want to pass arguments with shebang, I want to enable those 2to3 warnings in the python code itself, like `import warnings; warnings.enable("2to3")` or whatever. – Alex Jun 25 '13 at 11:17
  • Right, except there is *no other way* to set that flag. Both the tokenizer and the AST code needs to know about the flag too, which means it needs to be set *before* code is running. – Martijn Pieters Jun 25 '13 at 13:26
  • There's a solution suggested in [this thread](http://mail.python.org/pipermail/python-dev/2008-September/082441.html), but it doesn't work for me. Can you not just create a shell script containing `python -3 $*`, and point your she-bang line to that instead? – Aya Jun 25 '13 at 13:37

1 Answers1

-1

As i can understand what you want to ask is that "i want to change my default python2 interpreter to python3", if the question is this then i will give you an example of VSCode to do this: Open VSCode (i assume that you had installed the python interpreter that you want to set as default, here: i am taking example of python 3.8.2) and at the bottom left corner you can see your default python version click on it and select the one you want to set as default.

To check which version of python you are using:type "python --version" in Mac or Linux Terminal.

Hope this will help you.