安裝virtualenv 2

nginx_web發表於2012-06-08

 

[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/,如需轉載,請註明出處,否則將追究法律責任。