Linux 上搭建python环境

  • Post author:
  • Post category:linux


1.安装python

1.1debian安装python

curl -SL https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tgz| tar -zxvC /usr/local

apt-get update &&

apt-get install build-essential python3-dev python3-setuptools python3-pip default-mysql-client default-libmysqlclient-dev python-smbus libncursesw5-dev libgdbm-dev libc6-dev libreadline-dev libbz2-dev zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libffi-dev -y &&

cd /usr/local/Python-3.8.8 && ./configure –enable-optimizations –with-ensurepip=install –prefix=/usr/local/python3.8 && make altinstall &&

#移除python27的软连接

mv /usr/bin/python /usr/bin/python27

#建立新的软连接

ln -s /usr/local/python3.8/bin/python3.8 /usr/bin/python && ln -s /usr/local/python3.8/bin/pip3.8 /usr/bin/pip &&

mkdir ~/.pip/ && echo [global]\nindex-url = https://mirrors.163.com/pypi/simple/ >~/.pip/pip.conf &&

chown -R /usr/local/python3.8 &&

rm -rf /usr/local/Python-3.8.8 &&

rm -rf /var/lib/apt/lists/* && python -m pip install –upgrade pip

1.2 centos7安装python3.8

curl -SL https://www.python.org/ftp/python/3.8.8/Python-3.8.8.tgz| tar -zxvC /usr/local

yum update && yum -y groupinstall “Development tools” && yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-dev &&

cd /usr/local/Python-3.8.8 && ./configure –enable-optimizations –with-ensurepip=install –prefix=/usr/local/python3.8 && make altinstall

#移除python27的软连接

mv /usr/bin/python /usr/bin/python27 && ln -s /usr/local/python3.8/bin/python3.8 /usr/bin/python && ln -s /usr/local/python3.8/bin/pip3.8 /usr/bin/pip && mkdir ~/.pip/ && echo [global]\nindex-url = http://mirrors.aliyun.com/pypi/simple/>~/.pip/pip.conf && rm -rf /usr/local/Python-3.8.8 && rm -rf /var/lib/apt/lists/* && python -m pip install –upgrade pip

更改yum配置

因为其要用到python2才能执行,否则会导致yum不能正常使用(不管安装 python3的那个版本,都必须要做的)

vi /usr/bin/yum

把 #! /usr/bin/python 修改为 #! /usr/bin/python2

vi /usr/libexec/urlgrabber-ext-down

把 #! /usr/bin/python 修改为 #! /usr/bin/python2

vi /usr/bin/yum-config-manager

#!/usr/bin/python 改为 #!/usr/bin/python2



版权声明:本文为weixin_45226922原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。