Django | How to Start a Python Virtual Environment?

Roy Wang
RoyWannago
Published in
2 min readFeb 27, 2019
Picture source: LearnBATTA https://learnbatta.com/blog/how-to-install-python-virtualenv-19/

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 folder
  • mkdir: create a folder
  • django-664django-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 env
New 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.
Screenshot of establishing a virtual environment

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

  1. ★★★ LIKE IT: Applaud for 3 seconds! (5–10 claps)
  2. ★★★★ LOVE IT: Applaud for 5–10 seconds! (10–30 claps)
  3. ★★★★★ SUPER ENJOY IT: Applaud for 10–20 seconds! (30–100 claps) Leave a comment below or share the article with your friends!

喜歡這篇文章你可以

  1. ★★★ 喜歡:拍手 5~10 下!
  2. ★★★★很喜歡: 拍手 10~30 下,分享給你朋友!
  3. ★★★★★喜歡到不得了: 拍手 30~100 下,幫我留言或分享給朋友!

--

--

Roy Wang
RoyWannago

I’m a product designer and traveler who likes writing and photography.