简体   繁体   English

如何直接在python代码中启用2to3?

[英]How to enable 2to3 in python code directly?

I have a python script that needs to be started with the -3 option to check for python 3 incompatibilities.我有一个需要使用-3选项启动的 python 脚本来检查 python 3 的不兼容性。 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但是因为我需要在virtualenv环境中运行脚本,所以在shebang中不能使用绝对路径,所以我使用

#!/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)!效果很好,除了缺少选项“-3”(因为在此上下文中无法再使用它)!

Is there a way to 'activate' this option in the code itself?有没有办法在代码本身中“激活”这个选项? To enable the 2to3 warnings during the run of the code?在代码运行期间启用2to3警告?

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.我可以理解你想问的是“我想将我的默认 python2 解释器更改为 python3 ”,如果问题是这样,那么我会给你一个 VSCode 的例子来做到这一点:打开 VSCode(我假设你有安装了你想设置为默认的python解释器,这里:我以python 3.8.2为例),在左下角你可以看到你的默认python版本点击它并选择你想设置为默认的那个.

To check which version of python you are using:type " python --version " in Mac or Linux Terminal.要检查您使用的是哪个版本的 python:在 Mac 或 Linux 终端中键入“ python --version ”。

Hope this will help you.希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM