Django + PyPy = ?

678 views
Skip to first unread message

Dmitry Pisklov

unread,
Jul 22, 2011, 6:40:38 PM7/22/11
to django...@googlegroups.com
Hi all,

Tried to use PyPy to run django and tried following this instructions:

But with no luck - I'm getting this error when trying to run pypy manage.py:

$ pypy manage.py runserver
'import site' failed
Traceback (most recent call last):
  File "app_main.py", line 53, in run_toplevel
  File "manage.py", line 2, in <module>
    from django.core.management import execute_manager
ImportError: No module named django.core

 However, it can find django module:

$ pypy
'import site' failed
Python 2.7.1 (b590cf6de419, Apr 30 2011, 02:00:34)
[PyPy 1.5.0-alpha0 with GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``"3 + 3 = 8"  Anto in the JIT
talk''
>>>> import django
>>>> django
<module 'django' from '/usr/share/pyshared/django/__init__.py'>
>>>> 
Googling didn't helped me - any ideas?

PS it works well with my default python2.6 installation. My OS is debian, if it can help anyhow...

Bill Freeman

unread,
Jul 25, 2011, 9:12:17 AM7/25/11
to django...@googlegroups.com
Get PyPy running properly first? You second example still has the
error message, even before python's banner is printed. That's not
related to Django at all, I'll bet.

Best to find a PyPy FAQ, mailing list, or IRC channel on which to ask.

Bill

> --
> 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/-/fQx3WRQIiHIJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

Dmitry Pisklov

unread,
Jul 25, 2011, 2:09:37 PM7/25/11
to django...@googlegroups.com
It doesn't make any difference. This error appears if you start pypy from directory other than /pypy-dist/bin. If I start it right from there:

./pypy

Python 2.7.1 (b590cf6de419, Apr 30 2011, 02:00:34)                                                                                                                                      
[PyPy 1.5.0-alpha0 with GCC 4.4.3] on linux2                                                                                                                                            
Type "help", "copyright", "credits" or "license" for more information.                                                                                                                  
And now for something completely different: ``PyPy is an exciting technology                                                                                                            
that lets you to write fast, portable, multi-platform interpreters with less                                                                                                            
effort''                                                                                                                                                                                
>>>> from django.core.management import execute_manager                                                                                                                                 

Traceback (most recent call last):                                                                                                                                                      
  File "<console>", line 1, in <module>                                                                                                                                                 

ImportError: No module named django.core                                                                                                                                                
>>>>

No error you mentioned, but still it doesn't work.

Cheers,
D

Bill Freeman

unread,
Jul 25, 2011, 3:13:34 PM7/25/11
to django...@googlegroups.com
It still doesn't seem like a Django issue, but a pypy issue. You need
to be able to run stuff from other than the pypy-dist/bin directory
for pypy to be useful.

One possibility is that you are actually getting a different pypy
executable. Say (on *nix) "which pypy" from one of those other
directories and see if it mentions the correct pypy.

I don't know a lot about pypy per seh, but does running it from
pypy-dist/bin mean that you haven't run setup.py to install it in your
environment?

For python itself, there are a limited number of places it looks for
site.py on startup, which, in turn, builds up sys.path, so that it
knows where to get stuff for imports that aren't relative to the
current directory. Probably pypy is similar. I still think that it's
not installed correctly.

> --
> 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/-/8aRQYvpY3lkJ.

Dmitry Pisklov

unread,
Jul 27, 2011, 4:34:12 PM7/27/11
to django...@googlegroups.com
That's basically the information I'm trying to find. PyPy docs says nothing about that, and they doesn't mention any setup process at all - all that I need to do according to their site is "unpack and run - and don't touch anything!"... And it simply works for simple python stuff... But not for django. And I'm pretty sure it's not a django problem - I'm just trying to find here someone who tried running django on pypy and succeeded.

Bill Freeman

unread,
Jul 28, 2011, 9:37:25 AM7/28/11
to django...@googlegroups.com
So what happens if you type while pypy-dist/bin is not the current directory.:

/absolute/path/to/pypy-dist/bin/pypy

Error or no?

If no error, how about, while cd'ed to your django
project (where settings.py and manage.py are:

/absolute/path/to/pypy-dist/bin/pypy manage.py shell

Error or no?

If no error, how about (presuming bash or sh):

export PATH=/absolute/path/to/pypy-dist/bin:$PATH
pypy manage.py shell

(or the equivalent for your shell.) You could make this
permanent, if it works and you like it, in ~/.bash_profile .

Or if you don't want to change your PATH environment
variable, you could edit manage.py to begin with:

#!/absolute/path/to/pypy-dist/bin/pypy

Then do:

chmod +x manage.py

And you can then say:

manage.py shell

(or syncdb, runserver, whatever).

Or you can make a shell script called, say, manage, that
cd's to your django project directory, and invokes
manage.py with the appropriate pypy, passing on any
command line arguments that the script got, put the
script somewhere on your path, and you can say:

manage shell

(If you put it somewhere like /usr/local/bin on a multi-user
machine, you may want to choose a better name.)

BTW, I'm not sure, but I don't expect that mod_wsgi would
be willing to run you using pypy.

Bill

> --
> 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/-/OY8G3ppuqcgJ.

Dmitry Pisklov

unread,
Jul 29, 2011, 1:37:46 PM7/29/11
to django...@googlegroups.com
Well, on the second step it fails:

In the different directory (not in bin dir):
$ /home/wsgi/pypy-1.5/bin/pypy
Python 2.7.1 (b590cf6de419, Apr 30 2011, 02:00:34)
[PyPy 1.5.0-alpha0 with GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``"that's why the 'or' is really an
'and' "''
>>>> 

No error, as you can see... Now running shell:
$ /home/wsgi/pypy-1.5/bin/pypy manage.py shell
Traceback (most recent call last):                                                                                                                                                      
  File "app_main.py", line 53, in run_toplevel                                                                                                                                          
  File "manage.py", line 2, in <module>                                                                                                                                                 
    from django.core.management import execute_manager                                                                                                                                  
ImportError: No module named django.core 

The same error...

PS: I'm using fastcgi behind nginx.

Bill Freeman

unread,
Jul 29, 2011, 2:30:22 PM7/29/11
to django...@googlegroups.com
OK.

Try:

$ cd /to/whereever/manage.py/is
$ /home/wsgi/pypy-1.5/bin/pypy
...
>>>> import sys, pprint
>>>> pprint.pprint(sys.path)

Are the directories holding your django install there?

If not, are the directories here pretty much only within (I'm
guessing) /home/wsgi/pypy-1.5/lib ?
That is, the stuff that you've used easy_install or pip install to
install, or python setup.py to
install, may be installed in your python's lib directories, but pypy
may not be falling back to
use those when it doesn't find them in its own lib dirs (I don't know
if it is supposed to). If
this seems to be the problem, you have a number of options available,
including using
pypy to run ez_setup.py to get an easy_install that installs there,
and reinstalling stuff
using that easy_install, or getting packages from pypi and running
their setup.py files by
hand using pypy.

But before you go to far, find one simple package that you have
installed, something
without a lot of dependencies, in your python, that you can't import
from the pypy prompt,
and see what it takes to install that for pypy.

Bill

> --
> 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/-/iAijeg2ZUIsJ.

Dmitry Pisklov

unread,
Aug 2, 2011, 1:19:30 PM8/2/11
to django...@googlegroups.com
Well...

$ /home/wsgi/pypy-1.5/bin/pypy
Python 2.7.1 (b590cf6de419, Apr 30 2011, 02:00:34)
[PyPy 1.5.0-alpha0 with GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``yes, but what't the sense of 0 <
"duran duran"''
>>>> import sys,pprint
>>>> pprint.pprint(sys.path)
['',
 '/home/wsgi/pypy-1.5/lib_pypy',
 '/home/wsgi/pypy-1.5/lib-python/modified-2.7',
 '/home/wsgi/pypy-1.5/lib-python/2.7',
 '/home/wsgi/pypy-1.5/lib-python/modified-2.7/lib-tk',
 '/home/wsgi/pypy-1.5/lib-python/2.7/lib-tk',
 '/home/wsgi/pypy-1.5/lib-python/2.7/plat-linux2',
 '/home/wsgi/pypy-1.5/site-packages',
 '/home/wsgi/pypy-1.5/site-packages/PIL']
>>>>

So you're right, it sees only dirs inside its installation dir. But funny thing is that directory 
/home/wsgi/pypy-1.5/site-packages is actually symlink:
/home/wsgi/pypy-1.5/site-packages -> /usr/share/pyshared/
and it points to the python's site-packages. And that PIL (last entry) exists in the target directory. So I wonder why on earth it sees only PIL subdir, from helluva lot of others? Even if I set path manually:

$ export PYTHONPATH=/usr/share/pyshared
$ /home/wsgi/pypy-1.5/bin/pypy
Python 2.7.1 (b590cf6de419, Apr 30 2011, 02:00:34)
[PyPy 1.5.0-alpha0 with GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``to save a tree, eat a beaver''
>>>> import pprint, sys
>>>> pprint.pprint(sys.path)
['',
 '/usr/share/pyshared',
 '/home/wsgi/pypy-1.5/lib_pypy',
 '/home/wsgi/pypy-1.5/lib-python/modified-2.7',
 '/home/wsgi/pypy-1.5/lib-python/2.7',
 '/home/wsgi/pypy-1.5/lib-python/modified-2.7/lib-tk',
 '/home/wsgi/pypy-1.5/lib-python/2.7/lib-tk',
 '/home/wsgi/pypy-1.5/lib-python/2.7/plat-linux2',
 '/home/wsgi/pypy-1.5/site-packages',
 '/home/wsgi/pypy-1.5/site-packages/PIL']
>>>>

The same error after that:

$ /home/wsgi/pypy-1.5/bin/pypy manage.py shell
 
Traceback (most recent call last):
  File "app_main.py", line 53, in run_toplevel
  File "manage.py", line 2, in <module>
    from django.core.management import execute_manager
ImportError: No module named django.core


So I think I'll give up at this point - I now realized that my interest in pypy come probably too early... 

Bill Freeman

unread,
Aug 2, 2011, 1:30:14 PM8/2/11
to django...@googlegroups.com
See if there is a .pth file somehow made pypy specific in
/home/wsgi/pypy-1.5/site-packages or /home/wsgi/pypy-1.5 that mentions
the PIL package but nothing else.

> --
> 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/-/JkpNIjkA3qYJ.

Dmitry Pisklov

unread,
Aug 4, 2011, 2:46:37 PM8/4/11
to django...@googlegroups.com
In site-packages there's only one .pth file named PIL.pth, mentioning only PIL, but it  doesn't prevent pypy from importing other modules from there:

$ ls /home/wsgi/pypy-1.5/site-packages/

Cheetah/
Cheetah-2.4.2.1.egg-info/
django/
Django-1.2.3.egg-info
flup/
flup-1.0.2.egg-info/
lsb_release.py
mx/
PIL/
PIL.pth
psycopg2/
psycopg2-2.2.1.egg-info
web/
web.py-0.34.egg-info

And here's  what I've got with pypy:
$ ./pypy
Python 2.7.1 (b590cf6de419, Apr 30 2011, 02:00:34)
[PyPy 1.5.0-alpha0 with GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``ECOOP is finished''
>>>> import web.wsgi
>>>> dir (web.wsgi)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '_is_dev_mode', 'http', 'httpserver', 'listget', 'os', 'runfcgi', 'runscgi', 'runwsgi', 'sys', 'validaddr', 'validip', 'web']
>>>> import django
>>>> dir(django)
['VERSION', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'get_version']
>>>> import psycopg2
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/wsgi/pypy-1.5/site-packages/psycopg2/__init__.py", line 69, in <module>
    from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: No module named _psycopg
>>>>

So it seems like pypy has problems with importing packages - not only with django... 
Reply all
Reply to author
Forward
0 new messages