解决系统不同Python版本下,repo因不同版本导致的SyntaxError: invalid syntax异常
Posted 高桐@BILL
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决系统不同Python版本下,repo因不同版本导致的SyntaxError: invalid syntax异常相关的知识,希望对你有一定的参考价值。
首先,repo同步代码时报错,如下:
repo init -u https://android.googlesource.com/platform/manifest -b android-10.0.0_r40
File "/mnt/f/13_car/QQ3A.200705.002/.repo/repo/main.py", line 79
file=sys.stderr)
^
SyntaxError: invalid syntax
if sys.version_info.major < 3:
print('repo: error: Python 2 is no longer supported; '
'Please upgrade to Python .+.'.format(*MIN_PYTHON_VERSION_SOFT),
file=sys.stderr)
sys.exit(1)
else:
if sys.version_info < MIN_PYTHON_VERSION_HARD:
print('repo: error: Python 3 version is too old; '
'Please upgrade to Python .+.'.format(*MIN_PYTHON_VERSION_SOFT),
file=sys.stderr)
sys.exit(1)
elif sys.version_info < MIN_PYTHON_VERSION_SOFT:
print('repo: warning: your Python 3 version is no longer supported; '
'Please upgrade to Python .+.'.format(*MIN_PYTHON_VERSION_SOFT),
file=sys.stderr)
那么确认为是python版本问题,则卸载掉python2.7等无关版本,接着重新同步代码时发现repo不见了,查看日志发现卸载到python2.7时,repo被一起卸载了,日志如下:
root@HuangYaBin1:/mnt/f/13_car/QQ3A.200705.002# apt-get remove python2.7
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libice-dev libpthread-stubs0-dev libpython-stdlib libpython2.7-minimal libpython2.7-stdlib libsm-dev libx11-dev
libx11-doc libxau-dev libxcb1-dev libxdmcp-dev libxt-dev openjdk-9-jdk-headless python-minimal python2.7-minimal
x11proto-core-dev x11proto-input-dev x11proto-kb-dev xorg-sgml-doctools xtrans-dev
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
python python-kerberos python2.7 repo
则没办法重新安装repo,又发现repo安装时会自动安装python2.7并配置python环境变量;
如下为部分安装日志:
Unpacking python-kerberos (1.1.5-2build1) ...
Selecting previously unselected package repo.
Preparing to unpack .../repo_1.12.32-2_all.deb ...
Unpacking repo (1.12.32-2) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up python2.7 (2.7.12-1ubuntu0~16.04.18) ...
Setting up python (2.7.12-1~16.04) ...
Setting up python-kerberos (1.1.5-2build1) ...
Setting up repo (1.12.32-2) ...
那么没办法设置python别名,默认执行python是使用python3.8,命令如下:
alias /usr/bin/python3.8 /usr/bin/python
虽然执行python的时候,使用的是默认python3.8但实际上执行repo init时依然报同样的错。
最终建立一个软链接解决问题;
ln -s /usr/bin/python3.8 /usr/bin/python.
以上是关于解决系统不同Python版本下,repo因不同版本导致的SyntaxError: invalid syntax异常的主要内容,如果未能解决你的问题,请参考以下文章
Win10下python不同版本同时安装并解决pip共存问题