Ubuntu18.04 pip和pip3 共存并指定python版本

**

Ubuntu18.04 pip和pip3 共存并指定python版本

**
1.安装pip和pip3

sudo apt install python-pip
sudo apt install python3-pip

2.查看各个版本python路径

which python2.7
which python3.6

一般来说文件在 /usr/bin 目录下:

/usr/bin/python2.7
/usr/bin/python3.6

3.修改环境变量,解决多版本python共存。
3.1 指令

gedit ~/.bashrc

3.2 在bashr文件末尾添加

alias pip=/usr/bin/pip
alias pip3=/usr/bin/pip3
alias python=/usr/bin/python2.7
alias python3=/usr/bin/python3.6

3.3 使环境变量生效

1. source ~/.bashrc
2. 重启
3. 注销

4.改变 /usr/bin 下的pip和pip3 文件内容
4.1 变更pip内容,gedit /usr/bin/pip

#!/usr/bin/python
# GENERATED BY DEBIAN
 
import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
if sys.version_info.major == 3 and sys.version_info.minor == 8:
    from pip import __main__
 
    if __name__ == '__main__':
        sys.exit(__main__._main())
else:
    from pip import main
    if __name__ == '__main__':
        sys.exit(main())

4.2 变更pip2内容,gedit /usr/bin/pip2

#!/usr/bin/python2.7
# GENERATED BY DEBIAN
 
import sys
 
# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip import main
if __name__ == '__main__':
    sys.exit(main())

4.2 变更pip3内容,gedit /usr/bin/pip3

#!/usr/bin/python3
# -*- coding:utf-8 -*-
# GENERATED BY DEBIAN
 
import sys
import os
 
# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
if sys.version_info.major == 3:
    if sys.version_info.minor == 8:
        from pip import __main__
 
        if __name__ == '__main__':
            sys.exit(__main__._main())
    else:
        from pip import main
 
        if __name__ == '__main__':
            sys.exit(main())
else:
    msg = "当前Python版本为Python%s.%s,不能使用pip3!" % (sys.version_info.major, sys.version_info.minor)
    os.system("echo %s" % msg)
    os.system("""echo "请使用'update-alternatives --config python' 切换Python版本" """)

5.查看pip、pip3、python、python3版本
5.1 pip
Ubuntu18.04 pip和pip3 共存并指定python版本_第1张图片
5.2 pip3
在这里插入图片描述
5.3 python
在这里插入图片描述
5.4 python3
在这里插入图片描述

参考链接:
https://www.cnblogs.com/lczmx/p/12428041.html
https://blog.csdn.net/gymaisyl/article/details/86563916

你可能感兴趣的:(ubuntu,gparted,linux)