Install build python3.6.1 pip install virtual environment

First, install python3.6

1. Installation depend on the environment,

# 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

2. Download Python3

# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

3. Install python3

I personally used to install in / usr / local / python3 (specific installation position of personal preference)
to create the directory:

# mkdir -p /usr/local/python3

Unzip the downloaded Python-3.xxtgz package (specific package name because you download the Python differs depending on the specific version does not differ, such as: I downloaded the Python3.6.1 that I have here is the Python-3.6.1.tgz.)

# tar -zxvf Python-3.6.1.tgz

4. unpacked into the directory, compile and install

# cd Python-3.6.1
# ./configure --prefix=/usr/local/python3

make

# make

make install
make install    或者 make && make install

5. Establish a soft python3

# ln -s /usr/local/python3/bin/python3 /usr/bin/python3

6 and the / usr / local / python3 / bin added PATH

# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH

Press ESC, enter: wq Enter to exit.
Modify finished, remember to take the following command line, so that the step changes to take effect:

# source ~/.bash_profile

Check that Python3 and pip3 normally available

# python3 -V
Python 3.6.1
# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)

Create a virtual environment

virtualenv is a tool to create isolated Python environment. Virtualenv create a file that contains all the necessary executable files, and to use the required engineering Python package.

installation

pip install virtualenv

Basic use

  1. Create a virtual environment for a project:
$ cd my_project_dir
$ virtualenv venv  #venv为虚拟环境目录名,目录名自定义

virtualenv venv Will be created in the current directory in a folder that contains Python executable file, and  pip a copy of the library, so you can install additional package. Virtual environment name (in this case is  venv ) can be arbitrary; if the file name will be omitted are in the current directory.

In any directory you run the command, which creates a copy of Python, and the place is called the  venv file.

  1. To start using a virtual environment, it needs to be activated:
$ source venv/bin/activate  

从现在起,任何你使用pip安装的包将会放在 venv Folder, and cut off from the global installation of Python.

 

  1. If you temporarily completed the work in a virtual environment, you can disable it:
$ . venv/bin/deactivate
Released nine original articles · won praise 459 · views 160 000 +

Guess you like

Origin blog.csdn.net/songhait/article/details/96284559