0
votes

I cannot configure Django and Miniconda on my Mac.

I receive this error every time when I run python manage.py runserver:

Traceback (most recent call last): File "manage.py", line 10, in main from django.core.management import execute_from_command_line ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "manage.py", line 21, in main() File "manage.py", line 12, in main raise ImportError( ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forge t to activate a virtual environment?

These are the steps I have followed so far:

  • cd /Users/myuser/projects/My_Django_Stuff
  • conda create --name MyDjangoEnv python=3.7
  • source activate MyDjangoEnv
  • conda install django=2.2
  • django-admin startproject first_project
  • cd first_project
  • python manage.py runserver

If I run conda list, django package appears to be installed in my environment:

ca-certificates           2020.1.1                      0
certifi                   2019.11.28               py37_0
django                    2.2.5                    py37_1
libcxx                    4.0.1                hcfea43d_1
libcxxabi                 4.0.1                hcfea43d_1
libedit                   3.1.20181209         hb402a30_0
libffi                    3.2.1                h475c297_4
ncurses                   6.1                  h0a44026_1
openssl                   1.1.1d               h1de35cc_4
pip                       20.0.2                   py37_1
python                    3.7.6                h359304d_2
pytz                      2019.3                     py_0
readline                  7.0                  h1de35cc_5
setuptools                45.2.0                   py37_0
sqlite                    3.31.1               ha441bb4_0
sqlparse                  0.3.0                      py_0
tk                        8.6.8                ha441bb4_0
wheel                     0.34.2                   py37_0
xz                        5.2.4                h1de35cc_4
zlib                      1.2.11               h1de35cc_3

I have tried to delete the environment and create a new one, but I receive the same error every time.

Most of the solutions found online are based on "make sure the environment is activated" and "install Django again using pip", but none of them applies to me as the environment is 100% activated and I use conda for it.

Any idea how I can fix this? Thank you!


Edit: I don't know what was wrong, but after uninstalling Miniconda, reinstalling it again, creating a new environment and reinstalling Django, I no longer get the above error message.

Edit 2: This is getting stupid. I run Django, create my first views, templates, the website was working properly, but after the first mac restart, I get this error again.

Edit 3: I forgot to mention all the commands were executed in Atom's terminal. It looks like Django is actually working if I start the server using Mac's terminal.

If I run which python I get the following response:

Atom's terminal: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3

Mac's terminal: /Users/myuser/opt/miniconda3/envs/MyDjangoEnv/bin/python3

What can be wrong?

2

2 Answers

1
votes

Ok I thinks it's a silling mistake ! Can you run python3 manage.py and not python manage.py

On my mac it's enough ;)

0
votes
pip3 install django

Try this, I had the same problem, using pip3 to install Django again, it worked. Activate your env first.