如何使用/安装 python 2to3?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31228927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use/install python 2to3?
提问by Kirbies
From this https://docs.python.org/3.4/library/2to3.htmlit says that 2to3 should be installed as a script alongside the python interpreter. However, in my /usr/bin/ folder there are no 2to3 executable, and running find
from / finds no 2to3 executable either. I do however have a folder called lib2to3 at /usr/lib64/python{3.4/2.7}/lib2to3 but containing nothing I found relevant. In python/site-packages/setuptools/ there is a lib2to3_ex.py script, but nothing happens if I run it. How do I get to the point where I can simply type 2to3 upgradethisscripttopython3.py
?
从这个https://docs.python.org/3.4/library/2to3.html它说 2to3 应该作为脚本安装在 python 解释器旁边。但是,在我的 /usr/bin/ 文件夹中没有 2to3 可执行文件,并且find
从 /运行也找不到 2to3 可执行文件。然而,我在 /usr/lib64/python{3.4/2.7}/lib2to3 有一个名为 lib2to3 的文件夹,但不包含我认为相关的任何内容。在 python/site-packages/setuptools/ 中有一个 lib2to3_ex.py 脚本,但如果我运行它,则没有任何反应。我如何达到可以简单输入的程度2to3 upgradethisscripttopython3.py
?
回答by Kirbies
So the solution is that at least not for me, the Tools/scripts files were not automatically installed. On ubuntu this would be solved by installing python-examples
which on opensuse is called python-demo
所以解决方案是至少对我来说不是,工具/脚本文件没有自动安装。在 ubuntu 上,这将通过安装python-examples
在 opensuse 上被调用来解决python-demo
回答by Chris W.
On CentOS (and other RHEL-like distros) you will need to run yum install python-tools
, which installs 2to3
to /usr/bin/2to3
在 CentOS(和其他类似 RHEL 的发行版)上,您需要运行yum install python-tools
,它会安装2to3
到/usr/bin/2to3
回答by Daniyal Naeem
You need to first install the following packages:
您需要先安装以下软件包:
apt install 2to3
apt install python3-lib2to3
apt install python3-toolz
Then, You can simply go to that directory your python file is in and type the following command:
然后,您可以简单地转到您的 python 文件所在的目录并键入以下命令:
2to3 ./filename.py
2to3 ./filename.py
OR
或者
2to3 . -w
2to3 . -w
This last will convert all the python files that are in the directory.
这最后将转换目录中的所有 python 文件。
回答by P. Le Sager
On Fedora 29, the python-tools
is not providing 2to3
. I had to install the development package:
在 Fedora 29 上,python-tools
不提供2to3
. 我必须安装开发包:
dnf install python3-devel
I found this out by first calling:
我通过第一次调用发现了这一点:
dnf whatprovides /usr/bin/2to3
回答by Aqeeb Imtiaz Harun
So far I've been using pip install 2to3
. Conversions worked like absolute charm!
(I'm on Ubuntu 18.04)
到目前为止,我一直在使用pip install 2to3
. 转换工作就像绝对的魅力!(我在 Ubuntu 18.04 上)