Tuesday, May 15, 2012

Re: Django virtualenv, pythonpath issues

To deploy with WSGI you probably want to use Apache with modwsgi.
There are other ways, but this is common.

modwsgi must be build against the python you want to use, and it
should have preferably been built after being configured with
--enable-shared. That is the only python that apache will use. If
the installed apache/modwsgi combination if for a python other than
the one that you want, you can't use it. You have several options,
depending on how "yours" the server is.

You can try to run your project with the available python
You can replace the system modwsgi with one that is to your liking.
You can add a separate apache with a suitable modwsgi and let the
main apache proxy to it

Note that you can't typically replace the system python (what you get
when the root user types "python") without breaking some system
management scripts.

Either of the second two options begins with building a python of the
right version. You will first have to install "development" versions
of several of the system libraries (these packages typically just have
the .h files). Then in the ./configure step specify --enable-shared
and, to keep your python separate if need be, something like
--prefix=/opt/python2.7 .

Build apache second (unless you are allowed to replace it's modwsgi),
since its files will be needed to build modwsgi. (It is possible that
the current apache has enough stuff for modwsgi's build to work, but
if it is a distro apache, you don't want it changing out from under
yuo when someone does and update.)

Finally, build modwsgi telling where to find your python and your install.

Remake your virtual environment against your new python.

Use the WSGIPythonHome directive in your apache config to tell modwsgi
how to set the PYTHONHOME environment variable for its pythons, which
should identify your virtual environment (set it to the directory
containing your ve's lib and bin directories). This allows for the
best match between the paths seen under modwsgi and those seen under
the development server. You can do some extra fixups in your .wsgi
file.

Bill

On 5/15/12, Otávio Augusto Soares <otaviokk@gmail.com> wrote:
>
>
> I'm trying to deploy a django app with virtualenv but I'm not a linux
> expert user.
>
> It's on a shared host. If I type python I got the python 2.4 console. If a
> type python2.7 I got the 2.7 console.
>
> I want to use the 2.7.
>
> 1. I installed virtualenv with setuptools in my private .site-packages.
> 2. I created my env using python 2.7: .site-packages/virtualenv
> --no-site-packages -p python2.7 env
> 3. I activated my env and installed the packages I need.
> 4. I configured (tried to) my .wsgi to use the env
>
> I've been 2 days in step 4. The server has some pre installed modules,
> which are on sys.path. For example, it has django installed, but I want to
> use the module installed in my virtualenv.
>
> I read several wsgi documentation and I came to this:
>
> import sys, os, site
>
> sys.stdout = sys.stderr
>
> os.environ['PYTHON_EGG_CACHE'] =
> '/home/bruddennautica/apps_wsgi/.python-eggs'
> os.environ['DJANGO_SETTINGS_MODULE'] = "brudden.settings"
>
> sys.path.append('/home/bruddennautica/apps_wsgi')
> sys.path.append('/home/bruddennautica/apps_wsgi/env/lib/python2.7/site-packages')
>
> activate_this = '/home/bruddennautica/apps_wsgi/env/bin/activate_this.py'
> execfile(activate_this, dict(__file__=activate_this))
>
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
>
> With this conf, I got a django error which shows me some things. The django
> error isn't important, it's caused because the django version is not equal
> to the one I installed in my virtualenv, the python version either.
>
> PRINT: http://dl.dropbox.com/u/9290581/error.png
>
> It's possible to see the python path entries, most of them not from
> virtualenv. The first one is:
> /home/bruddennautica/apps_wsgi/env/lib/python2.4/site-packages. However
> this folder doesn't exists. Apparently it's added by activate_this.py in
> line 22:
>
> site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3],
> 'site-packages')
>
> Anyone can help me?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/ETGErWaZyMoJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate