Ubuntu12.10 install and configure Django in Virtualenv

Source: Internet
Author: User
Tags install django pip install django
1. install apache and apache-python module: sudoapt-getinstallapache2sudoapt-getinstalllibapache2-mod-python2.7 2. Configure vim/etc/apache2/conf. d/charset in apachepython to cancel adddefacharcharsetutf-

1. Install the apache and apache-python modules:

  1. Sudo apt-get install apache2
  2. Sudo apt-get install libapache2-mod-python2.7
Ii. apache python Configuration
  1. Vim/etc/apache2/conf. d/charset, uncomment adddefacharcharset UTF-8
  2.  
  3. Vim/etc/apache2/mod-available/python. conf, add:
  4. AddHandler mod_python. py
  5. AddType text/html. py
  6. PythonHandler pytest
  7. PythonDebug On
  8.  
  9. Sudo ln-s/etc/apache2/mod-available/python. conf/etc/apache2/mod-enabled/python. conf
  10.  
  11. Sudo vim/etc/apache2/sites-available/python, the content is as follows:
  12. DocumentRoot/var/www/py
  13. ServerName py
  14.  
  15. AddHandler mod_python. py
  16. PythonHandler pytest
  17. PythonDebug On
  18.  
  19. Ln-s/etc/apache2/sites-available/python/etc/apache2/sites-enabled/python
  20.  
  21. Mkdir-p/var/www/py
  22. Chown-R www-data: www-data/var/www/py // the user running apache. The default value is www-data.
  23. Chmod-R 775/var/www/py
  24. Sudo adduser dave www-data
  25.  
  26. Sudo service apache2 restart
  27. Access: http: // 127.0.0.1
Iii. test whether the task is successful: sudo vim/var/www/py/pytest. py. PythonHandler pytest in the Same Name:
  1. #! /Usr/bin/python
  2. #-*-Coding: UTF-8 -*-
  3. From mod_python import apache
  4.  
  5. Def handler (req ):
  6. Req. content_type = 'text/html '// type of the request object
  7. Req. write ('Hello! ') // Req is the request object, which has a proprietary method: write
  8. Return apache. OK
  9.  
  10. Chown-R www-data: www-data pytest. py
  11. Chmod 775 pytest. py
  12.  
  13. Sudo service apache2 restart
  14. Access: http: // 127.0.0.1/py/pytest. py
Iv. virtualenv installation and configuration
  1. Sudo apt-get install-y python-dev python-setuptools
  2. Sudo easy_install virtualenv virtualenvwrapper pip
  3.  
  4. Sudo mkdir/home/dave/study/webapps // The total working directory of all virtualenv Environments
  5. Sudo chown-R www-data: www-data/home/dave/study/webapps
  6. Sudo chmod-R g + rw/home/dave/study/webapps
  7.  
  8. Add the following line ~ /. Bashrc:
  9. Export VIRTUALENV_USE_DISTRIBUTE = 1
  10. Export WORKON_HOME =/home/dave/study/webapps
  11. Source/usr/local/bin/virtualenvwrapper. sh
  12. Export PIP_VIRTUALENV_BASE = $ WORKON_HOME
  13. Export PIP_RESPECT_VIRTUALENV = true
  14. Export PYTHONPATH =/usr/local/lib/python2.7: $ PYTHONPATH
  15.  
  16. Then source ~ /. Bashrc. If an error is reported, view the directory owner and permissions.
Create a virtual environment and install related software:
  1. Cd ~ /Study/webapps
  2. Mkvirtualenv firstenv
  3. Pip install "django = 1.4.5 ",
  4. Pip install MySQL-python
  5. // Install the related software in the virtual environment. Note that before installing mysql-python, you must first install sudo apt-get install python-dev libmysqlclient-dev; otherwise, the installation will fail.
  6.  
  7.  
  8. Check whether django is successfully installed:
  9. Python, enter idle
  10. > Import django
  11. > Print django. VERSION
  12. 1.4.5
For general usage of virtualenvwrapper, see http://www.cnblogs.com/Phenix_Yang/archive/2012/05/08/2489724.html:
  1. Cd webapps
  2. Mkvirtualenv NAME // create a virtual environment
  3. Rmvirtualenv NAME // delete a virtual environment
  4. Lsvirtualenv // list all Virtual Environments
  5. Workon NAME // enter the specified virtual environment. If no NAME is specified, all virtual environments are listed.
  6. Deactivate // exit the current Virtual Environment
General Usage of pip: when installing the software, pip is found on the pypi website, while pypi only collects links to the software package. The problem is that the link may be invalid, so pip is also flawed.
  1. Pip freeze // list all installed software packages
  2. Pip search django // find the software package with django in the name
  3. Pip install django // install django. The latest version is installed by default.
  4. Pip install "django = 1.4.5" // specify the version when installing the software package. You can also use <, <=,>,> = to specify the version range, for example, pip install "django> 1.4 <1.5"
  5. Pip install-U django // upgrade django
  6. Pip uninstall django // uninstall django
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.