Django | How to Start a Python Virtual Environment?
Before developing the Django project, we would like to set up a proper environment first. We don’t want to install Django globally!!! Due to the lots of different versions of Python and Django, using a virtual environment can help you establish a safe place to develop without messing up with other projects you are developing with another version.
1. Create a project folder
$ cd desktop
desktop $ mkdir django-664
cd
: move to another level of the foldermkdir
: create a folderdjango-664
django-664: folder name
The folder structure will be:
— <project folder> — <env>
2. Create a virtualenv folder
- Use
$ virtualenv env
desktop $ cd django-664
django-664 $ virtualenv envNew python executable in /Users/RoyWang/Desktop/django-664/env/bin/python2.7
Also creating executable in /Users/RoyWang/Desktop/django-664/env/bin/python
Installing setuptools, pip, wheel…
done.
You will see a folder named “env” is created within folder “django-664”.
3. Activate the virtual environment
- move to the folder where env folder is at.
$ source env/bin/activate
4. How to check if you successfully establish the virtual environment
Use $ which python
- Before activate:
RoyWang django-664 $
RoyWang django-664 $ which python
/anaconda3/bin/python
- After activate:
(env) RoyWang django-664 $
(env) RoyWang django-664 $ which python
/Users/RoyWang/Desktop/django-664/env/bin/python
Then you can start to install requirements/dependencies!
Hi, I am Roy, a full-stack UX designer. My website: royfalinwang.com
If you find this article helpful, you can
- ★★★ LIKE IT: Applaud for 3 seconds! (5–10 claps)
- ★★★★ LOVE IT: Applaud for 5–10 seconds! (10–30 claps)
- ★★★★★ SUPER ENJOY IT: Applaud for 10–20 seconds! (30–100 claps) Leave a comment below or share the article with your friends!
喜歡這篇文章你可以
- ★★★ 喜歡:拍手 5~10 下!
- ★★★★很喜歡: 拍手 10~30 下,分享給你朋友!
- ★★★★★喜歡到不得了: 拍手 30~100 下,幫我留言或分享給朋友!