centos7环境编译安装python3.7.7和pipenv的简单使用

centos7环境编译安装python3.7.7

# 安装基本的基础源和epel源为阿里云的mirrors
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

# 安装依赖
# bzip2-devel 一定要先安装,然后编译python,compress插件依赖

yum install -y gcc gcc-c++ htop telnet iotop iptraf iftop libpng12 make logrotate xinetd ntsysv  sysstat perl autoconf libjpeg libjpeg-devel libpng libpng-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel libxml2 libxml2-devel libxslt-devel libevent-devel libtool libtool-ltdl bison  ntpdate  patch vim wget openssh-clients bind-utils

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

yum install -y mysql-devel python-devel mysql-lib
yum install libffi-devel -y

# 安装python3,最好开screen避免中断
screen -S python

# 获取python3.7.7源码并编译安装
cd /usr/local/src
wget https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tgz
tar xf Python-3.7.7.tgz
cd Python-3.7.7
mkdir -p /usr/local/python3

./configure --prefix=/usr/local/python3

make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

[root@sz_xxgc_cms_slave01_18_214 Python-3.7.7]# python3 -V
Python 3.7.7

# 设置pip的阿里云源:提升pip安装软件速度

pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/

# 安装pipenv的错误处理:
# pip3 install pipenv

报错:
    ModuleNotFoundError: No module named '_ctypes'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.


解决办法,yum install libffi-devel -y 重新编译安装python3.7

ln -s /usr/local/python3/bin/pipenv /usr/bin/pipenv3

# 创建python3.7的虚拟环境
[root@sz_xxgc_cms_slave01_18_214 myproject]# pipenv3 --python 3.7

# 在目录下安装django包
# pip3 install django

# 下载很慢,更换pipenv的源
[root@sz_xxgc_cms_slave01_18_214 myproject]# cat Pipfile 
[[source]]
name = "pypi"
url = "https://mirrors.aliyun.com/pypi/simple/"
verify_ssl = true

[dev-packages]

[packages]

[requires]
python_version = "3.7"


# 查看依赖关系
[root@sz_xxgc_cms_slave01_18_214 myproject]# pipenv3 graph
Django==3.0.4
  - asgiref [required: ~=3.2, installed: 3.2.5]
  - pytz [required: Any, installed: 2019.3]
  - sqlparse [required: >=0.2.2, installed: 0.3.1]

Pipfile.lock里面是hash值,有利于安全性
pipenv3 install requests --skip-lock 跳过安全检测



# 进入虚拟环境
[root@sz_xxgc_cms_slave01_18_214 myproject]# pipenv3 shell
Launching subshell in virtual environment…
[root@sz_xxgc_cms_slave01_18_214 myproject]#  . /root/.local/share/virtualenvs/myproject-fWPhQNBN/bin/activate
(myproject) [root@sz_xxgc_cms_slave01_18_214 myproject]

exit退出虚拟环境

# 安装在dev环境
pipenv install --dev pytest --skip-lock

 2.安装virtualenv虚拟环境,并创建纯净的虚拟环境
pip3 install virtualenv
/usr/local/python3/bin/virtualenv --python=/usr/local/python3/bin/python3 /usr/local/api_monitor_env/

posted @ 2020-03-13 23:32  reblue520  阅读(786)  评论(0编辑  收藏  举报