No module named django after upgrade to os x Lion

213 views
Skip to first unread message

angelika

unread,
Oct 27, 2011, 2:17:58 AM10/27/11
to Django users
Hello,

I'm new to both Python and Django. A few months ago, I installed
Django on my mac (running Snow Leopard). I took me quite some time,
but I got it running. After that I didn't get around to doing anything
with it. A few weeks ago, I upgraded my mac to run Lion and now, when
I type import django in the python interpreter, it says No module
named django.

I found someone who had had a similar problem, and I'm guessing it
could be connected to the fact that Lion comes with Python 2.7.1? My
Django version is 1.2.5. Again, I know almost nothing about Python, so
I could be way off base. Any ideas how I can solve this, or find out
what the problem is?

/Angelika

Tom Evans

unread,
Oct 27, 2011, 5:28:51 AM10/27/11
to django...@googlegroups.com

Python packages are installed for a specific minor version of python.
If you upgrade your minor version of python, then you will need to
reinstall all the python packages you use for that specific minor
version of python.

By 'minor version', I mean this: Python 2.7.1 has major version 2,
minor version 7 and minor minor version 1. You need to reinstall
whenever you change major or minor version.

Cheers

Tom

angelika

unread,
Oct 27, 2011, 9:30:20 AM10/27/11
to Django users
Thanks, Tom. I see. So basically I need to reinstall Django, if I want
to run it on Python 2.7.1, is that it?

As far as I can tell, the older versions of Python are still installed
on my machine. Does that mean that it might be possible to run an
older version instead, and not have to reinstall Django? Can I run
different versions of Python on the same machine, and just switch
between the two?

/Angelika

On Oct 27, 11:28 am, Tom Evans <tevans...@googlemail.com> wrote:

Andre Terra

unread,
Oct 27, 2011, 9:43:22 AM10/27/11
to django...@googlegroups.com
You can run different versions of python using virtualenv [1]. It is hands down the best way to handle multiple python environments.

You can use virtualenvwrapper [2] to automate some of the process. I'm not sure how good it is on Mac OS, but you should be fine. I found a link [3] that looks like a tutorial, but unfortunately blogspot.com is blocked for me, so I can't read through it to assert its quality.


Good luck!
AT

[1] http://pypi.python.org/pypi/virtualenv
[2] http://www.doughellmann.com/projects/virtualenvwrapper/
[3] http://paintincode.blogspot.com/2010/08/install-pip-virtualenv.html



--
You received this message because you are subscribed to the Google Groups "Django users" group.
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.


Tom Evans

unread,
Oct 27, 2011, 9:59:03 AM10/27/11
to django...@googlegroups.com
On Thu, Oct 27, 2011 at 2:43 PM, Andre Terra <andre...@gmail.com> wrote:
> You can run different versions of python using virtualenv [1]. It is hands
> down the best way to handle multiple python environments.
>
> You can use virtualenvwrapper [2] to automate some of the process. I'm not
> sure how good it is on Mac OS, but you should be fine. I found a link [3]
> that looks like a tutorial, but unfortunately blogspot.com is blocked for
> me, so I can't read through it to assert its quality.
>
>

+1

For my projects I use virtualenv and pip, with all the required
packages specified in a requirements.pip file.

When I want to redeploy, it is simply a case of:

rm -rf environ
virtualenv --no-site-packages environ
source environ/bin/activate
pip install -r requirements.pip

requirements.pip is simple and looks like this:

django>=1.3,<1.4
south
MySQL-python
django-timezones
(etc)

Makes everything consistently reproducible. No packages get installed
in my system python folders, and my django app is insulated from any
packages added to the system python folders.

Cheers

Tom

http://www.pip-installer.org/en/latest/index.html
http://code.google.com/p/modwsgi/wiki/VirtualEnvironments

Kurtis Mullins

unread,
Oct 27, 2011, 10:20:57 AM10/27/11
to django...@googlegroups.com
Good luck with installing MySQL-python. You'll probably see an error at some point that the Module MySQLdb is missing if you use MySQL and don't install it. Last time, with Snow Leapord, I had to install "Mac Ports" to get it working.

If you don't want to use the complexity of the virtual environment, just run "sudo easy_install django" or "sudo pip install django" from your terminal. This will install Django system-wide. 

Of course a virtual environment seems to be a good idea by consensus and Tom's instructions include a specific Django version which is the latest stable available.

Javier Guerra Giraldez

unread,
Oct 27, 2011, 11:04:30 AM10/27/11
to django...@googlegroups.com
On Thu, Oct 27, 2011 at 9:20 AM, Kurtis Mullins
<kurtis....@gmail.com> wrote:
> If you don't want to use the complexity of the virtual environment, just run
> "sudo easy_install django" or "sudo pip install django" from your terminal.
> This will install Django system-wide.

the same commands work inside a virtualenv. with the advantage of
being independent of what Apple does with the rest of the system.

--
Javier

bazaarsoft

unread,
Oct 27, 2011, 11:30:08 AM10/27/11
to Django users
Mac OS has always carried multiple Python installs. You can start
python using python2.5, python2.6, and on Lion python2.7. Those
installs are under /System/Library/Frameworks/Python.framework/ but
links to the executables are in /usr/bin/.

When you install Python packages, they get installed in /Library/
Python/VERSION#/site-packages/, so your django install is probably
under the 2.6 directory. Python 2.6 was the default python on Snow
Leopard - I believe Python 2.7 is the default on Lion and django isn't
installed in that directory which is why it stopped finding it.

Just FYI...

jay

creecode

unread,
Oct 27, 2011, 11:45:58 AM10/27/11
to django...@googlegroups.com
Hello Angelika,

As a test you may want to try the defaults command ( for more info "$ man defaults" and/or google "mac os x defaults" ) to see if your Django install is still in the site-packages of an older version of python.  Try something like this on the command line...

$ defaults write com.apple.versioner.python Version 2.6

    ( or 2.5, 2.4, etc depending on which version of Python you were using before ).

Log out and back into your shell.

$ python

>>> import django

Let us know what you find.

In the end though you may just want to reinstall Django into the current version of the Apple supplied "current" version of Python for Lion ( 2.7.x ),  If you did the above test, just run the defaults command with 2.7 and log out/in, etc.  Then do your Django install.  Keep in mind that the older Django might still be hanging around in the old location so if your're concerned about disk space, you may want to attempt removal.  Otherwise it shouldn't cause a problem.

Toodle-looooooooooo............
creecode

creecode

unread,
Oct 27, 2011, 11:55:42 AM10/27/11
to django...@googlegroups.com
Angelika may not want to get into virtualenv and virtualenvwrapper at this point.  If you're just getting into Python/Django it may be more overhead than you want to deal with conceptually at this time.  If your project is simple or you're just learning then you may want to wait until you feel the need for these tools.

Don't get me wrong these tools are fantastic and I use them myself!

Toodle-loooooooooo..........
creecode

Andre Terra

unread,
Oct 27, 2011, 12:12:27 PM10/27/11
to django...@googlegroups.com
IMHO, If you can't understand how imports and sys.path work, it's best to put the Django book aside and read up on the basics of installing and running Python.


Cheers,
AT

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

angelika

unread,
Oct 28, 2011, 5:13:20 AM10/28/11
to Django users
Thank you all for your help and suggestions. Last time I installed
Django it took a full two days and I was nearly in tears at the end.
Most of the time was spend trying to solve the problems that Kurtis is
talking about, with the MySQLdb package. Although I am usually not a
person who takes shortcuts, this time I'm really looking for the
easiest way to just get the darn thing to work.

creecode, I tried the commands you suggested first. No matter which
version I switched to, it still said No module named django, which
seems weird but there it is. So I ran sudo easy_install django, just
to see if it could be that easy. When the install was done, it seemed
to work at first. I could run import django, no problem. I started the
tutorial on djangoproject.com and got as far as setting up a db and
running python manage.py runserver, before the dreaded
"django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module: No module named MySQLdb" started showing up. God damn it.

At this point I thinking maybe I should just switch to using
PostgreSQL instead, if that would solve the problem. What do you guys
think?

/Angelika

Andre Terra

unread,
Oct 28, 2011, 5:47:20 AM10/28/11
to django...@googlegroups.com
PostgreSQL is great, you will have no regrets!


Cheers,
AT

Kurtis Mullins

unread,
Oct 28, 2011, 6:49:43 AM10/28/11
to django...@googlegroups.com
I'd give PostgreSQL a shot and see if it magically works for you. It's an awesome database. If you have any problems with it though, here's the "easy way out" I took. I just installed Mac Ports and never had another problem. Of course, you'll have to make sure you're using the Mac Ports tools you install (Python, easy_install/pip) and not the ones that come with OSX. More information here:


Some of the packages you'll need include Python, setup tools, and the MySQL-python connector. Let me know if you decide to go this route and I'll be happy to help you along the way! There's also lots of good info that can be found with google.

Good luck!

angelika

unread,
Oct 28, 2011, 10:22:28 AM10/28/11
to Django users
Alright, I'm gonna give PostgreSQL a try over the weekend, I'll let
you know how it works out.
Thanks, guys!
/Angelika

On Oct 28, 12:49 pm, Kurtis Mullins <kurtis.mull...@gmail.com> wrote:
> I'd give PostgreSQL a shot and see if it magically works for you. It's an
> awesome database. If you have any problems with it though, here's the "easy
> way out" I took. I just installed Mac Ports and never had another problem.
> Of course, you'll have to make sure you're using the Mac Ports tools you
> install (Python, easy_install/pip) and not the ones that come with OSX. More
> information here:
>
> http://www.macports.org/
>
> Some of the packages you'll need include Python, setup tools, and the
> MySQL-python connector. Let me know if you decide to go this route and I'll
> be happy to help you along the way! There's also lots of good info that can
> be found with google.
>
> Good luck!
>
>
>
>
>
>
>
> On Fri, Oct 28, 2011 at 5:47 AM, Andre Terra <andrete...@gmail.com> wrote:
> > PostgreSQL is great, you will have no regrets!
>
> > Cheers,
> > AT
>

creecode

unread,
Oct 28, 2011, 12:19:44 PM10/28/11
to django...@googlegroups.com
Hello Angelika,


On Friday, October 28, 2011 2:13:20 AM UTC-7, angelika wrote:

creecode, I tried the commands you suggested first. No matter which
version I switched to, it still said No module named django, which
seems weird but there it is.

If your curious about where the old Django install may have gotten to you could try on the command line...

sudo find -x / -name django -print

So I ran sudo easy_install django, just
to see if it could be that easy. When the install was done, it seemed
to work at first. I could run import django, no problem. I started the
tutorial on djangoproject.com and got as far as setting up a db and
running python manage.py runserver, before the dreaded
"django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module: No module named MySQLdb" started showing up. God damn it.

If you are just doing local development for learning I think you can bypass the database install, at least that is what the Django Quick Install docs indicate.

At this point I thinking maybe I should just switch to using
PostgreSQL instead, if that would solve the problem. What do you guys
think?

You could give it a go but if you're just wanting to get through the tutorial is does seem like overkill.  I've just tried installing Postgres on Mac OS X for the first time and it wasn't smooth sailing by any means.  Part of the issues were related to installing the Postgres server on an older OS version and hardware.  I did install psycopg2 on recent hardware with current Lion and a fair amount of hair pulling.  psycopg2 is a connector so that Django, through Python, will be able to talk to a Postgres server.  It does the same job that MySQLdb does for MySQL.

Toodle-loooooooooooooo.............
creecode

Kurtis

unread,
Oct 28, 2011, 1:56:34 PM10/28/11
to Django users
Okay, I think I've got the exact steps down needed to get this running
right. If these are actually it, I'm not sure if I had any other
prerequisites I can't think of at the moment, then it's a matter of
copying and pasting 3 lines into your terminal. (Less than 5-10
minutes total)

1. Install "Brew" (http://mxcl.github.com/homebrew/)
2. Use Brew to Install mysql-connector-c
3. Install MySQL-python

Open up your terminal and follow these steps. If you are unsure of
anything during the process, then feel free to read more information
on what these are. Google is your friend here :)

/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
brew install mysql-connector-c
sudo easy_install mysql-python

Hopefully that works for you! Good luck.

angelika

unread,
Nov 2, 2011, 5:49:29 AM11/2/11
to Django users
Thanks a million, Kurtis! I followed your advice and I no longer get
any errors when I run "python manage.py runserver". Hurray :) !

I'll probably give PostgreSQL a try once I've got the hang of python
and django a bit more, since you were all so positive about that.

My next problem is that the command python manage.py synchdb does not
create any tables, but I've started a new thread for that :)
http://groups.google.com/group/django-users/browse_thread/thread/eca94f905a6bea10

Thanks for all your help!
/Angelika

On Oct 28, 7:56 pm, Kurtis <kurtis.mull...@gmail.com> wrote:
> Okay, I think I've got the exact steps down needed to get this running
> right. If these are actually it, I'm not sure if I had any other
> prerequisites I can't think of at the moment, then it's a matter of
> copying and pasting 3 lines into your terminal. (Less than 5-10
> minutes total)
>
> 1. Install "Brew" (http://mxcl.github.com/homebrew/)
> 2. Use Brew to Install mysql-connector-c
> 3. Install MySQL-python
>
> Open up your terminal and follow these steps. If you are unsure of
> anything during the process, then feel free to read more information
> on what these are. Google is your friend here :)
>
> /usr/bin/ruby -e "$(curl -fsSLhttps://raw.github.com/gist/323731)"
Reply all
Reply to author
Forward
0 new messages