经历
python3执行python脚本import cv2报错,发现原因是指定的python2.7目录下的cv2,后来为了在安装python3版本的opencv,安装了pip3,结果安装opencv报错,然后升级了pip3,然后pip的所有指令都不能用了。。。一直报错
Traceback (most recent call last):
File "/usr/bin/pip3", line 11, in <module>
sys.exit(main())
File "/home/qin/.local/lib/python3.5/site-packages/pip/__init__.py", line 12, in main
from pip._internal.utils.entrypoints import _wrapper
File "/home/qin/.local/lib/python3.5/site-packages/pip/_internal/utils/entrypoints.py", line 4, in <module>
from pip._internal.cli.main import main
File "/home/qin/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 58
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
原因
查了很多,大多数老外的说法是,高版本的pip不再支持python3.5
解决
-
卸载pip
sudo apt remove --purge python3-pip
-
移除pip的相关文件
sudo apt autoremove
-
下载pip的安装文件
curl -O https://bootstrap.pypa.io/pip/3.5/get-pip.py
-
执行安装文件
/usr/bin/python3 /home/qin/下载/rosbag2video-master/get-pip.py
-
pip降级
sudo -E python3 -m pip install --upgrade "pip < 19.2"
大功告成,希望对大家有所帮助