Python3 installation and configuration of the virtual environment

Content Today

Today https://www.cnblogs.com/pyyu/p/9015317.html content blog address

1. python3 compiler installation
1. Download source python3
CD / opt
yum wget command to install the install -Y wget
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz

. 1. before installing python3, dependent on the environment to solve
by yum install kit automatically handles dependencies, each package is divided by a space
to install these packages in advance, in the future it will not be a lot of pit

have to ensure that these dependencies toolkit properly installed
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. Extract the source package
after download python3 good source package
Python-3.6.2.tgz
unzip,
tar command to decompress tgz format
tar -xvf Python-3.6.2.tgz


3. switch the source package directory
cd Python-3.6. 2

4. Compile and the mounting
1. The release makefile build file, which is used to compile and makefile installed
./configure --prefix = / opt / python36 /
mounting path specified software --prefix
2. Compile start to python3
the make
3. Compiler and mounted (this step only, will be generated / opt / python36)
the make the install
4. python3.6 environment variable configuration
1. configuration flexible connection (note that this configuration and PATH, choose one)
LN -s soft target file connection file
ln -s /opt/python36/bin/python3.6 / usr / bin / python3
at this time no PIP
LN -s / opt / python36 / bin / PIP3 / usr / bin / PIP3



2. configuration path environment variables ( choose one can)
echo $ view the PATH environment variable to
/ usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / root / bin
# variable assignment, take effect only temporarily, need to write to the file, made permanent
the PATH = / usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / root / bin: / opt / python36 / bin
#linux have a global personal profile
edit this file, PATH is written on the bottom line
vim / etc / profile
is written
PATH = / usr / local / sbin : / usr / local / bin: / usr / sbin: / usr / bin: / root / bin: / opt / python36 / bin
Save and exit

read this / etc / profile such that commencement
Source / etc / profile

5. the installation of a test linux django,
PIP3 the install django
6. the created project django
django-ADMIN startproject the mysite
7. the APP, created django
django-ADMIN startApp app01

8. the view function to write, test a view index

9. Notice of modification allow_hosts settings.py, windows to get access to the linux django project

yum tool

yum install nginx -y


If you use the command yum, yum prompt process is locked, you can not use the
solution: ps -ef | grep yum process, which is said to have also used by another process yum
yum there is only one process use

python
click Test, mac, run a hello world

Throughput
Django 600
Flask 1000+
Tornado 1800+ non-blocking asynchronous frame
sanic 2800+ uvloop driving game event domain interface


Go
NET / HTTP Web server 6W +

 


python virtual environment virtualenv
1. demand on the linux server, can either have django2.0 environment, can run django1.11.11 environmental
thinking:
1.django2.0 want to run, we have to prepare python interpreter + pip3 package management
2. wish to run django1.11.11 python interpreter PIP3 +
- ??????? mounted compile a python3.6
- PIP3 module installed, are placed /opt/python36/lib/python3.6/site- Packages

the virtualenv is a virtual interpreter
is based on the python interpreter in physical, virtual / avatar a plurality of interpreters

venv1
django2.0
venv2
django1.1
venv3
flask

venv4
requests
scrapy

Installation virtualevn

1. Download virtualenv tool
installation tool by pip physical environment
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple virtualenv
after the installation is complete you will have one of the linux command virtualenv
2. Create a virtual environment venv1 venv2

virtualenv --no-site-packages --python = python3 s15venv1
call virtual environment command
parameters --no-site-packages it is to build a clean, isolated modules
--python = python3 this parameter is specified to which a virtual environment physical interpreter based on
the last one is the name of the virtual environment will create such a folder
3. Go to the virtual environment directory, activate the virtual environment
to find your virtual environment bin directory underground activate file
Source myenv / s15venv1 / bin / activate
-
activate virtual environment, the principle is to modify the pATH variable, path is executed sequentially
echo $ pATH environment variable to check
Which python3
Which pip3 check whether the normal virtual environment

4. test the installation of two virtual environments, venv1, venv2, and run two different django version of the project

5. Exit command virtual traded
deactivate

 

 

 

vim editor,
vimer
vim programmer


Local development environment to ensure consistency of operations and online
solutions:
1. order to ensure the consistency of the environment, export the current package python environment
pip3 freeze> requirements.txt

This will create a requirements.txt file, which contains a simple list of the current environment in all packages and their version.
You can use a list of "pip list" in case of no requirements document to view the installed packages.


2. uploaded to the server, create virtualenv in the server, import the required project in venv modules rely
pip3 install -r requirements.txt


Virtual environment management tool virtualenvwrapper

1. Install this command, you must have a physical interpreter underground, pay attention! !
virtualenvwrapper install PIP3

1.1
pay attention, look at this
note, look at this
note, look at this
note, look at this
note, look at this
note, look at this
note, look at this
note, look at this
note, look at this
note look at this
note, look at this
note, look at this
note configuration path here, you need to physically interpreter python, on the front path

echo $ pATH
here to keep the configuration, like me, will python3 on the front
[ ~ @ localhost root] # echo $ the PATH
/ opt / python36 / bin: / usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / root / bin: / root / bin


2. modify environment variables, each boot to load the tool virtualenvwrapper

vim ~ / .bashrc .bashrc file in the user's home directory #vim editing, this file is the user at login, you read this file
#export read the role of shell commands
# These variables according to your own absolute path environment modify
export WORKON_HOME = ~ / Envs # set virtualenv unified management directory
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS = '- no-site -packages' # virtualenvwrapper add parameters to generate a clean environment isolated
export VIRTUALENVWRAPPER_PYTHON = / opt / python347 / bin / python3 # specify python interpreter
source /opt/python34/bin/virtualenvwrapper.sh # virtualenvwrapper execute the installation script

3. log back in session, so that the configuration takes effect
Zimbabwe Logout
SSH ....


4. The right words virtualenvwrapper tools already available
to provide what commands?
mkvirtualenv virtual environment name # to automatically download a virtual environment, and activate the virtual environment

workon virtual environment name # activates the virtual environment

deactivate exit the virtual environment

rmvirtualenv delete virtual environment

cdvirtualenv into the directory currently active virtual environment where

Directory cdsitepackages into the currently active virtual environment, python package


Python virtual environment management tools virtualenvwrapper

 

Guess you like

Origin www.cnblogs.com/duhong0520/p/11687503.html