Auto update Python 2.x to 3.x
阿新 • • 發佈:2021-06-24
1, How to check the python version
import sys
if sys.version_info < ( 3.0 )
print ( "python version is 2.x" )
else :
print ( "python version is 3.x" )
|
2, How to change the default python version
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.5 /usr/bin/python
|
3, How to install python3.x package
sudo apt install python3 -pip
sudo pip3 install package
|
4,Auto update python2.x to python3.x
http://python-future.org/futurize.html#forwards-conversion
http://python-future.org/automatic_conversion.html
4.1 Install future
sudo pip install future
|
4.2 execute cmd
futurize --stage1 -w **/*.py
futurize --stage2 -w **/*.py
|
or
futurize -w **/*.py
|
5, Changed lib
2.x | 3.x |
---|---|
import ConfigParser | import configparser |
import copy_reg | import copyreg |
import Queue | import queue |
import SocketServer | import socketserver |
import HTMLParser | import html |
import urllib2 | import urllib |