Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: Couldn't import Django

Tags:

django

I've already configured virtualenv in pycharm, when using the python manage.py command, this is error shown:

E:\video course\Python\code\web_worker\MxOnline>python manage.py runserver
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?

How should I fix it, I've installed django.

like image 768
kerberos Avatar asked Sep 14 '17 05:09

kerberos


People also ask

How do I import Django project into Visual Studio?

In Visual Studio, select File > New > Project, search for "Django", and select the Blank Django Web Project template. (You can also find the template under Python > Web in the left-hand list.)


4 Answers

I think the best way to use django is with virtualenv it's safe and you can install many apps in virtualenv which does not affect any outer space of the system vitualenv uses the default version of python which is same as in your system to install virtualenv

sudo pip install virtualenv

or for python3

sudo pip3 install virtualenv

and then in your dir

mkdir ~/newproject

cd ~/newproject

Now, create a virtual environment within the project directory by typing

virtualenv newenv

To install packages into the isolated environment, you must activate it by typing:

source newenv/bin/activate

now install here with

pip install django

You can verify the installation by typing:

django-admin --version

To leave your virtual environment, you need to issue the deactivate command from anywhere on the system:

deactivate
like image 120
Kalariya_M Avatar answered Oct 10 '22 15:10

Kalariya_M


You need to install Django, this error is giving because django is not installed.

pip install django
like image 28
Astik Anand Avatar answered Oct 10 '22 13:10

Astik Anand


When you install Django on your computer all things go fine but when you install a Virtual environment it gets separated from all things. You will know it's importance when you will make a final project and deploy it to any cloud or hosting.

Just reinstall Django in the virtual environment and baam:

pip install Django

and then just run the command for testing:

python manage.py runsever

and you are all done.

like image 21
Kartikey Srivastava Avatar answered Oct 10 '22 14:10

Kartikey Srivastava


You need to use both commands: pip install django and pip3 install django that worked for me

like image 20
Artur Boytsov Avatar answered Oct 10 '22 15:10

Artur Boytsov