Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Python can't import Django and it's in the site-packages directory
#1
Hello,

I'm trying to play around with the Django tutorial in the Django website, but I ran into an error and don't understand why I am getting it. I found some info about it in other forums, but the answers talk about setting a virtual environment or adding it to the PYTHONPATH environment variable. I still don't understand virtual environments and I'm trying to run this example without it—probably I'll learn and use one soon—and I have django in the following directory "C:\Users\Ivan\Anaconda3\pkgs\python-3.7.0-hea74fb7_0\Lib\site-packages". Isn't this directory supposed to be correct for python to import Django?

This is the exact command I'm using and the exact error I'm getting:

!python manage.py runserver
Output:
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 <module> main() File "manage.py", line 16, in main ) from exc 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?
Thanks in advance.
Quote
#2
django needs a virtual env. to run.

open command prompt pip install virtualenv
virtualenv . (to use a specic python version - virtualenv . -p python3.8 or whatever)

source bin/activate for linux or don't remember the command for windows should not be hard to find

pip install django

django-admin startproject project-name

python-version manage.py runserver

This tutorial is pretty good in helping understand how to get started with django
https://www.youtube.com/watch?v=UmljXZIypDc
The only dumb question, is one that doesn't get asked.
Gaming Collection
Homepage
Johnny's CookBook - Powered By: Python3.8 | Bootstrap4 | Apache2 | Django
Quote
#3
Hi, menator. Thank you very much for your reply.

I read something in the tutorial about creating the virtual environment, but I think I remember seeing it was optional. Probably I have a bigger concern right now because here https://docs.djangoproject.com/en/3.0/in...#verifying it tells you to import django to make sure it was installed successfully. However, when I do import django I get
Output:
ModuleNotFoundError: No module named 'django'
. This is what confuses me, because it is in my site-packages folder along with the other packages I have installed via pip. For example, chardet is there, and I can import it and use it normally. Actually, I can run !django-admin startproject project-name and create the project successfully. Probably I need to add it to my PYTHONPATH? If so, my question is, why do I have to do it if it's in my site-packages folder already?
Quote
#4
Django needs a virtual environment to run.
The only dumb question, is one that doesn't get asked.
Gaming Collection
Homepage
Johnny's CookBook - Powered By: Python3.8 | Bootstrap4 | Apache2 | Django
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Cannot import BeautifulSoup4 as bs4 and BeautifulSoup4 not in same directory B5473829 1 592 Jul-05-2019, 06:55 PM
Last Post: snippsat
  convert html to pdf in django site shahpy 4 3,002 Aug-17-2018, 11:10 AM
Last Post: Larz60+
  Django packages for website with paid user accounts jmarchini 2 1,224 Jan-08-2018, 09:10 AM
Last Post: SarbjitGrewal
  first django site-ms word/pdf files jon0852 1 2,354 Nov-19-2017, 08:39 PM
Last Post: homayoon_hashemi

Forum Jump:


Users browsing this thread: 1 Guest(s)