[Django]-No module named django.core when running django-admin startproject myproject

5👍

Even if you make it work, it is not good practice to do what you’re doing! Ideally, the only python-related binaries you would want in /usr/local/bin/ would be python, pip and virtualenv (or venv, pyvenv)…

I would suggest you to delete /Library/Frameworks/Python.framework/Versions/3.6 ONLY IF you installed it there. As far as I know, macOS only comes with python2.7 installed and not python3.6!

Then open a new shell and try this:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install python3
pip3 install virtualenv
cd ~/Desktop/
mkdir proj
cd proj
virtualenv -p python3 env
source env/bin/activate
pip install django
django-admin.py startproject testproj

skip the first step if you already have brew installed

2👍

Check your permissions in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ with an ls -la command. If you see anything owned by root, this probably needs to change. I suspect that since you installed some packages as root, the permissions are weird and it can’t find the module. If this is the case, reinstall the package(s) as your own user using sudo.

Another thing you should check: as phd mentioned you need to make sure you’re using the version of python you think you are. Check this by running which python to tell you the location of the one you’re referencing, and python --version to tell you which version you’re using. If it’s not Python 3.6, then you installed Django for a different version of Python. In this case, simply install Django for version 3.6 and you’ll be on your way.

For future reference, Python offers a module called venv to prevent version mishaps like this. More info can be found here.

1👍

It seems like you are trying to create or work on a django project without using a python virtual environment. I recommend reviewing the python 3 venv documenation (https://docs.python.org/3/library/venv.html). Then creating a virtual environment (venv) specifically for your web application. Once you you that project’s venv setup you can install django into that venv.

0👍

On MacOS, use sudo before the command:

sudo django-admin startproject myproject

Leave a comment