linux environment compiler installation python3
1.linux under way to install software
Choose the yum utility, convenience, resolve dependencies between the software itself and automatically download and install
Configuring source yum
Ali cloud sources can be selected, such as Tsinghua source
配置第一个仓库,里面有大量系统常用软件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
配置第二个仓库,携带大量第三方软件(nginx,redis,mongodb,mairadb等)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
2.yum repository directory:
cd /etc/yum.repos.d/
# 在这个目录第一层的repo文件就会被识别问yum软件仓库
3. Empty the cache yum
yum clean all
4. Generate a new cloud Ali yum cache
yum makecache
2.centos7 under way to compile and install the python3
1. The need to address the infrastructure required to compile development environment
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
2. Download python3 compilation code package, decompress
wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tar.xz
xz -d Python-3.6.7.tar.xz
tar -xf Python-3.6.7.tar
3. Go to decompress the generated source code folder
cd Python-3.6.7
4. compile command trilogy
第一曲:找到一个[配置的可执行文件,configure],执行它,且指定软件安装位置
./configure --prefix=/opt/python367/
第二曲:在上一步,会生成一个makefile,编译安装,在linux下必须用gcc工具去编译,使用的命令时
make&&make
第三曲:这一步是执行安装,会生成一个/opt/python367文件夹,可用的解释器都在这里了
make install
The configuration environment variable, easy to use quick python3
1.先获取当前的PATH变量,然后把python3的bin目录加进去
echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
2.永久修改PATH的值
-直接修改/etc/profile ,系统全局的配置文件,每个用户在登陆系统的时候,都会加载这个文件
vim /etc/profile
-写入新的PATH变量 PATH="/opt/python367/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin"
3.重新登陆,或者手动读取这个/etc/profile
source /etc/profile # 让这个文件中的变量生效
3. virtual environment virtualenv
1. Download the virtual environment module
It is a module of the python with the installation pip
pip3 install -i https://pypi.douban.com/simple virtualenv
2. Create a virtual environment
virtualenv --no-site-packages --python=/opt/python367/bin/python3.6 venv_django2
#解释
--no-site-packages 创建的新的venv,不携带任何模块,是个纯净的python解释器环境
--python 指定以哪个解释器为本体,创建新的虚拟环境
3. Activate the virtual environment
source activate
# 系统会将venv的解释器目录,加到PATH的最前面
4. In a virtual environment, install the new module, project management
pip3 install -i https://pypi.douban.com/simple django==1.11.23
创建django项目
django-admin startproject ceshi
修改django的settings.py 中ALLOW_HOSTS=['*']
5. Start project
python3 ceshi/manage.py runserver 0.0.0.0:9999
6. Quit command virtual environment
deactivate
4.virtualenvwrapper upgraded version of the virtual environment tool
1. Install
Do not install in a virtual environment
pip3 install -i https://pypi.douban.com/simple virtualenvwrapper
2. modify the configuration file
Every time you turn on the tool load virtualenvwrapper
1.打开用户个人的环境变量配置文件
全局配置文件 /etc/profile # 每个用户登陆都生效
用户个人配置文件 ~/.bash_profile
root在登陆的时候,会读取这个文件中的代码
vim ~/.bash_profile
2.填入如下信息,针对你自己的python环境修改
#设置virtualenv的统一管理目录
export WORKON_HOME=~/目录名
#添加virtualenvwrapper的参数,生成干净纯净的环境
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
#指定python解释器
export VIRTUALENVWRAPPER_PYTHON=/opt/python3/bin/python3
#执行virtualenvwrapper安装脚本
source /opt/python3/bin/virtualenvwrapper.sh
3. Create a shortcut / switched virtual environment
mkvirtualenv 虚拟环境名 #创建虚拟环境
lsvirtualenv #列出虚拟环境的名字
workon 虚拟环境名字 #激活或切换虚拟环境
lssitepackages #列出虚拟环境中的模块信息,其实就是虚拟环境第三方模块目录
cdvirtualenv #进入虚拟环境家目录
cdsitepackages #进入虚拟环境第三方模块目录