virtualenv + pip freeze setup issue

666 views
Skip to first unread message

towerofbabel

unread,
Mar 21, 2011, 11:49:48 AM3/21/11
to pywe...@googlegroups.com
Hi, I wonder if someone can help me with some virtualenv and pip issues.

I am on Ubuntu 10.04 and I have successfully set up virtualenv with pip. 

How do I know I was successful? 
I can activate and deactivate a specific virtual environment I have created, and I have used yolk to check what is installed in my virtualenv. I have installed Django in my virtualenv (tested by importing django from the python interpreter in the virtual env).


But, I have encountered two problems:

1. pip freeze 
I try to build a requirements file with sudo pip freeze > filename.txt and no matter what, it tells me permission is denied for filename.txt. I have created other files in the virtualenv using touch with success - The problem is just with freeze and even though I use sudo I still get permission denied.

2. Running Django as WSGI
I have successfully checked that WSGI is configured correctly for apache (by running a simple hello world wsgi application in a public folder). However, I get 500 errors when I try to run my Django project from my wsgi file.

My wsgi file is here:
/path/to/public/application.wsgi

I have my WSGI script alias set up correctly in the virtual host file for the domain (that is how I tested WSGI before I tried to run Django)

Here is my wsgi file for the django project:

import os
import sys
import site

site.addsitedir('/path/to/virtenv_1/lib/python2.6/site-packages')

os.environ['DJANGO_SETTINGS_MODULE'] = 'project_name.settings'

sys.path.append('/path/to/public')

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

According to several sources, my file appears fine. Yet, Internal Server Error when this file is used.

Any ideas?

Thanks.


Shai Berger

unread,
Mar 21, 2011, 11:56:22 AM3/21/11
to pywe...@googlegroups.com
On Monday 21 March 2011 17:49:48 towerofbabel wrote:
>
> *1. pip freeze *

> I try to build a requirements file with sudo pip freeze > filename.txt and
> no matter what, it tells me permission is denied for filename.txt. I have
> created other files in the virtualenv using touch with success - The
> problem is just with freeze and even though I use sudo I still get
> permission denied.
>
That's because the redirection is evaluated by the shell "outside" of sudo;
the sudo applies only to the "pip freeze" part, not to the
">requirements.txt". The standard solution is to use tee (look it up if you
don't know it):

pip freeze | sudo tee requirements.txt

HTH,
Shai.

Shai Berger

unread,
Mar 21, 2011, 12:04:56 PM3/21/11
to pywe...@googlegroups.com
On Monday 21 March 2011 17:49:48 towerofbabel wrote:
>
> *2. Running Django as WSGI*

> I have successfully checked that WSGI is configured correctly for apache
> (by running a simple hello world wsgi application in a public folder).
> However, I get 500 errors when I try to run my Django project from my wsgi
> file.
>
> My wsgi file is here:
> /path/to/public/application.wsgi
>
> I have my WSGI script alias set up correctly in the virtual host file for
> the domain (that is how I tested WSGI before I tried to run Django)
>
> Here is my wsgi file for the django project:
>
> import os
> import sys
> import site
>
> site.addsitedir('*/path/to/virtenv_1/*lib/python2.6/site-packages')
>
> os.environ['DJANGO_SETTINGS_MODULE'] = '*project_name*.settings'
>
> sys.path.append('*/path/to/public*')

>
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
>
> According to several sources, my file appears fine. Yet, Internal Server
> Error when this file is used.
>
> Any ideas?
>
In all probability, path issues: Either your WSGI doesn't define the path to
your project correctly (the file you have says that the project should be a
folder in public), or you've developed your site in the project folder and
trusted the path to include it (because when you run with manage.py runserver,
it is the working directory). You should be able to find out more by either:

1) Looking at the Apache error log, or
2) Making sure you have DEBUG=True in your settings and looking at the error
page.

HTH,
Shai.

benny daon

unread,
Mar 21, 2011, 12:25:04 PM3/21/11
to pywe...@googlegroups.com
On Monday 21 March 2011 17:49:48 towerofbabel wrote:
>
> *2. Running Django as WSGI*
> I have successfully checked that WSGI is configured correctly for apache
> (by running a simple hello world wsgi application in a public folder).
> However, I get 500 errors when I try to run my Django project from my wsgi
> file.
>

Shai is probably right - a path issue. I'd suggest using gunicorn instead of wsgi, where you need no setup files.It really simplified deployment for us.

Benny

towerofbabel

unread,
Mar 21, 2011, 3:43:58 PM3/21/11
to pywe...@googlegroups.com
awesome, thanks. No, I didn't know about tee but now I do.

towerofbabel

unread,
Mar 21, 2011, 3:53:49 PM3/21/11
to pywe...@googlegroups.com
Shai and Benny, Thanks for the help. It was indeed a silly path issue and Shai was on the money:

sys.path.append('/path/to/public')

should have been

sys.path.append('/path/to/virtenv_1')

Thanks.

gunicorn looks interesting but Being a relative beginner I'll just stick with getting a handle on apache/WSGI for now.


Meir Kriheli

unread,
Mar 21, 2011, 4:33:03 PM3/21/11
to pywe...@googlegroups.com
On 03/21/2011 09:53 PM, towerofbabel wrote:
> Shai and Benny, Thanks for the help. It was indeed a silly path issue
> and Shai was on the money:
>
> sys.path.append('*/path/to/public*')
>
> /*should have been*/
>
> sys.path.append('*/path/to/virtenv_1*')
>
> Thanks.
>

Obligatory documentation link with more info:
http://code.google.com/p/modwsgi/wiki/VirtualEnvironments


Cheers
--
Meir Kriheli

Reply all
Reply to author
Forward
0 new messages