A step-by-step guide on installing setting up VS Code, PowerShell, Python, Git, GitHub, and virtualenv. With pictures!
One of the roadblocks of learning data science or any programming, in general, is setting up the development environment on the local machine. So I’ve decided to buy a brand new computer to use solely for documenting the steps I took in setting up my development environment.
Today, we’ll be going through the steps of downloading, installing, and setting up some of the most common tools used in data science projects. We’ll be covering:
- Visual Studio Code
For today’s guide, we’ll be using a Lenovo laptop with the following specifications:
Processor: Intel i3–10110U CPU @ 2.10 GHz
Installed RAM: 8.00 GB
System Type: 64-bit OS
Operating System: Windows 10 Home
Without further ado, let’s get started.
Setting Up Visual Studio Code
Let’s open up a Google Chrome web browser window and go to https://code.visualstudio.com.
Click on the giant blue button to VS Code “Download for Windows.”
Proceed to download the installer in the “Downloads” folder.
After it’s downloading, double-click on the installer program.
Let’s accept the agreement and click “Next.”
Accept the defaults by clicking on the “Next” button several times.
Make sure the box to “Add to PATH …” is checked.
Optional, but I figured it’s beneficial to include the “Open with Code” actions to both Windows Explorer file and directory context menus.
Hit “Next” one more time and click on “Install.”
When the installer finishes installing, just click on “Finish.”
At this point, a VS Code window will open and presents us with an option to change the color theme.
I like the color blue, so I decided on the “Deep Blue” theme by Julian Kaindl.
After the changes take effect, let’s go ahead and close the “Get Started” and the Extensions page by clicking on the “x” and extensions icons.
Find the “Terminal” menu on the top of the application and select “New Terminal” as shown below.
We will be working a lot on the terminal in the future, so it’s handy to know the keyboard shortcut for this:
CTRL + Shift + `.
Every time we open a new PowerShell terminal, a little advert for PowerShell shows up, and it’s quite annoying. Let’s change it!
Type in the following at the Terminal prompt:
Notepad will then notify you that it cannot find the ps1 file. Click on “Yes” to create one.
A blank notepad file will pop up.
Copy and paste the following into the file:
cls tells the computer to clear the screen of the default prompt and
Write-Host 'XXX' displays XXX into a line on the screen. You can change the code above to suit your taste.
Set-location "XXX..." sets the default directory and
function prompt "XXX $(get-location)>" controls what the terminal prompt will look like.
Save the file.
The result is shown below.
Next on our itinerary is downloading and installing Python. Let’s head on over to https://python.org/downloads.
I don’t recommend downloading the latest build yet because I like to be conservative and opt for an earlier version that most packages support. Scrolling down the page, we’ll see our favorite, the 3.9.9 release version.
Click on “Download.”
Scroll down and click on “Windows Installer (64-bit).”
Save it in the “Downloads” folder.
And double-click on the installer program to start the installation.
Make sure you check “Add Python 3.9 to PATH” and click on “Customize Installation.”
Make sure all the boxes are checked before clicking on the “Next” button
Click on the “Install” button.
When it’s done installing, it might show you the option to “Disable path length limit,” click on it.
To verify that Python 3.9 was correctly installed, let’s fire up a new terminal on VS Code and type:
It should say “Python 3.9.9.”
I use a different virtual environment for each of my data science projects.
has a good explanation of “Why you should a virtual environment for EVERY python project!”
Let’s go back to our terminal and type the following:
pip install --user virtualenv
If it gives you a warning like below:
it means we need to add the directory to the PATH in our environment variables.
Let’s take note of the directory where virtualenv was installed.
Then, click on the start at the bottom-left area of your Windows desktop and click on the gear icon for “Settings.”
We will see a screen similar to the one below.
At the search box in the middle of the screen, type in “env” and click on the first dropdown option, “Edit environment variables for your account.”
On the next screen, click on “Edit…” as shown below.
Next, click on the “New” button.
Type in the directory where virtualenv was installed and click on the “OK” button.
Click “OK” one more time, and we’re golden!
Setting up Git & Github
Let’s head to https://git-scm.com/downloads and click on the green “Download for Windows” button.
Click on the “Click here to download” link to download the latest version of Git for Windows.
Save it on the “Downloads” folder.
Double-click the installer.
Click “Next” to accept the default installation location.
On the next screen, uncheck the two boxes underneath “Windows Explorer Integration.”
Then, click “Next” two more times.
Change the default editor by clicking on the dropdown arrow as shown below.
Select “Visual Studio Code as Git’s default editor” and click on “Next.”
Select the second option to set the default branch name to “main” instead of “master.”
Click on “Next” several more times.
And finally, click on the “Install” button to start the actual installation.
Once the install process finishes, ensure the “Launch Git Bash” is checked and click on “Finish.”
On the terminal window that launches (this is the Git Bash), type in:
git config --global -user.name "YOUR NAME HERE"
(Ensure you replace “YOUR NAME HERE” with your name.)
Next, type the following to set the email.
git config --global user.email "YOURNAME@EMAIL.COM"
(Similarly, replace “YOURNAME@EMAIL.COM” with your own.)
Next, we will generate a public/private key pair for SSH. On the terminal, type in:
ssh-keygen -t ed25519 -C "YOURNAME@EMAIL.COM"
Don’t forget to replace “YOURNAME@EMAIL.COM” with your name.
When asked for the file with which to save the key, just hit the
ENTER key to accept the default.
When asked for the password or passphrase, hit the
ENTER key twice.
It should then generate the random art image for the key, as shown below.
Next, we’re going to add the key to the ssh-agent. Type in:
eval "$(ssh-agent -s)"
It should say “Identity added….”
Next, we’re going to copy the key to the clipboard. Type in:
clip < ~/.ssh/id_ed25519.pub
For this next part, we need to go to Github’s settings.
Under the “Access” section, look for “SSH and GPG keys.”
We will see something like the one below. For the next step, click on the green “Run SSH key” button.
On the next screen that follows, let’s paste the contents of the clipboard (
CTRL+V) and then click on the green “Add SSH key” button at the bottom of the large text box.
At this point, we need to test if git was installed properly and also if our Github setup worked.
Let’s open a new windows explorer window and navigate where you usually store your code. Then, right-click somewhere and create a new folder for our test project.
For this time, let’s name it “test-github-setup.”
For the next part of the process, we will create a new repository on Github and grab the SSH information that is provided. So, head on to your Github repositories and click the green “New” button as shown below.
Let’s give it a name and add a description.
Scroll down, and click on the green “Create repository” button.
On the next page that appears, ensure that SSH is selected and click the copy icon on the right of the textbox.
Then, let’s switch to our terminal and type in the following:
git remote add origin PASTE_IN_THE_SSH_INFORMATION_HERE
Don’t forget to replace PASTE_IN_THE_SSH_INFORMATION_HERE with the information we copied in the previous step. It should be something like email@example.com:username/repository-name. git.
Let’s now switch to a Windows Explorer and navigate to the location of our local repository and confirm that nothing else exists on the folder except the .git folder.
Next, type in the following on the terminal:
git pull origin main
If you get a message that says, “The authenticity of host ‘github.com… can’t be established…” type in “yes” as a response.
You should then get a warning message like the one below.
To test our connection to the remote Github repo, let’s create a new text document in the folder as shown below.
Name it test.txt and switch to the terminal.
On the terminal, type in:
git push -u origin main
On your Github page, click the refresh icon on the browser, and let’s see what happens next!
Instead of the setup page, we now should see the “test.txt” document that we created on the local machine (repo).
Remember the Windows PowerShell Profile that we created earlier? Navigate to the
C:\Users\Dd\OneDrive\Documents\WindowsPowerShell folder, open
Microsoft.PowerShell_profile.ps1 and add the following to create some shortcut commands.
The code above sets some shortcut commands that replace long-winded ones. For example, instead of typing jupyter notebook (you have to pip install notebook first!), simply type
jn and you’re good to go!
Similarly, instead of typing
git init type in
gii instead. Here are the other git commands:
- gii: git init
- gss: git status
- gaa: git add .
- gcc COMMIT_MESSAGE: git commit -m COMMIT_MESSAGE
- grr SSH_INFO: git remote add origin SSH_INFO
- gpush: git push -u origin main
- gpull: git pull origin main
Because I’m really lazy, I’ve also added the following shortcut for pip installing some of the most often used packages related to data science:
- pipinit: pip install notebook numpy pandas scipy matplotlib sklearn seaborn scikit-learn
And finally, let’s not forget to ensure that setting up a virtual environment is also a breeze:
- vnv387: virtualenv v399 -p PATH_TO_PYTHON_387_EXE
- vnv399: virtualenv v399 -p PATH_TO_PYTHON_399_EXE
- vnv310: virtualenv v399 -p PATH_TO_PYTHON_310_EXE
- act387: .\v387\Scripts\activate
- act399: .\v399\Scripts\activate
- act310: .\v310\Scripts\activate
And that’s it! We’ve successfully set up our new machine for data science in Python.