How to Setup a Data Science Project - Creating a virtual environment
Deborah Agboola
Posted on March 25, 2021
As a data scientist, or a software engineer, or whatever you are doing, you have to ensure that your code is clean, reusable, and iterable upon.
There are certain basic rituals you do as a data scientist before start working on your project. That is setting up the environment in which you will work on.
As you work on projects, you have to be careful not to install the packages you need for your project directly on your system. It is strongly advised even as you work with other people.
You should have a virtual environment for each project you want to work on.
Why? This is because of the dependencies your project will need. You don't want confusion concerning the packages your application will need. When you create a virtual environment and install the necessary packages that your project will need, the package names are listed in your requirements.txt file so that when your teammate needs to work on that project with you, s/he will be able to install only the packages and dependencies s/he needs for the project by typing this code below.
pip install -r requirements.txt
Setting Up Your Virtual Environment
Create the folder you want to use for the project
Open the command line terminal. copy the file path of the terminal and paste it into the command line.
Create a virtual environment using the code below
python -m venv name-of-virtual-environment
Activate the virtual environment
A folder will be created in your project folder. if you look into the folder, you will see a bunch of folders and files. copy the path of the folder and paste it into the command line
In that scripts folder, there is a file called activate.bat
we are going to run that file in order to activate the virtual environment
activate.bat
Now your virtual environment has been activated on your project folder, you can start installing the dependencies you will need.
Note:
If you use a Linux environment, since you will be working on the terminal, just do this code below
source name-of-environment/bin/activate
It's straightforward.
I hope you learnt something new.
Happy Coding!!! 🥳🎉
Posted on March 25, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.