I usually work on PC's but started to work on projects on my mac. I run Python 3 and when I started a new project I did the following:
1) In main project folder, installed virtualenv and activated it.
2) Install Django and Gunicorn
3) Did startproject
When I try to python3 manage.py startapp www I get an error that Django could not be imported. Below is what was in the terminal:
(venv) AB:directory AB$ pip freeze
Django==1.10
gunicorn==19.6.0
(venv) AB:directory AB$ ls
directory manage.py
(venv) AB:directory AB$ python3 manage.py startpap www
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
import django
ImportError: No module named 'django'
During handling of the above exception, another exception occurred:
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?
Try using
python -m pip install django
This is the safest way as far as I know
I had the same problem, make sure you activated virtualenv, since once you close cmd it is no longer activated:
env\\Scripts\\activate
in cmd
Now cmd should have (env) just like this: (env) c:\\users\\user\\PROJECT\\..
Now you can type: python manage.py runserver
I also had the same problem when I use Pycharm. I solved it by adding:
import sys
sys.path.append('/Users/et/PycharmProjects/Jieba_Analyzer/venv/lib/python3.6/site-packages')
to manage.py
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.