Ubuntu1604 use virtualenv tools to build the python2,3 development environment __python

Source: Internet
Author: User
Tags virtual environment virtualenv
using virtualenv tool to build python2,3 development environment under Ubuntu1604

Ubuntu1604 use virtualenv tools to build python23 development environment virtualenv tool installation and Python virtual environment create Python 2 release development of Python 3 version of the problem attached to the PIP command speed check

Reference documentation: Online "biography podcast python installation Tutorial Reference document", according to their actual installation process to add changes, thanks for sharing. Building the environment is second, it is important to understand the use of the command, so as to extrapolate

ubuntu16.04 has a python environment and does not need to be installed in a python environment. However, the default installation version is Python2, and there are problems with python3 development, such as when installing packages with PIP, and Python2 packages when installed by default. To install the Python3 package, you need to use the Virtualenv tool to create an independent Python environment that addresses the problem of interference between the python2 and python3 environments. virtualenv tool installation and Python virtual environment creation

1. Install and upgrade the Python Package management tool PIP

    # install PIP
    sudo apt-get install python-pip
    # Update pip
    pip install--upgrade pip

2.virtualenv Tool Installation

Installing Virtualenv and Virtualenvwrapper (more convenient for centralized management of virtual environments)

    sudo apt-get install python-virtualenv
    sudo easy_install virtualenvwrapper

When the above tools are installed, the mkvirtualenv command is not found and you need to perform the following environment variable settings

    # Create a directory to store the virtual environment
    mkdir $HOME/.virtualenvs

    # Add rows to ~/.BASHRC:
    export workon_home= $HOME/.virtualenvs
    source/usr/local/bin/virtualenvwrapper.sh

    # Running:
    source ~/.BASHRC

3.virtualenvwrapper Basic use to create a virtual environment

    mkvirtualenv [Virtual Environment name]
View the current virtual environment directory
    Workon
Switching Virtual Environments
    Workon [Virtual Environment name]
Exit Virtual Environment
    Deactivate
Delete (Use caution)
    rmvirtualenv [Virtual Environment name]
Python version 2 development

Creating a Python2 Virtual development environment

    Mkvirtualenv-p/usr/bin/python2.7 py2
    Use the python2.7+django1.7.8 environment, you should install the following environment:
    (py2) python@ubuntu:~$ pip Freeze list
    pip==9.0.1
    django==1.7.8
    ipdb==0.8.1
    ipython==3.2.0
    pillow==2.8.2

Store the above package name in Package_py2.txt, in your Python virtual environment, and run:

    Pip Install-r package_py2.txt

You can use the PIP freeze list to view after the installation is complete, some are not the latest version, use the PIP list--outdated check which packages need to be updated, and then use the PIP install--upgrade [install package name] to select the update

In fact : This is not more convenient, because the last thing to update, so you can choose to install directly, the system will automatically choose the latest version, of course, is not the new better, according to the specific needs to choose:

PIP Install [installation package name]
Python version 3 development

Creating a Python3 Virtual development environment

    Mkvirtualenv-p/usr/bin/python3.5 py3
    Use the python3.5+django1.9.4 environment, you should install the following environment:
    (PY3) python@ubuntu:~$ pip Freeze list
    pip==9.0.1
    django==1.9.4
    ipdb==0.8.1
    ipython==4.1.2
    pillow==2.8.2

Store the above package name in Package_py3.txt, in your Python virtual environment, and run:

    Pip Install-r package_py3.txt

Note : Install the above environment to install to pillow will appear failed building wheel for ... Error, workaround, install using the General installation command:

    Pip Install Pillow
problems encountered

Question 1: Using the PIP list is a hint:

Deprecation:the default format would switch to columns in the future. can use--format= (legacy|columns) (or define a format= (Legacy|columns) in your pip.conf under the [List] section) to D Isable this warning

I'm telling you, the default format for the PIP list will be columns. Can not be tube, but still very annoying, resolved as follows:

In the ~/pip/pip.conf configuration file (not created on your own), add the following statement to avoid such warnings:

[list]
format=columns
attached: pip command Quick check
- -
To view installed packages Pip Show–files somepackage
Check which packages need to be updated Pip list–outdated
Upgrade Package Pip Install–upgrade somepackage
Uninstall Package Pip Uninstall Somepackage
Parameter explanation Pip–help

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.