简体   繁体   中英

python3 pip3 and django 2 confusion

I'm new to Python so please help me understand this: From Django's documentation: I need python 3+ to run Django 2+ and I need to check my version by running this:

$ python -m django --version

$ python --version
Python 2.7.14
$ python -m django --version
1.11.10

However I've installed python3 and pip3 in order to install (or upgrade?) Django 2 so:

$ python3 --version
Python 3.6.3    
$ python3 -m django --version
    2.0.2

It seems to me that there are 2 python run parallely on my machine (Linux Ubuntu 17) so what I did was not upgrading Python, pip or Django but installing a newer version of them.

Some answers on stackoverflow suggest that I should not use pip3 to upgrade Django.

So how do I use python3 to test my app and work with Django 2?

From Django's documentation, all commands for Django 2 use python , not python3 . Should I assume they mean python3 ?

You should consider first installing pyenv in order to have multiple versions of python on your machine:

https://github.com/pyenv/pyenv

Then you should create a virtual environment with the specific Python version that you want to use and where you will install the requirements/packages that you need http://docs.python-guide.org/en/latest/dev/virtualenvs/

The recommended way to run Django is inside a virtual environment. There are instructions to install Django in a virtual environment in the Django girls tutorial . Once you have activated your Python 3 virtual environment, you can use python to access your virtual environment's Python 3.

If you don't use a virtual environment, then you should use python3 in your commands.

best option for you is to work with a virtualenv, see this article if you are using windows http://timmyreilly.azurewebsites.net/python-pip-virtualenv-installation-on-windows/

your problem is that your operating system needs python2.7 to run, so it is the standard python unless you chage that manually. If you want to avoid, a lot of problems, use irtualenv it is a safe way to work, and you can easily transport your work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM