linux-centos6.9将python版本指向改成python3.7
前提:已经存在python2.6,目前已经成功安装了python3.7。
问题:
python -V/pip list :提示报错
python3 -V/pip3 list :正常

1.查看python指向:
- ls -l /usr/bin | grep python
root@Adfuser-Test lib]# ls -l /usr/bin | grep python -rwxr-xr-x. 1 root root 6808 6月 19 2018 abrt-action-analyze-python lrwxrwxrwx. 1 root root 30 12月 26 14:04 python -> /usr/local/python3/bin/python3 lrwxrwxrwx. 1 root root 6 12月 25 17:43 python2 -> python -rwxr-xr-x. 2 root root 4864 6月 20 2019 python2.6 lrwxrwxrwx. 1 root root 30 12月 26 14:17 python3 -> /usr/local/python3/bin/python3 -rwxr-xr-x. 2 root root 4864 6月 20 2019 python.back -rwxr-xr-x. 1 root root 9032 8月 18 2016 python.bak
由上图可知python和python3都指向——>/usr/local/python3/bin/python3
于是我直接进去这个地址,看是否正确。
[root@Adfuser-Test lib]# cd /usr/local/python3/bin/python3 -bash: cd: /usr/local/python3/bin/python3: 没有那个文件或目录 [root@Adfuser-Test lib]# cd /usr/local/python -bash: cd: /usr/local/python: 没有那个文件或目录 [root@Adfuser-Test lib]# cd /usr/local/python3 [root@Adfuser-Test python3]# ll 总用量 16572 drwxr-xr-x. 18 501 501 4096 12月 25 18:05 Python-3.7.1 -rw-r--r--. 1 root root 16960060 10月 20 2018 Python-3.7.1.tar.xz
2.提示没有哪个路径,于是我这里需要找到正确的地址,并重新软链接地址
[root@Adfuser-Test python3]# cd .. [root@Adfuser-Test local]# cd bin [root@Adfuser-Test bin]# ll 总用量 18944 lrwxrwxrwx. 1 root root 8 12月 25 19:06 2to3 -> 2to3-3.7 -rwxr-xr-x. 1 root root 101 12月 25 19:06 2to3-3.7 -rwxr-xr-x. 1 root root 242 12月 25 19:06 easy_install-3.7 lrwxrwxrwx. 1 root root 7 12月 25 19:06 idle3 -> idle3.7 -rwxr-xr-x. 1 root root 99 12月 25 19:06 idle3.7 -rwxr-xr-x. 1 root root 223 12月 26 15:18 pip -rwxr-xr-x. 2 root root 223 12月 26 15:18 pip3 -rwxr-xr-x. 1 root root 223 12月 26 15:18 pip3.7 lrwxrwxrwx. 1 root root 8 12月 25 19:06 pydoc3 -> pydoc3.7 -rwxr-xr-x. 1 root root 84 12月 25 19:06 pydoc3.7 lrwxrwxrwx. 1 root root 9 12月 25 19:06 python3 -> python3.7 -rwxr-xr-x. 2 root root 9675760 12月 25 19:04 python3.7 lrwxrwxrwx. 1 root root 17 12月 25 19:06 python3.7-config -> python3.7m-config -rwxr-xr-x. 2 root root 9675760 12月 25 19:04 python3.7m -rwxr-xr-x. 1 root root 3083 12月 25 19:06 python3.7m-config lrwxrwxrwx. 1 root root 16 12月 25 19:06 python3-config -> python3.7-config lrwxrwxrwx. 1 root root 10 12月 25 19:06 pyvenv -> pyvenv-3.7 -rwxr-xr-x. 1 root root 441 12月 25 19:06 pyvenv-3.7 -rwxr-xr-x. 1 root root 214 12月 26 15:18 wheel [root@Adfuser-Test bin]# pwd /usr/local/bin [root@Adfuser-Test bin]#
3.因为python3.7安装时,执行的是./configure --prefix=/usr/local/python3.7.1,则为:
[root@Adfuser-Test bin]# mv /usr/bin/python /usr/bin/python.bak mv:是否覆盖"/usr/bin/python.bak"? [root@Adfuser-Test bin]# ln -s /usr/local/bin/python3.7 /usr/bin/python ln: 创建符号链接 "/usr/bin/python": 文件已存在 [root@Adfuser-Test bin]# rm -rf /usr/bin/python [root@Adfuser-Test bin]# ln -s /usr/local/bin/python3.7 /usr/bin/python [root@Adfuser-Test bin]# mv /usr/bin/pip /usr/bin/pip.bak [root@Adfuser-Test bin]# ln -s /usr/local/bin/pip3 /usr/bin/pip
4.最后:输入python验证
[root@Adfuser-Test bin]# python Python 3.7.1 (default, Dec 25 2019, 19:03:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
成功!
ps注意:这里每个人的安装路径都不一致,大致可供参考。
参考链接:https://blog.csdn.net/u014775723/article/details/85213793
善于跌倒仍喜爱奔跑~

浙公网安备 33010602011771号