[Django] Get started with Django -- Install python and virtualenv

Install python3 on MacOS:

brew install python3

Come alone with python3, there are also some other tools are installed as well, for examlpe: 'pip, setuptools'...

We need 'pip' to help us install virtualenv.

Why virtualenv?

Main reason is to resolve the libaraies conflict for different django project. So for each project, you should create new virtual env, and install libraries only for this project, NEVER globally!

Install:

pip3 install virtualenv

Before create a new virtual env, we need to check the python3 location:

which python3

And in my case, it is:

/usr/local/bin/python3

Create new virtual env:

virtualenv -p /usr/local/bin/python3 myFirstProject

Go to the env folder we just create and start working on this env:

cd myFirstProject
. bin/activate

Now we are in the virtual env, we can start install django:

pip install django

To make sure and get familiar where those libraries are installed, we can go to:

ls lib/python3.6/site-packages

And you should be able to find django is there.

And also you can type:

python   // type paython

>>> import django   // import django lib
>>> django.VERSION // see the verison

(1, 10, 5, 'final', 0) // prints out


Other way to create new env with >python3.3 only:

python3 -m venv demo

Deactive you env:

deactivate

List all the libararies:

pip list
原文地址:https://www.cnblogs.com/Answer1215/p/6481974.html