How to use/install python 2to3?

断了今生、忘了曾经 提交于 2019-12-10 12:32:36

问题


From this https://docs.python.org/3.4/library/2to3.html it 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 ?


回答1:


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




回答2:


On CentOS (and other RHEL-like distros) you will need to run yum install python-tools, which installs 2to3 to /usr/bin/2to3




回答3:


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:

2to3 ./filename.py

OR

2to3 . -w

This last will convert all the python files that are in the directory.




回答4:


On Fedora 29, the python-tools is not providing 2to3. I had to install the development package:

dnf install python3-devel

I found this out by first calling:

dnf whatprovides /usr/bin/2to3


来源:https://stackoverflow.com/questions/31228927/how-to-use-install-python-2to3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!