安裝virtualenv 2
[root@s26 my_django]# easy_install virtualenv Searching for virtualenv Reading http://pypi.python.org/simple/virtualenv/ Reading http://www.virtualenv.org Reading http://virtualenv.openplans.org Best match: virtualenv 1.6.3 Downloading http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.6.3.tar.gz#md5=73a69184e35f1e2c2f9016c889c4d26a Processing virtualenv-1.6.3.tar.gz Running virtualenv-1.6.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-V5fQfD/virtualenv-1.6.3/egg-dist-tmp-MV73Zz warning: no previously-included files matching '*.*' found under directory 'docs/_templates' Adding virtualenv 1.6.3 to easy-install.pth file Installing virtualenv script. to /usr/local/bin
Installed /usr/local/lib/python2.7/site-packages/virtualenv-1.6.3-py2.7.egg Processing dependencies for virtualenv Finished processing dependencies for virtualenv
|
virtualenv 的作用相當於 Sandbox,它通過隔離包目錄和系統環境引數來實現多個相對獨立的虛擬環境。可避免過多的第三方庫因為版本依賴造成問題。同時每個獨立的虛擬環境只需通過打包即可分發,也大大方便了系統部署。(摘自網際網路)
生成虛擬環境
[root@s26 my_django]# virtualenv /var/www/myenv New python executable in /var/www/myenv/bin/python Installing setuptools............done. Installing pip...............done.
|
在虛擬環境中安裝軟體
[root@s26 myenv]# ls bin include lib [root@s26 myenv]# source /var/www/myenv/bin/activate (myenv)[root@s26 myenv]# (myenv)[root@s26 myenv]# pip install django Requirement already satisfied (use --upgrade to upgrade): django in /usr/local/lib/python2.7/site-packages Cleaning up... (myenv)[root@s26 myenv]# pip install django --upgrade Downloading/unpacking django Downloading Django-1.3.tar.gz (6.5Mb): 6.5Mb downloaded Running setup.py egg_info for package django
Installing collected packages: django Found existing installation: Django 1.3 Not uninstalling Django at /usr/local/lib/python2.7/site-packages, outside environment /var/www/myenv Running setup.py install for django changing mode of build/scripts-2.7/django-admin.py from 644 to 755
changing mode of /var/www/myenv/bin/django-admin.py to 755 Successfully installed django Cleaning up... (myenv)[root@s26 myenv]# pip install mako Downloading/unpacking mako Downloading Mako-0.4.1.tar.gz (317Kb): 317Kb downloaded Running setup.py egg_info for package mako
warning: no files found matching '*.xml' under directory 'examples' warning: no files found matching '*.mako' under directory 'examples' warning: no files found matching 'ez_setup.py' no previously-included directories found matching 'doc/build/output' Downloading/unpacking MarkupSafe>=0.9.2 (from mako) Downloading MarkupSafe-0.12.tar.gz Running setup.py egg_info for package MarkupSafe
Installing collected packages: mako, MarkupSafe Running setup.py install for mako changing mode of build/scripts-2.7/mako-render from 644 to 755
warning: no files found matching '*.xml' under directory 'examples' warning: no files found matching '*.mako' under directory 'examples' warning: no files found matching 'ez_setup.py' no previously-included directories found matching 'doc/build/output' changing mode of /var/www/myenv/bin/mako-render to 755 Running setup.py install for MarkupSafe
building 'markupsafe._speedups' extension gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c markupsafe/_speedups.c -o build/temp.linux-i686-2.7/markupsafe/_speedups.o gcc -pthread -shared build/temp.linux-i686-2.7/markupsafe/_speedups.o -o build/lib.linux-i686-2.7/markupsafe/_speedups.so Successfully installed mako MarkupSafe Cleaning up... (myenv)[root@s26 myenv]#
|
注意,在此環境下安裝的軟體僅在此環境下有效。
建立專案:
建立第一個專案myappdir1
[root@s26 www]# django-admin.py startproject myappdir1 [root@s26 www]# tree myappdir1 myappdir1 |-- __init__.py |-- manage.py |-- settings.py `-- urls.py
0 directories, 4files |
建立第二個專案myappdir2
[root@s26 www]# django-admin.py startproject myappdir2 [root@s26 www]# tree myappdir2 myappdir1 |-- __init__.py |-- manage.py |-- settings.py `-- urls.py
0 directories, 4files |
編寫模組:
在第一個專案中新增hello_world.py
[root@s26 myappdir1]# vi hello_world.py from django.http import HttpResponse
def hello_world(request): return HttpResponse("Hello world--app1") |
在第二個專案中新增hello_world2.py
[root@s26 myappdir2]# vi hello_world2.py from django.http import HttpResponse
def hello_world2(request): return HttpResponse("Hello world--app2") |
設定應用:
在第一個專案的urls.py新增黑體字部分
[root@s26 myappdir1]# more urls.py from django.conf.urls.defaults import patterns, include, url from myappdir1.hello_world import hello_world
# Uncomment the next two lines to enable the admin: # from django.contrib import admin # admin.autodiscover()
urlpatterns = patterns('', # Examples: # url(r'^$', 'myappdir1.views.home', name='home'), # url(r'^myappdir1/', include('myappdir1.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin: # url(r'^admin/', include(admin.site.urls)),i ('^hello_world/$', hello_world),
) |
在第二個專案的urls.py新增黑體字部分
[root@s26 myappdir2]# cat urls.py from django.conf.urls.defaults import patterns, include, url
from myappdir2.hello_world2 import hello_world2
# Uncomment the next two lines to enable the admin: # from django.contrib import admin # admin.autodiscover()
urlpatterns = patterns('', # Examples: # url(r'^$', 'myappdir2.views.home', name='home'), # url(r'^myappdir2/', include('myappdir2.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin: # url(r'^admin/', include(admin.site.urls)), ('^hello_world2/$', hello_world2),
) |
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27043155/viewspace-732229/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- python3安裝和使用virtualenvPython
- CentOS 已安裝virtualenv, 但還是報錯誤 bash: virtualenv: command not foundCentOS
- 簡單安裝與使用虛擬環境virtualenv
- 通過virtualenv安裝指定版本的python的虛擬環境Python
- 2. 安裝
- JBOSS安裝——2
- RAC安裝2
- 2,ELK安裝--ES安裝(單機版)
- ora2pg安裝及解除安裝
- DB2 安裝DB2
- OCFS安裝續2
- python virtualenv報錯-bash: virtualenv: command not foundPython
- 【RAC】 RAC For W2K8R2 安裝--解除安裝(八)
- ubuntu 安裝及相關軟體安裝(2)Ubuntu
- 2 Oracle Data Guard 安裝Oracle
- Sqoop2安裝OOP
- docker安裝swoft2Docker
- helm2安裝配置
- 2節點RAC安裝
- CentOS安裝pm2CentOS
- db2解除安裝DB2
- XE2安裝JVCL
- 2-LinuxJava安裝LinuxJava
- BookKeeper 介紹(2)--安裝
- 安裝配置 msys2
- Manjaro Liunx 安裝到使用 2 安裝後的配置JAR
- 【RAC】 RAC For W2K8R2 安裝--grid的安裝(四)
- 安裝mplayer2和smplayer2
- 【RAC安裝】 AIX下安裝Oracle 11gR2 RACAIOracle
- 【RAC】 RAC For W2K8R2 安裝--RDBMS軟體的安裝(五)
- Electron教程翻譯2:安裝
- WSL2安裝systemd方法
- reids(2)概述與安裝
- 如何打包安裝pm2
- db2 命令列安裝DB2命令列
- XE2再次安裝JVCL
- fail2ban 安裝指南AI
- 安裝11gr2 RAC