DEV Community

ashrafZolkopli
ashrafZolkopli

Posted on

Create A Virtual Environment

Continue on from where we have left off, lets now start a virtual environment. If you are new with python, you might wonder why do we need a virtual environment. Short answer you don't actually. Long answer well since your PC/Laptop will not be used for only one project, sometimes when you make multiple project you might need to have packages or library that will conflict with another library that you are using on another project. So by having different isolated virtual environment, your project A will not have conflicting library with let say project B or so and so. Don't make the mistake I did way back when I started my python journey. Hahaha Boy what a honest newbie mistakes. Imagine how long it took my to figure that one out.... even StackOverFlow cant help me there...

Anyway lets now focus on creating a virtual enviroment.

for reference your terminal should look like this now....

VS Terminal

now with your cursor click inside the terminal enter the following command


pipenv shell

by the way, there are multiple virtual environment library that you can use. However I think for me the easiest one had been pipenv... My step by step guide is for pipenv. If you prefer or are using other packages please consult each packages manual, you're on your own. I can't help much with other packages.

once you have enter the pipenv shell command in your terminal and press enter, you will see this

VS Pipenv shell

if you notice the directory now is different

Pipenv Dir

the () indicates that you are currently inside the virtual environment. for window, the convention as been your filename-hash
on Mac/Linux its just your filename.

btw if you look at your explorer now you will see a new file call Pipfile. Always open your virtual environment where you see the Pipfile is located.

Ok now we have created a virtual environment. In the next post I will be going through how to install Django and also start a Django project.

Top comments (0)