centos中python2和python3共存情况下,pip3安装和冲突问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/clever_wr/article/details/89056595

       之前为了升级centos 7的版本从python2升级到python3,曾经设法只保留python3版本,删除centos中的python2版本,事实证明踩了很多坑,甚至是把linux系统搞崩溃。吓得我瑟瑟发抖。于是才发现这两个版本是可以共存的只要让对应的/usr/bin/python对应相应的机器自带python2版本,/usr/bin/python3软连接/usr/bin/python3.6,就可以通过python3指令执行python3版本。

[root@hw007 bin]# python
Python 2.7.5 (default, Oct 30 2018, 23:45:53) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
------------------------------------------------------------------------[root@hw007 bin]# python3
Python 3.6.6 (default, Mar 29 2019, 00:03:27) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

简直是非常nice,但是对于python2对应的pip和python3对应的pip有所不同。python3对应的pip是pip3。所以需要再下载一个相应的版本才行。下面是具体操作:

wget –no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e6
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6/
python3 setup.py build
python3 setup.py install
wget –no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
tar -zxvf pip-8.0.2.tar.gz
cd pip-8.0.2/
python3 setup.py build
python3 setup.py install
whereis pip3 #会发现在/usr/bin中没有pip3,因此需要创建一个软连接
sudo ln -sf /usr/local/bin/pip3.6 /usr/bin/pip3 #软连接
pip3

显示下面内容显示已经成功,(如果不执行软连接那步会报错:-bash: /usr/bin/pip3: No such file or directory) 

Usage:   
  pip3 <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging
                              levels).
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort).
  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
  --no-color                  Suppress colored output

然后我执行pip3进行下载:

pip3 install paddlepaddle

会报错,显示当前pip版本太低,需要执行以下指令,然后在执行上面指令:

pip3 install --upgrade pip
sudo ln -sf /usr/local/bin/pip3.6 /usr/bin/pip3
pip3 install paddlepaddle

猜你喜欢

转载自blog.csdn.net/clever_wr/article/details/89056595