ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 安装virtualenv 2

安装virtualenv 2

原创 Linux操作系统 作者:nginx_web 时间:2012-06-08 07:10:16 0 删除 编辑

 

[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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-06-06

  • 博文量
    54
  • 访问量
    409526