Python Development Environment configuration and python Development Environment
Based on Linux/Mac OS X. Maybe many of my friends want the same thing as me, and they are afraid that they will forget it.
I. Description of the version platform 1. The configuration of the development environment of the system platform is based on Linux or Mac OS X. It should be the same if it is not tested on windows. However, I personally suggest that Python is developed on Linux or OS X. These two systems provide native support for Python. At least it comes with the system. For Python of Ubuntu 12.04:
2.7.3(Not to mention other features, but other versions have not been tested.) Of course, if the system version is higher than 12.04, it is also possible to bring Python in OS X 10.9: the version is
2.7.5Ii. Virtual Environment configuration 1. Virtual Environment Description there are many Python versions, from 2.5 to 3. x is available, and the compatibility between versions and third-party packages is not very good. In order to ensure that each version has an isolated environment and does not affect each other, a virtual environment is required to isolate each version. I have a deep understanding. Because of compatibility issues, errors occur. what's even worse is that I still don't know how to modify them. It is often because I have changed this one. Therefore, it is necessary to make a virtual environment. Then install the required software package in each environment (together
pip). These environments are isolated from each other. 2. to install and configure Linux (Ubuntu here), make sure that the following two steps are performed:
sudo apt-get install build-essentialsudo aptitude install python-dev
Install pip in Linux
sudo apt-get install python-pip
Installing pip is also required for OS X.
sudo easy_install pip
Then install virtualenv Through pip. The methods for Linux and OS X are the same.
sudo pip install virtualenv
3. Convenient virtual environment: virtualenvwrapper
Installation:
sudo pip install virtualenvwrapper
Configure virtualenvwrapper
Modify
sudo vim /usr/local/bin/virtualenvwrapper.sh
Change the directory for storing the virtual environment to what you want. The default path is $ HOME/. virtualenvs.
I changed it to $ HOME/virtualenvs.
This path should not be changed. It is just a place to store the virtual environment. Creating a Python project, such as django, is not stored in this directory.
In ~ The last line of the/. bashrc file is added as follows:
export WORKON_HOME=$HOME/.virtualenvs
And
source /usr/local/bin/virtualenvwrapper.sh
In this way, the management tool is ready and then executed:
source ~/.bashrc
The environment is ready!
3. How to Use the virtualenvwrapper installed in the previous step, we can easily use and manage the virtual environment. 3.1 create a virtual environment. In the next operation, we need to create a virtual environment (that is, a directory ), the path created in this virtual environment is $ HOME/virtualenvs, that is, in virtualenvs under your user's HOME directory.
mkvirtualenv test2-pyenv
Check again ~ /Virtualenvs, found more than test2-pyenv
The virtual environment will be automatically activated after creation, and the command prompt will also 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 activate the Virtual Environment
$ workon test2-env
3.5 enter the virtual environment directory
$ cdvirtualenv
3.6 enter the site-packages directory of the Virtual Environment
$ cdsitepackages
3.7 list all software packages in the site-packages directory
$ lssitepackages
3.8 stop the Virtual Environment
$ deactivate
3.9 delete a virtual environment
$ rmvirtualenv test2-env
In addition, it is very convenient when we migrate the environment and re-build it. 4. Rebuilding the Python environment.
4.1 put the software package configuration in the file $ pip freeze> requirements.txt 4.2 re-build the rebuild environment. during deployment, the corresponding version of the software package is installed in the production environment, do not have issues such as version compatibility:
$ Pip install-r requirements.txt
Reference: Click the open link.
Click Open Link
Prepare the ghost virtual environment. Do you want to develop a django application? Django project. Let's get started.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.