python中的pip install 报错SyntaxError: invalid syntax解决方法
文章源自公式库网-https://www.gongshiku.com/html/202303/pythonzhongdepip-install-baocuosyntaxerror-invalid-syntaxjiejuefangfa.html
原因:
1、在Python运行环境里执行pip指令是错误的文章源自公式库网-https://www.gongshiku.com/html/202303/pythonzhongdepip-install-baocuosyntaxerror-invalid-syntaxjiejuefangfa.html
2、Pip21.0.1版本在2020年1月停止支持Python2,在2020年3月停止支持Python3.5文章源自公式库网-https://www.gongshiku.com/html/202303/pythonzhongdepip-install-baocuosyntaxerror-invalid-syntaxjiejuefangfa.html
解决:
一开始打开cmd,我就输入:python,再输入pip……,就出现了SyntaxError: invalid syntax错误!文章源自公式库网-https://www.gongshiku.com/html/202303/pythonzhongdepip-install-baocuosyntaxerror-invalid-syntaxjiejuefangfa.html
文章源自公式库网-https://www.gongshiku.com/html/202303/pythonzhongdepip-install-baocuosyntaxerror-invalid-syntaxjiejuefangfa.html
有些情况下,关了cmd,再次打开,直接输入pip……就成功!文章源自公式库网-https://www.gongshiku.com/html/202303/pythonzhongdepip-install-baocuosyntaxerror-invalid-syntaxjiejuefangfa.html
但也可能遇到其它情况……文章源自公式库网-https://www.gongshiku.com/html/202303/pythonzhongdepip-install-baocuosyntaxerror-invalid-syntaxjiejuefangfa.html
提示Defaulting to user installation because normal site-packages is not writeabl
这是权限的问题,可以通过 右键 点击开始菜单(win10/win11),找到 终端管理员文章源自公式库网-https://www.gongshiku.com/html/202303/pythonzhongdepip-install-baocuosyntaxerror-invalid-syntaxjiejuefangfa.html
文章源自公式库网-https://www.gongshiku.com/html/202303/pythonzhongdepip-install-baocuosyntaxerror-invalid-syntaxjiejuefangfa.html
提示WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, st
使用国内的pip源文章源自公式库网-https://www.gongshiku.com/html/202303/pythonzhongdepip-install-baocuosyntaxerror-invalid-syntaxjiejuefangfa.html
- 阿里云:http://mirrors.aliyun.com/pypi/simple/
- 中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/
- 豆瓣 (douban):http://pypi.douban.com/simple/
- 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
- 中国科学技术大学:http://pypi.mirrors.ustc.edu.cn/simple/
最终解决办法:
pip install 安装包 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
如下图: