Unable to do import django

1,085 views
Skip to first unread message

Yves S. Garret

unread,
Jul 8, 2013, 2:10:59 PM7/8/13
to Django users
I've gone through the entire django install steps and when I fired up my Python shell
(python 2.7.5, to be exact) and did import django, this is what I got:

>>> import django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named django

sudo python setup.py install should have done it, yes?  If not, what am I missing?

Larry Martell

unread,
Jul 8, 2013, 2:28:58 PM7/8/13
to django...@googlegroups.com
What platform are you on? On my Mac when I was running 10.5 I had to
create this symlink:

ln -s /usr/local/lib/python2.6/dist-packages/django
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django

But I did not have to do that with 10.8 - there the install just worked.

On CentOS I also had to create a symlink:

ln -s /usr/lib/python2.6/dist-packages/django
/usr/lib/python2.6/site-packages/django

Those are the only 2 platforms I have experience with, so if you're on
something else I can't help.

You could try:

import sys
print sys.path

and see where it's searching.

Yves S. Garret

unread,
Jul 8, 2013, 4:00:15 PM7/8/13
to django...@googlegroups.com

I'm running CentOS 6.3.

This is what happens when I print sys.path.

>>> import sys
>>> print sys.path
['', '/home/user', '/home/user/Downloads/Cython/Cython-0.19.1', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']

Yves S. Garret

unread,
Jul 8, 2013, 3:58:10 PM7/8/13
to Django users
Ok, just installed Django anew with pip (first did uninstall, then install).

This is what I have:

$ django-admin.py help

Traceback (most recent call last):
  File "/usr/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 359, in execute
    version=get_version(),
  File "/usr/lib/python2.6/site-packages/django/__init__.py", line 6, in get_version
    from django.utils.version import get_version
ImportError: cannot import name get_version
$ python
Python 2.7.5 (default, Jun  6 2013, 18:46:06)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named django

Larry Martell

unread,
Jul 8, 2013, 4:03:12 PM7/8/13
to django...@googlegroups.com
On Mon, Jul 8, 2013 at 2:00 PM, Yves S. Garret
Try creating the symlink. Assuming django is in
/usr/local/lib/python2.7/dist-packages/django:

sudo ln -s /usr/local/lib/python2.7/dist-packages/django
/usr/local/lib/python2.7/site-packages/django

Yves S. Garret

unread,
Jul 8, 2013, 4:31:47 PM7/8/13
to django...@googlegroups.com

I just checked, it's not in the path that you described.  The directory
dist-packages is not there, but there is a distutils directory.

How would I find the location where django is installed?

Yves S. Garret

unread,
Jul 8, 2013, 4:34:10 PM7/8/13
to django...@googlegroups.com

Ok, I just found the path, it's located here:
/usr/lib/python2.6/site-packages

My version of CentOS is hosted in Azure Windows virtual environment.

Larry Martell

unread,
Jul 8, 2013, 4:34:10 PM7/8/13
to django...@googlegroups.com
On Mon, Jul 8, 2013 at 2:31 PM, Yves S. Garret
sudo find / -type d -name django -print

Larry Martell

unread,
Jul 8, 2013, 4:36:17 PM7/8/13
to django...@googlegroups.com
On Mon, Jul 8, 2013 at 2:34 PM, Yves S. Garret
I don't know anything about anything related to windows, but it seems
you're running python 2.7 and django was installed for 2.6.

Yves S. Garret

unread,
Jul 8, 2013, 5:01:37 PM7/8/13
to django...@googlegroups.com

How weird.  I have python2.7 set as a default.

$ python --version
Python 2.7.5

Is there a way to force it to be 2.7?

Drew Ferguson

unread,
Jul 8, 2013, 5:18:21 PM7/8/13
to django...@googlegroups.com
Yo

You have 2 versions of python installed:

* python 2.6 installed probably in /usr/bin and using /usr/lib/python2.6

* python 2.7 installed in /usr/local/bin and possibly /usr/lib/python2.7

You need to decide which one you want to use and deal with the tools and
binaries installed for the version to be rejected e.g. pip is currently
installed for 2.6 whereas the default python is 2.7.

The fact that 2.7 is installed in /usr/local/bin suggests this was a
manual build

Also you should consider using virtualenv or similar

https://docs.djangoproject.com/en/1.5/topics/install/#install-the-django-code

On Mon, 8 Jul 2013 15:58:10 -0400
--
Drew Ferguson
AFC Commercial
http://www.afccommercial.co.uk

Yves S. Garret

unread,
Jul 8, 2013, 5:46:25 PM7/8/13
to django...@googlegroups.com

Yes, 2.7 is a manual build and I'd like to use 2.7.  Any way I can go that route?

Drew Ferguson

unread,
Jul 8, 2013, 6:11:36 PM7/8/13
to django...@googlegroups.com
On Mon, 8 Jul 2013 14:46:25 -0700 (PDT)
"Yves S. Garret" <yoursurr...@gmail.com> wrote:

> On Monday, July 8, 2013 5:18:21 PM UTC-4, Drew Ferguson wrote:
> >
> > Yo
> >
> > You have 2 versions of python installed:
> >
> > * python 2.6 installed probably in /usr/bin and
> > using /usr/lib/python2.6
> >
> > * python 2.7 installed in /usr/local/bin and
> > possibly /usr/lib/python2.7
> >
> > You need to decide which one you want to use and deal with the tools
> > and binaries installed for the version to be rejected e.g. pip is
> > currently installed for 2.6 whereas the default python is 2.7.
> >
> > The fact that 2.7 is installed in /usr/local/bin suggests this was a
> > manual build
> >
> > Also you should consider using virtualenv or similar
> >
> >
> > https://docs.djangoproject.com/en/1.5/topics/install/#install-the-django-code
> >
>
> Yes, 2.7 is a manual build and I'd like to use 2.7. Any way I can go
> that route?
>

Install virtualenv for 2.7

Make sure you know which binaries you are using to install
packages with: /usr/bin/pip is currently linked to python2.6 so don't use
that obviously. You may need to install pip or other tools manually for
v2.7

Afterwards install django in a virtualenv


--
Drew

Yves S. Garret

unread,
Jul 8, 2013, 7:42:20 PM7/8/13
to django...@googlegroups.com

If it's less of a pain in the neck, I'd like to use 2.6.  I'd prefer 2.7, but what
I'm working on won't kill me if I go 2.6.
Reply all
Reply to author
Forward
0 new messages