返回顶部

CentOS 7 初始化python3.7.2配置

安装系统依赖

https://www.jianshu.com/p/3ec24f563b81

有Python, MySQL的依赖,Elasticsearch对Java依赖,django-compressor的压缩需要的bizp2-devel等

[root@zanhu ~]# yum -y update
[root@zanhu ~]# yum -y install python-devel zlib-devel mysql-devel libffi-devel bzip2-devel openssl-devel java wget gcc readline-devel 

安装git/redis/nginx/supervisor

[root@zanhu ~]# yum -y  install git redis nginx supervisor

保证实例重启后服务依然运行  

[root@zanhu ~]# systemctl enable redis nginx supervisord
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
[root@zanhu ~]#

安装Python3

一条条来不容易出问题,阿里云的服务器下载Python-3.7.2.tar.xz很慢,可以先浏览器下载了再传到服务器上,后面下载elasticsearch-2.4.6.tar.gz也是一样  

[root@zanhu ~]# wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
[root@zanhu ~]# tar -xvf Python-3.7.2.tar.xz
[root@zanhu ~]# cd Python-3.7.2
[root@zanhu ~]# ./configure --prefix=/usr/local/python3 --enable-optimizations
[root@zanhu ~]# make
[root@zanhu ~]# make install

创建软链接

[root@zanhu ~]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@zanhu ~]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

在 /etc/profile 中添加python3环境变量

export PATH=/usr/local/python3/bin:$PATH

是环境变量生效

source /etc/profile 

升级pip

pip3 install --upgrade pip

验证安装结果

[root@zanhu ~]# python3 -V
Python 3.7.2
[root@zanhu ~]# pip3 -V
pip 18.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
[root@zanhu ~]# whereis python3
python3: /usr/bin/python3 /usr/local/python3
[root@zanhu ~]# whereis pip3
pip3: /usr/bin/pip3
[root@zanhu ~]#

 

创建python3.7虚拟环境

pip3 install pipenv
mkdir project
cd project/
pipenv --python 3.7

修改python源

vim Pipfile

内容如下

[[source]]
url = "https://mirrors.aliyun.com/pypi/simple/"
verify_ssl = true
name = "pypi"

[packages]
django = "*"

[dev-packages]

[requires]
python_version = "3.7" 

在虚拟环境中安装包

pipenv install django 

安装Elasticsearch

切换到zanhu用户,elasticsearch服务不能使用root用户运行  

[zanhu@zanhu ~]$ wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.6/elasticsearch-2.4.6.tar.gz
[zanhu@zanhu ~]$ tar -xvf elasticsearch-2.4.6.tar.gz

 

  

posted @ 2020-11-20 11:27  Crazymagic  阅读(141)  评论(0编辑  收藏  举报