10

宝塔面板Centos7环境下如何使Python2与Python3共存

 3 years ago
source link: https://www.huhexian.com/12971.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

宝塔面板Centos7环境下如何使Python2与Python3共存

青山 2021-11-2314:09:12评论567字

最近在研究一个爬虫应用,需要用到Python3,由于目前我的服务器是Centos7系统,默认装的Python2,为了不冲突服务器内的其他应用,想要看看可以让Python2与Python3共存,在网上搜寻了相关教程,发现有很多教程了,而且很简单,下面自己也备份一份。

下载python3安装包并解压

  1. wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
  2. tar -xzvf Python-3.7.2.tgz

编译安装包

进入解压,编译安装包,指定安装路径,并执行安装命令

  1. cd Python-3.7.2
  2. ./configure --prefix=/usr/local/python37 #注意:prefix参数用于指定将Python安装在新目录,防止覆盖系统默认安装的python
  3. make && make install

建立软链接

  1. ln -s /usr/local/python37/bin/python3.7 /usr/bin/python3
  2. ln -s /usr/local/python37/bin/pip3 /usr/bin/pip3

输入python3检查状态

宝塔面板Centos7环境下如何使Python2与Python3共存

检查安装情况,按Ctrl+z或者输入exit()退出。

到这里,我们就已经实现了Python2与Python3共存,希望对有需要的朋友有所帮助。


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK