Python can't import Django and it's in the site-packages directory - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Python can't import Django and it's in the site-packages directory (/thread-24335.html) |
Python can't import Django and it's in the site-packages directory - karkas - Feb-09-2020 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 Thanks in advance.
RE: Python can't import Django and it's in the site-packages directory - menator01 - Feb-10-2020 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 RE: Python can't import Django and it's in the site-packages directory - karkas - Feb-11-2020 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/intro/install/#verifying it tells you to import django to make sure it was installed successfully. However, when I do import django I get . 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?
RE: Python can't import Django and it's in the site-packages directory - menator01 - Feb-11-2020 Django needs a virtual environment to run. |