Python Development Environment Configuration

Source: Internet
Author: User
Tags virtual environment

Based on Linux/mac OS X.

Maybe a lot of friends want it as much as I do. In addition, I'm afraid I forgot.

First, version number of the Platform 1, system platformThe configuration of this development environment is based on Linux or Mac OS X, which is not tested for Windows, so it's not good to say. Should all be the same. Just personal advice, Python development is still done on Linux or OS X platforms. These two systems provide native support for Python. At least the system comes with it.Python for Ubuntu 12.04: Version number 2.7.3(not to say otherwise.) Just the other version number has not been tested) of course, the system version number is higher than 12.04 is also able toOS X 10.9 comes with Python: The version number is 2.7.5Ii. configuration of the virtual Environment 1, description of the virtual environmentPython has a very wide version number, from 2.5 to 3.x, and the compatibility between version numbers and third-party packages is not very good, and in order for each of them to have an isolated environment that does not affect each other, a virtual environment is necessary to isolate each version number.

I have a deep understanding, because of the compatibility of the light error, but also do not know how to change, often changed this one has errors, so the virtual environment is very necessary. then install the required packages in each environment (with pip use), this series of environments are isolated from each other.

2, install the configuration Linux (here specifically Ubuntu) on the installation please first ensure that the following two steps:

sudo apt-get install build-essentialsudo aptitude Install Python-dev


Linux installation Pip
sudo apt-get install Python-pip
OS x same to install PIP first
sudo easy_install pip

Then install Virtualenv via PIP. The methods of Linux and OS X are the same.


3, convenient use of virtual environment: Virtualenvwrapper

Installation:

sudo pip install Virtualenvwrapper

Configure Virtualenvwrapper

Changes

sudo vim  /usr/local/bin/virtualenvwrapper.sh
Change the folder hosting the virtual environment to the one you want, the default path is $home/.virtualenvs

I changed it to $home/virtualenvs.

This path is still not changing, just a place to store the virtual environment, creating a Python project for example, Django or something is not stored in this folder.

Add the following to the last line of the ~/.BASHRC file, for example:

Export Workon_home= $HOME/.virtualenvs

And

source/usr/local/bin/virtualenvwrapper.sh
So the management tools are done well and then run:
SOURCE ~/.BASHRC

The environment is well.

Third, how to useThanks to the virtualenvwrapper installed in the previous step, we are able to easily use and manage virtual Environments 3.1 Create a virtual environment the next operation is to create a virtual environment (that is, a folder), the path created by this virtual environment is $home/virtualenvs , that is, in the Virtualenvs under your household folder.
Mkvirtualenv test2-pyenv
Check ~/virtualenvs again and find out more test2-pyenv
Once created, you will actively activate your virtual environment, and the command prompt will change to this:
(test2-env) Terminal_user> test2-env$

3.2 List all Virtual environments
$ lsvirtualenv



3.3 List all Virtual environments
$ lsvirtualenv


3.4 Activating a virtual environment
$ Workon test2-env


3.5 Entering the Virtual Environment folder
$ cdvirtualenv


3.6 Enter the Site-packages folder for the virtual environment
$ cdsitepackages



3.7 Listing all packages for the Site-packages folder
$ lssitepackages



3.8 Stopping a virtual environment
$ deactivate



3.9 Deleting a virtual environment
$ rmvirtualenv test2-env


In addition: when we migrate the environment and rebuild it is also very convenient 4, rebuild the Python environment

4.1 Placing the package configuration in a file$ pip freeze > Requirements.txt4.2 Rebuilding and rebuilding (rebuild) environment is the software package that installs the corresponding version number in the production environment at the time of deployment. Do not issue issues such as version number compatibility:


$ pip install-r requirements.txt


See: Click to open link
Click to open link

--------------------------------------------------------------------------------------------------------------- ---------------the virtual environment ready, or develop a Django application to try? Django Project, start it.


Python Development Environment Configuration

Related Article

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.