Search code examples
djangodjango-2.1

I installed Django version over 2.x but the command django-admin startproject(lowercase) make project with 1.x version


python3 -m venv venv
source venv/bin/actvaite # activate virtual env
pip install --upgrade pip
pip3 install Django # Django 2.1.7 installed

django-admin startproject temp # 1.x version
Django-admin startproject temp # 2.x version

  1. django-admin vs Django-admin
    django-admin start with lowercase make project 1.x version Django-admin start with uppercase make project 2.x version

  1. offical docs - start with lowercase docs

summary 1) whats wrong in my environment? 2) how can i make project with django-admin(lowercase)


Solution

  • It seems like the pip command is pointing to Python 2.x, and pip3 is pointing to Python 3.x. To see if this is this case:

    deactivate  # in case you're in a virtual environment
    pip --verison
    pip3 --verison
    

    This will show you which version of Python each one points to. Since Django 2.x is only compatible with Python 3, pip will automatically installed Django 1.11.x if you're installing with pip under Python 2.x.

    The best way around this is to ensure you're using a virtual environment. To start a new Django project:

    python3 -m venv my_project_venv
    . my_project_venv/bin/activate
    pip --version  # Make sure it is pointing to Python 3
    pip install django
    django-admin startproject my_project
    

    The next time you come back to work on your project, you can re-activate the virtual environment with everything you've pip installed inside it:

    . my_project_venv/bin/activate
    

    Good luck!