centos6.5 installation Python3 installation, PYTHON3 virtual environment creation Venv

Source: Internet
Author: User
Tags virtual environment

Cause: After centos6.5 is installed, when you type Python from the command line, the default is the python2.6.6 version, and the Python3 version is not installed. You also want to learn python3, so you need to install the Python3 version under centos6.5.

"Python3 Installation"

1. Download the Python3 installation package:

(1) If you are able to connect to the Internet, direct:

[Email protected] 3pyex]# wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz

Where I installed the version is python-3.6.0, if you want to install another version, then open the site https://www.python.org/ftp/python/, in the Python directory will see the entire Python version of the directory, the above/ 3.6.0/python-3.6.0.tgz replace it with the version you need.

(2) If you cannot connect to the Internet, download the version that you need to install on the above website and put it under one of the centos6.5 folders.

2, installation Python3:

Assume that the downloaded python-3.6.0.tgz is under directory/home/:

[[email protected] home]# cd/home/[[email protected] home]# tar-zxvf python-3.6.0.tgz[[email protected] home]# CD Python -3.6.0[[email protected] home]#/configure[[email protected] home]# Make[[email protected] home]# make install

After installation, you can open the Python version of python3.6.0 by typing python3 on the command line:

The Python3 here is installed by default to the/usr/local/bin/directory, and I do not make any other changes here because/usr/local/bin/is already included in the environment variable path.

"Pip use"

Description: Pip is a tool for installing and managing Python packages, and the Python installation kit has easy_install, Setuptools, Pip,distribute. And Pip is a substitute for easy_install.

1, after the installation of python3.6.0, the default has been installed PIP, the command line type PIP, you can see our default is PIP3

2. Install Python package:

[Email protected] home]# PIP3 install Pythonpackage

Where Pythonpackage is the Python package to be installed, you can perform PIP3 install scipy if you want to install the SCIPY package.

"Venv Virtual Environment Creation"

Description: The Venv module provides the creation of a lightweight "virtual environment" that provides isolation support from the system Python. Each virtual environment has its own Python binaries (allowing for different versions of the Python authoring environment) and can have its own set of Python packages. His greatest benefit is that each Python project can be used in a single environment without affecting the Python system environment or the environment of other projects.

1. Create a virtual environment:

Suppose we create a virtual environment under the ~/py3/directory, which is an independent working environment for Python3.

[Email protected] home]# CD ~/py3/                 #进入到需要创建虚拟环境的目录 [[email protected] home]# python3-m venv.         #在当前目录下创建虚拟环境 [[email protected] home]# source Bin/activate       #激活该虚拟环境

At this point, we have a separate venv working directory, where you can see separate bin, Lib, include and other folders.

2. Test the virtual environment:

[Email protected] home]# CD ~/py3/                     #进入venv虚拟环境 [[email protected] py3]# pip install Scipy            #安装某个包 [email  Protected] py3]# python                         #进入python交互环境 [[email protected] py3]# Pythonpython 3.6.0 (default, May, 18:56:45) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on Linuxtype ' help ', ' copyright ', ' credits ' or ' license ' for more information.>>& Gt >>> >>> Import scipy            #导入scipy库 >>> print (scipy)            #将显示scipy库的信息 <module ' scipy ' From '/root/py3/lib/python3.6/site-packages/scipy/__init__.py ' >>>>   

If you can see the above information, then the VENV environment is set up, you can directly under the working directory for the development of Python3.

Description: After installing the VENV environment, you can use the PIP command in the environment directory, or you can type Python directly to open the Python 3.6.0 interactive mode. Also, in venv python3 interactive mode, when you type the import command, you can im+tab the key directly to complete the command. When the SciPy module is imported, all methods of scipy can also be displayed through the Scipi.+tab key. This can be said to be a benefit of using venv.

centos6.5 Installation Python3 installation, PYTHON3 virtual environment creation Venv

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.