2

My OS is Ubuntu 18.04 if that helps.

I tried installing using pip. It keeps saying it's successful but this is the result:

Requirement already satisfied: django in /usr/local/lib/python2.7/dist-packages (1.11.17)
Requirement already satisfied: pytz in /usr/local/lib/python2.7/dist-packages (from django) (2014.10)

Now, I tried upgrading it and it still shows the same error.

I tried using pip3. It's successful but when I try to import it on python 3.0, it shows this error:

ModuleNotFoundError: No module named 'django'

I also tried installing using virtualenv. It still doesn't work.

If it helps, this is the error which shows when I try installing using pip3:

Requirement already satisfied: django in ./pgadmin4/lib/python3.6/site-packages (2.1.4)
Requirement already satisfied: pytz in ./pgadmin4/lib/python3.6/site-packages (from django) (2018.3)
David Hermes
  • 33
  • 1
  • 5

3 Answers3

2

The most sane setup is to install django in a virtualenv environment.

Inside your project's directory, do like this:

python3 -mvenv venv
. ./venv/bin/activate
pip install django

Note that when the virtualenv is activated, python and pip are added to PATH from the virtualenv, so you don't need to worry about using python3 or pip3. And all your packages will be installed under ./venv, well isolated from everything else in your system.

To deactivate the virtualenv in the current shell, run deactivate. Just don't forget to re-run . ./venv/bin/activate every time you want to work on the Django project.

janos
  • 120,954
  • 29
  • 226
  • 236
  • Isn't pip for python2.7? I believe its pip3 for python3.6+. – kokeen Dec 15 '18 at 01:05
  • @kokeen If you just say "pip", it can be anything. It can be an alias to `pip3`. In the example I gave, it will be `./venv/bin/pip`, therefore the appropriate version for the `venv`, matching the version of the Python binary that was used to create it, in this example `python3`. – janos Dec 15 '18 at 01:09
  • Oh, that makes sense. I mentioned it as when I started working in python3 I used to face errors as I was more used to pip than pip3. – kokeen Dec 15 '18 at 01:12
  • 1
    @kokeen When working with Python, it's best to create a virtual environnent like this, and then you don't need to worry about versions. You can have perfectly isolated projects, using different versions of dependencies and Python interpreter itself, independently. You just have to remember to run the activation script every time before use. – janos Dec 15 '18 at 01:23
  • Yeah, that is what I do now. Thank you! – kokeen Dec 15 '18 at 01:25
1

Can you try this just for testing if you want to use in virtual environment

Start new project in new directory

mkdir djangoTest
cd djangoTest

Create new environment named venv

python3 -mvenv venv

Then activate it

source venv/bin/activate

install django in it (you have to use always pip instead pip3 in venv)

pip install django

And create your django project named testDjango

django-admin startproject testDjango
cd testDjango

Create new app in it

python manage.py startapp testApp

And finally try run server with

python manage.py runserver 
0

If you want, you can remove existing dependencies directly. If Django is already present, just uninstall it using pip3 and then reinstall it. I had the same issue with TensorFlow. I did a clean uninstall and then used a TensorFlow wheel for a new install.

pip3 uninstall django

You can take a look at this question for more details.

kokeen
  • 326
  • 1
  • 2
  • 8