2

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 "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! I am sure given I am new to python I am being a complete moron!

2 Answers 2

1

You can install "virtualenv": https://virtualenv.pypa.io/en/stable/installation/ and create virtual environment and install django there(which is good practice). You can avoid typing python3 inside virtual environment.

  1. virtualenv --no-site-packages -p python3 venv
  2. source venv/bin/activate
  3. pip install django

    ..................

    ..................

python manage.py runserver

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much for the help. I will do that! Just to check, will I need to reinstall python3 to that virtual machine or can I leave everything else where it is? I know SQLlite comes with the python download. Want to make sure all packages will be found.
0

Yes. Python 3's binaries are installed with a suffix of "3", so python will launch a Python 2 interpreter and you need to run python3 to specifically use Python 3.

2 Comments

You might add that if you use a virtualenv you can just type python, regardless of it being 2 or 3. The Django Girls tutorial actually has a note about it.
That's great - I really appreciate the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.