Python+django Deployment (i)

Source: Internet
Author: User
Tags virtual environment virtualenv

The reason why I wrote this article is that the Django environment is really easy to set up, before the installation of Ubuntu, it is very easy, but later I know that it is easy to do a situation in the back is very troublesome, polluting the system of the Python version, resulting in the system Python environment abnormal crash, System re-installed Ubuntu Pro you are feeling it, so a lot of people use virtualenv bar, but at the beginning of the period with virtualenv do not need the system of dependency package, but then toss to toss to go or is very troublesome, finally I had to delete all kinds of, So I finally saw a buddy's article, and I felt like I found what I wanted.

So start over Mac already default Python 2.7.5 for the System Python system version, completely independent of the virtual environment, easy to delete, move, change the environment in the various component versions, maybe I have a mild obsessive-compulsive disorder. Non-polluting system environment, no system-dependent package, full standalone Python version, standalone Django version, standalone Django dependency pack, so start from scratch

Step1: Installing PIP

Python can be installed in Python using Easy_install and Pip, but it is recommended to use PIP to see a post in StackOverflow to illustrate the rationale





PIP installation can be via source code package, Easy_install or script.


$ easy_install pip























Step2: Installing Virtualenv
  $ sudo pip install virtualenv 

How to:
1, create a virtual environment
$ virtualenv ENV1//Create a virtual environment ENV1

By default, the virtual environment Will rely on site packages in the system environment, that is, the system is installed in the third-party package will be installed in the virtual environment, if you do not want to rely on these--no-site-packages, you can add parameters to establish a virtual environment, You can use the following command to view the package installation location
# python-c "from distutils.sysconfig import get_python_lib; Print (Get_python_lib ()) "
/usr/lib/python2.7/dist-packages path under//ubuntu
/library/python/2.7/site-packages/ The path under/mac

$ virtualenv env2--no-site-package
\ \ When the command is installed, the site package will be installed in the created virtual environment, so that it is independent of the system and does not pollute the system.

2, enable the virtual Environment
CD ENV1
source./bin/activate
Note At this point the command line one more (ENV1), Env is the virtual environment name, and then all the modules will only be installed in the directory.

3, exiting the virtual environment
Deactivate

4, installing the Python module
pip install [suite name]

#Virtualenv The PIP installation tool is included with the virtual environment So the kit that needs to be installed can run directly: if the virtual environment is not started, the system also has the PIP tool installed, then the package will be installed in the system environment, in order to avoid this, you can add the following in the ~/.BASHRC file:
Export pip_require_ Virtualenv=true

or let the system automatically turn on the virtual environment when PIP is executed:
Export pip_respect_virtualenv=true
Step3: Installing Virtualenvwrapper
Virtaulenvwrapper is an expansion pack for virtualenv that makes it easier to manage virtual environments and can do:
1. Integrate all virtual environments into one directory
2. Manage (add, delete, copy) virtual environments
3. Quickly switch Virtual environments
4. Tab completion Virtual Environment name
5. Each operation is provided to allow the user to customize the hooks
6. You can write the name of the extension plugin Tab that is easy to share and the full virtual environment. Each operation is provided with a hooks that allows users to customize. Extension plugin system that can be easily shared.

-Installation
$ sudo pip install Virtualenvwrapper
\ \ You cannot use Virtualenvwrapper at this time, the default virtualenvwrapper is installed under/usr/local/bin, you actually need to run the virtualenvwrapper.sh file.

-CONFIG. BASHRC alias python= "python2.7"
#如果你的系统python安装的位置不是默认位置, please add the environment variable declaration
Path=${path}:/usr/local/share/python

#virtualenvwrapper
Export workon_home= $HOME/virtualenvs//Virtual Environment storage location for your own designation
source/usr/local/bin/virtualenvwrapper.sh//Specify the path of the execution file for Virtualenvwrapper
Export virtualenvwrapper_python=/usr/bin/python2.7//System python2.7 Execute file location, depending on your environment
Export virtualenvwrapper_virtualenv_args= '--no-site-packages '//start-up time to specify the parameters, we use the system-independent installation package
Export pip_virtualenv_base= $WORKON _home//Tell PIP virtualenv location
Export pip_respect_virtualenv=true//Make the system automatically open the virtual environment when PIP is executed

#如果是mac用户, because the user configuration that Terminal loads at startup is not. BASHRC, but ~/.bash_profile, where you need to join the ~/.bash_profile
[-R ~/.BASHRC] && source ~/.BASHRC

How to use
1. List of Virtual environments
Workon
Or
Lsvirtualenv

2. Create a new virtual environment
mkvirtualenv [Virtual Environment name]

3. Start \ Switch Virtual environment
Workon [Virtual Environment name]

4. Replicating Virtual Environments
$ cpvirtualenv Envname Targetenvname

5. Delete the virtual environment
rmvirtualenv [Virtual Environment name]

6. Leave the Virtual environment
Deactivate
Step3: Installing Pythonbrew

This is not the only way to test code in a different version of Python in the future, and this part is added to the following

STEP4: Installing auxiliary components


STEP5: Installing Django






To this local development Django environment is also installed, such a separate development environment, Pythonbrew installed Python version, not dependent on the system, completely independent, direct deletion without any impact, or Direct copy of the virtual machine environment changes in the Python version and the Django version can be carried out another test, and the system environment is not related to the results I want to the result, will not mess up the system, I directly toss the virtual environment

Python+django Deployment (i)

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.