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

       之前为了升级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

 

### 回答1: 在CentOS 7上安装Python 3和pip3,可以按照以下步骤进行操作: 1. 更新系统软件包: ``` sudo yum update ``` 2. 安装Python 3: ``` sudo yum install python3 ``` 3. 安装pip3: ``` sudo yum install python3-pip ``` 4. 验证Python 3和pip3是否安装成功: ``` python3 --version pip3 --version ``` 如果输出了版本号,则说明安装成功。 希望对您有帮助! ### 回答2: CentOS 7 默认自带 Python 2.x, 如果需要使用 Python 3.x,需自己手动安装。本文主要介绍 CentOS 7 安装 Python 3 和 pip3 的方法。 一、安装 Python 3 1. 更新系统组件 ``` yum update -y ``` 2. 安装依赖库 ``` yum install gcc openssl-devel bzip2-devel libffi-devel -y ``` 3. 下载 Python 3 源码 ``` cd /usr/src wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz ``` 4. 解压源码包 ``` tar xzf Python-3.8.1.tgz ``` 5. 编译源码安装 ``` cd Python-3.8.1 ./configure --enable-optimizations make altinstall ``` 6. 验证安装是否成功 ``` python3.8 ``` 二、安装 pip3 1. 下载 get-pip.py ``` curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py ``` 2. 安装 pip3 ``` python3.8 get-pip.py ``` 3. 验证安装是否成功 ``` pip3 -V ``` 以上就是 CentOS 7 安装 Python 3 和 pip3 的详细步骤,安装过程稍微有些繁琐,但不难操作。安装成功后可以愉快的使用 Python 3 编写代码了。 ### 回答3: CentOS 7作为一种可靠的操作系统,被许多的企业和个人所使用。安装Python3pip3将允许您在CentOS 7上运行Python3应用程序。本文将介绍如何在CentOS 7上安装Python 3和pip3。 首先,打开终端并以root权限登录。 接下来,安装更新: yum update 然后,安装EPEL存储库,这将为我们提供必要的资源。 yum install epel-release 安装Python 3: yum install python3 安装Python3后,需要验证是否自动安装pip3。可以使用以下命令来验证: pip3 --version 如果已安装pip3,则将显示已安装的版本信息。如果pip3没有安装,则需要手动安装。 手动安装pip3,首先需要安装setuptools和pip: yum install python3-setuptools 然后安装pip: easy_install-3.6 pip 要验证pip是否已安装,请输入以下命令: pip3 --version 安装成功后,将显示已安装的版本信息。 最后,您可以使用pip3来安装Python软件包和模块: pip3 install package_name 总之,CentOS 7安装Python3pip3很简单,只需要运行上述命令即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值