参考文章:
目录
安装
查看python3指向
python3 -V
查看python的指向。
ls -l /usr/bin | grep python
查看本地已安装的python
ls /usr/bin/python*
1) 首先更新软件包列表并安装必备组件:
sudo apt update
sudo apt install software-properties-common
#可选
2)接下来,将Deadsnakes PPA添加到您的来源列表中:
sudo add-apt-repository ppa:deadsnakes/ppa
#可选
1.直接使用apt-get安装python3.7
apt-get install python3.7
2.更新python3指向
法一、(没试过)建立软连接 更新Python 3以指向Python 3.7
rm -rf /usr/bin/python3
ln -s /usr/bin/python3.7 /usr/bin/python3
以下命令不用先:
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip
apt install python3-pip
#可选
法二、(推荐)将Python 3.6和Python 3.7添加到更新替代项
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
更新Python 3以指向Python 3.7
默认情况下,Python 3.6指向Python3。这意味着当我们运行python3时,它将作为python3.6执行,但我们希望将其作为python3.7执行。
输入以下命令以配置python3:
sudo update-alternatives --config python3
您应该获得以上输出。 现在键入2并按Enter键以使用Python 3.7。 请记住,选择号可能会有所不同,因此请选择适用于Python 3.7的选择号。
apt install python3-pip
测试python版本
最后输入以下命令测试当前版本的python:
python3 -V
pip3 -V
输出应该为 Python 3.7.**
遇到的坑
1.后出现
ModuleNotFoundError: No module named ‘apt_pkg’
解决方法
1.先将原来的Python apt模块进行删除:
sudo apt-get remove --purge python-apt
2.再将它删除:
sudo apt-get install -f -y python-apt
3.进入文件层:
cd /usr/lib/python3/dist-packages/
4.将它改变:
命令一(推荐)
sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.cpython-37m-x86_64-linux-gnu.so
PS:第三第四步运行成功是不会提示的。
或者命令二
sudo ln -s apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so
(如果报apt_pkg.so已存在,则使用命令 强制添加)
sudo ln -fs apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so
卸载python3.7(如果需要)
sudo apt remove python3.7
2.安装java8 即JDK8 即Oracle Java JDK 8出现错误
cannot import name ‘_gi’ from ‘gi’ (/usr/lib/python3/dist-packages/gi/__init
参考文章:importerror
root@vr:~# ls /usr/lib/python3/dist-packages/gi/
_constants.py _gi.cpython-36m-x86_64-linux-gnu.so module.py _propertyhelper.py repository
docstring.py importer.py _option.py __pycache__ _signalhelper.py
_error.py __init__.py overrides pygtkcompat.py types.py
root@vr:~# cd /usr/lib/python3/dist-packages/gi/
root@vr:/usr/lib/python3/dist-packages/gi# sudo cp _gi.cpython-36m-x86_64-linux-gnu.so _gi.cpython-37m-x86_64-linux-gnu.so
解决
3. 又出现问题,跟问题4一起解决
ImportError: cannot import name 'gi’ from ‘gi’ (/usr/lib/python3/dist-packages/gi/
-- networkd-dispatcher.service 单元已开始启动。
9月 03 22:59:42 me networkd-dispatcher[13707]: Traceback (most recent call last):
9月 03 22:59:42 me networkd-dispatcher[13707]: File "/usr/bin/networkd-dispatcher", line 23, in <module>
9月 03 22:59:42 me networkd-dispatcher[13707]: from gi.repository import GLib as glib
9月 03 22:59:42 me networkd-dispatcher[13707]: File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in <module>
9月 03 22:59:42 me networkd-dispatcher[13707]: from . import _gi
9月 03 22:59:42 me6 networkd-dispatcher[13707]: ImportError: cannot import name '_gi' from 'gi' (/usr/lib/python3/dist-packages/gi/_
9月 03 22:59:42 me systemd[1]: networkd-dispatcher.service: Main process exited, code=exited, status=1/FAILURE
9月 03 22:59:42 me systemd[1]: networkd-dispatcher.service: Failed with result 'exit-code'.
9月 03 22:59:42 me systemd[1]: Failed to start Dispatcher daemon for systemd-networkd.
-- Subject: networkd-dispatcher.service 单元已失败
-- Defined-By: systemd
cd /usr/lib/python3/dist-packages/gi/
sudo cp _gi.cpython-36m-x86_64-linux-gnu.so _gi.cpython-37m-x86_64-linux-gnu.so
sudo cp _gi_cairo.cpython-36m-x86_64-linux-gnu.so _gi_cairo.cpython-37m-x86_64-linux-gnu.so
4刚解决完上面的问题,新问题又来了
ModuleNotFoundError: No module named ‘_dbus_bindings’
9月 03 23:20:17 me networkd-dispatcher[21532]: File "/usr/bin/networkd-dispatcher", line 25, in <module>
9月 03 23:20:17 me networkd-dispatcher[21532]: import dbus
9月 03 23:20:17 me networkd-dispatcher[21532]: File "/usr/lib/python3/dist-packages/dbus/__init__.py", line 77, in <modu
9月 03 23:20:17 me networkd-dispatcher[21532]: import dbus.types as types
9月 03 23:20:17 me networkd-dispatcher[21532]: File "/usr/lib/python3/dist-packages/dbus/types.py", line 6, in <module>
9月 03 23:20:17 me networkd-dispatcher[21532]: from _dbus_bindings import (
9月 03 23:20:17 me networkd-dispatcher[21532]: ModuleNotFoundError: No module named '_dbus_bindings'
9月 03 23:20:17 me systemd[1]: networkd-dispatcher.service: Main process exited, code=exited, status=1/FAILURE
9月 03 23:20:17 me systemd[1]: networkd-dispatcher.service: Failed with result 'exit-code'.
9月 03 23:20:17 me systemd[1]: Failed to start Dispatcher daemon for systemd-networkd.
参考文章:参考
cd /usr/lib/python3/dist-packages/
sudo cp _dbus_bindings.cpython-36m-x86_64-linux-gnu.so _dbus_bindings.cpython-37m-x86_64-linux-gnu.so
sudo cp _dbus_glib_bindings.cpython-36m-x86_64-linux-gnu.so _dbus_glib_bindings.cpython-37m-x86_64-linux-gnu.so
突然后悔安装python3.7了,淦,解决问题