Can only get "manage.py runserver" if I use python3 instead of python

1,768 views
Skip to first unread message

Ja Cre

unread,
Aug 15, 2017, 3:18:24 PM8/15/17
to Django users
I have been working through the initial tutorial and ran into a load of issues with my anaconda install using python 2.7. In the end it wouldn't launch the server.

Anyway, I decided to change up on my machine to python3. That said, I am now getting strange results which are:

If I use the terminal command $python -m django --version I get the following:

"../Contents/MacOS/Python: No module named django"

 
If I change to "$python3 -m django --version" terminal gives me back: "1.11.4"

Now, when I am in the tutorial and starting again from the beginning I do the following: "$django-admin startproject mysite"

This seemed to work.

However, when I tried: "$python manage.py runserver" I get the following:

Traceback (most recent call last):

  File "manage.py", line 17, in <module>

    "Couldn't import Django. Are you sure it's installed and "

ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?


If I change to include 3, so "$python3 manage.py runserver" all is well.


My question is do I need to always use python3 in every command now? I does not say that in the tutorial.


My Mac OSx has a native install of 2.7 which I believe is required by my machine for other apps dependency.


Any help would be really appreciated!

Antonis Christofides

unread,
Aug 15, 2017, 3:33:58 PM8/15/17
to django...@googlegroups.com

Hi,

The Python 3 installation is completely separate from Python 2 (the same would hold if you had both 2.7 or 2.6, or 3.6.0 and 3.6.1; each Python version you have installed on the system is completely separate from the others). Somehow when you originally installed Django, you did so in Python 3. So Python 2 has no Django installed. If you install Django on Python 2 as well, you will be able to run it either way.

Make sure you also learn to use virtualenv.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com
--
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/00c61c2d-95ed-4022-840a-b997318e12ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ja Cre

unread,
Aug 16, 2017, 6:19:41 AM8/16/17
to Django users
Thanks Antonis,

I am now up and running with virtualenv and working great.

I appreciate your help!

Sol Chikuse

unread,
Aug 16, 2017, 4:32:28 PM8/16/17
to Django users
Hi Ja,

Just to add to what Antonis said, you can also create virtual environments with Python3 using the below code:

python3 -m venv your_virtual_dir_name

For instance to create a virtual directory with name mysite you will have to type:

python3 -m venv mysite


And then you can install django and other packages in that environment. You will have to activate it first just like with virtualenv.

Happy Coding!
Reply all
Reply to author
Forward
0 new messages