Proposal to document the error on trying to import django in python 3.4.

168 views
Skip to first unread message

Anjul Tyagi(geety)

unread,
Sep 9, 2015, 9:51:07 AM9/9/15
to Django developers (Contributions to Django itself)
Hi everyone,

I am new to django and wish to address the problem which I faced during the installation of django on Ubuntu 14.04.
I had two versions of python installed before I installed django: python 2.7.6 and python 3.4. I installed django as per the steps given in the documentation.
Now, 
If I type the following on the terminal:

python
>>>import django


It works correctly, but

python3
>>>import django

shows the module not found error. I think we can document this inside the "verifying" section of the "Quick Installation guide" part of documentation just to make sure that new users don't panic seeing this error.

Nick Sarbicki

unread,
Sep 9, 2015, 9:55:59 AM9/9/15
to Django developers (Contributions to Django itself)
Can you show us how you installed django?

More specifically, did you do 

pip install django

and

pip3 install django

As it looks like you only install django for 2.7, and not for 3.4.

- Nick.

Anjul Tyagi(geety)

unread,
Sep 9, 2015, 9:58:36 AM9/9/15
to Django developers (Contributions to Django itself)
yes, I installed django using pip and not pip3.

Nick Sarbicki

unread,
Sep 9, 2015, 10:05:15 AM9/9/15
to Django developers (Contributions to Django itself)
In which case you need to install it again with pip3.

All the defaults in Ubuntu (Python, pip etc.) are focused on 2.7, you always need to append 3 if you want it to be python3 specific.

For earlier versions of ubuntu this was because some core processes required python2.7 and would call it through python. I think they are past that with the latest release, but from memory there is a pep somewhere which states that this should remain the standard for now.

- Nick.

Nick Sarbicki

unread,
Sep 9, 2015, 10:07:37 AM9/9/15
to Django developers (Contributions to Django itself)
To make myself clear. I don't think we need to document this as it is not a django error. 

It is a Python error because the module was not installed correctly.

Maybe there should be a mention of the difference for installation on Ubuntu (and other linux distros?). But this would be unusual for anyone using Windows or Mac as they won't have a default Python install and will often only have 1 version, so 1 pip.

- Nick.

Anjul Tyagi(geety)

unread,
Sep 9, 2015, 10:17:48 AM9/9/15
to Django developers (Contributions to Django itself)
Thanks for all that information Nick, it helped me a lot.

Yes, it will be a platform specific information but may be we can just mention it in the documentation, giving the users a hint.

-Anjul

Tim Graham

unread,
Sep 9, 2015, 3:25:27 PM9/9/15
to Django developers (Contributions to Django itself)
I think a better use of time could be to update the docs to more strongly recommend virtualenv and discourage the use of `sudo pip install`.
Message has been deleted

Anjul Tyagi(geety)

unread,
Sep 10, 2015, 9:15:01 AM9/10/15
to Django developers (Contributions to Django itself)
Yes, this is a perfect solution to this issue. But how do we proceed with it ?

Sorry, but I am new to django contribution !

Tim Graham

unread,
Sep 10, 2015, 10:07:30 AM9/10/15
to Django developers (Contributions to Django itself)
I created a ticket: https://code.djangoproject.com/ticket/25376#ticket

You can read about how to get started contributing to Django in our docs: https://docs.djangoproject.com/en/dev/internals/contributing/

If you have any trouble, #django-dev is a good place to ask questions. Thanks!
Message has been deleted

Anjul Tyagi(geety)

unread,
Sep 11, 2015, 10:22:45 AM9/11/15
to Django developers (Contributions to Django itself)
I drafted the changes in the current documentation regarding emphasizing the use of virtualenv. Have a look and any suggestions are welcome.

Installing an official release with pip

This is the recommended way to install Django.

  1. Install pip. The easiest is to use the standalone pip installer. If your distribution already has pip installed, you might need to update it if it’s outdated. (If it’s outdated, you’ll know because installation won’t work.)

  2. Take a look at virtualenv and virtualenvwrapper. These tools provide isolated Python environments, which are more practical than installing packages systemwide. It's highly recommended to install django in the virtualenv. Virtualenv allows installing packages without administrator privileges and also prevent collision between different versions of python.

  3. If you have installed and set up the virtualenv, you can simply type pip install django after activating the virtualenv. This will install django in the virtualenv's site- packages directory. (No need to use sudo in this case).

    If you don't want to use virtualenv (not recommended), then for Linux, Mac OS X or some other flavor of Unix, enter the command sudo pip install Djangoat the shell prompt. If you’re using Windows, start a command shell with administrator privileges and run the command pip install Django. This will install Django in your Python installation’s site-packagesdirectory.



Installing the development version

Tracking Django development

If you decide to use the latest development version of Django, you’ll want to pay close attention to the development timeline, and you’ll want to keep an eye on the release notes for the upcoming release. This will help you stay on top of any new features you might want to use, as well as any changes you’ll need to make to your code when updating your copy of Django. (For stable releases, any necessary changes are documented in the release notes.)

If you’d like to be able to update your Django code occasionally with the latest bug fixes and improvements, follow these instructions:

  1. Make sure that you have Git installed and that you can run its commands from a shell. (Enter git help at a shell prompt to test this.)

  2. Check out Django’s main development branch (the ‘trunk’ or ‘master’) like so:

    	$git clone git://github.com/django/django.git django-trunk

    This will create a directory django-trunk in your current directory.

  3. Make sure that the Python interpreter can load Django’s code. The most convenient way to do this is to install virtualenv and then use pip. Take a look at how to install and setup the virtualenv here.

    After setting up and activating the virtualenv, type the following command.

    	$pip install -e django-trunk/

    (If not using a virtualenv you have to use sudo pip install -e django-trunk/ but its not recommended)

    This will make Django’s code importable, and will also make the django-admin utility command available. In other words, you’re all set!

    If you don’t have pip available, see the alternative instructions for installing the development version without pip.

Warning

Don’t run sudo python setup.py install, because you’ve already carried out the equivalent actions in step 3.

When you want to update your copy of the Django source code, just run the command git pull from within thedjango-trunk directory. When you do this, Git will automatically download any changes.





-Anjul


Tim Graham

unread,
Sep 11, 2015, 11:57:43 AM9/11/15
to Django developers (Contributions to Django itself)
Could you please submit a pull request? It's much easier to review and leave comments that way. Thanks!

Anjul Tyagi(geety)

unread,
Sep 22, 2015, 9:32:06 AM9/22/15
to Django developers (Contributions to Django itself)
How do I represent the changes the I made in the documentation, I created a branch of the ticket on my local django repository but now should I create a .txt file with the changes or create two new .txt files, one representing the original documentation and other representing the edited version and then share the "diff" file of the two ?

Tim Graham

unread,
Sep 22, 2015, 9:37:12 AM9/22/15
to Django developers (Contributions to Django itself)
See if https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/working-with-git/ helps. If you have further questions, it's probably easier if ask can ask in #django-dev on IRC rather the on this mailing list (which reaches hundreds of people). Thanks!
Reply all
Reply to author
Forward
0 new messages