New to Django

58 views
Skip to first unread message

Gary Dhillon

unread,
Feb 29, 2016, 8:05:12 PM2/29/16
to Django users
I've installed Django and I keep getting no module named django when importing. I have python 3.5.1 and used pip to install django 1.9.2. Its showing up on my python 2.7 though. Any help would be appreciated.

Lachlan Musicman

unread,
Feb 29, 2016, 9:19:21 PM2/29/16
to django...@googlegroups.com
You will find there are two different pips on your computer - the default is obv 2.7. the most likely command you will need is pip3 (on ubuntu), but your best bet is to:

 - set up a virtualenv
 - set up your path to default to python 3.5.1

I would use the virtualenv solution personally.

There is also the quick and dirty "which python" then doing an ls -l | grep pip on the directory that python is in (/usr/bin for me)

Cheers
L.


------
The most dangerous phrase in the language is, "We've always done it this way."

- Grace Hopper

On 1 March 2016 at 11:59, Gary Dhillon <gary...@gmail.com> wrote:
I've installed Django and I keep getting no module named django when importing. I have python 3.5.1 and used pip to install django 1.9.2. Its showing up on my python 2.7 though. Any help would be appreciated.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3ea8f361-3642-4b16-97f0-77ce379a0a49%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gary Dhillon

unread,
Mar 1, 2016, 2:55:17 AM3/1/16
to Django users
Thanks, really appreciate it!

Chris Bartos

unread,
Mar 1, 2016, 4:51:07 PM3/1/16
to Django users
The best way to use Python especially Django is by creating what is called a "Virtual Environment". This is a separate instance of Python that you can install all the tools that you need to run your Django app without having to messing up your current Python instance.

It will also help to freeze the packages you install which is great for deploying to different environments and such. But, the steps are pretty much the same everything you create a new Virtual Environment. These steps are assuming you use a Unix based operating system. If you are using Windows, these steps will be a little different.

Step 1: Install 'virtualenv'

First things first. You need to install virtualenv. You can do this with the 'pip' command.

$ pip install virtualenv

Step 2: Create your virtual environment

The next step to creating a virtual environment is to actually create it. This step will install an instance of Python and also install Pip for you so you can install the packages that you want.

$ virtualenv venv

You can call the virtual environment anything you like. I like to call it 'venv'

Step 3: Activate the virtual environment

This step will change your Python path so that you will use the virtual environment version of Python and Pip. You'll notice that when you enter this command, you might see '(venv)' next to your commandline. That's how you know that you're running the virtual environment

$ source venv/bin/activate

Step 4: Install your packages

You can then install your packages at this point. You'll be happy to know that you're packages will be installed inside of your virtual environment. So, when you try to 'import django', the Python interpreter will be able to find it.

Step 5: Deactivate your virtual environment

When you are done working on your Django app, and you want to exit from your virtual environment, simply call:

$ deactivate

You'll be back to your default Python path.

I hope this helps some. If you have any other questions, please let me know!
Reply all
Reply to author
Forward
0 new messages