๐ŸŽฌ
Data Science - Wintersemester 24/25
  • Welcome
  • Whatโ€™s Data Science and How Do I Do It?
    • ๐Ÿ“†Timeline
    • ๐Ÿดโ€โ˜ ๏ธR Overview
      • ๐Ÿ“ฉInstallation
      • ๐Ÿˆโ€โฌ›GitHub Setup
      • ๐Ÿฅ—DataCamp Courses
    • ๐ŸPython Overview
      • ๐Ÿ“ฉInstallation
      • ๐Ÿˆโ€โฌ›GitHub Setup
      • ๐Ÿ“ฆVirtual Environment Setup
      • ๐Ÿฅ—DataCamp Courses
  • Introduction to Your Project
    • About the Project Guide
    • What is this Project About?
  • Exploratory Data Analysis (EDA)
    • Getting started
    • Discovering the Data ๐Ÿ”Ž
      • Initial Exploration Tasks
      • Initial Data Visualization
    • Data Cleaning and Transformation
      • Cleaning the Crime Dataset๐Ÿ‘ฎ๐Ÿผ
      • Cleaning the Weather Dataset๐ŸŒฆ๏ธ
    • Data Visualization
      • Crime Rate Over Time
      • Crime Types
    • Grouping and Merging Data
    • Linear Regression
    • Impress us!
    • Internship Complete!
  • Advanced
    • Introduction
    • K-Means Clustering
      • The Clustering Model
      • Visualize the clusters
    • Impress us!
  • โœ…Exercise Checklist
  • Legal Disclaimer
Powered by GitBook
On this page
  • Verify your python installation
  • Set up a virtual environment
  1. Whatโ€™s Data Science and How Do I Do It?
  2. Python Overview

Virtual Environment Setup

PreviousGitHub SetupNextDataCamp Courses

Last updated 5 months ago

For the project we will use python virtual environments, this is a common practice for python projects.

Virtual environments are isolated environments with their own dependencies (packages).

Before proceeding make sure:

Verify your python installation

  1. Open the template (that you have cloned from GitHub) in VS Code.

  2. Open the terminal. (Ctrl+j or Cmd+j)

  3. Execute python --version

  4. If you get a response such as 3.13.0 or similar, you're good to go.

  5. If you get an error (e.g. python is not recognized as a ... command), this mainly happens on windows, if you're using macOS and this happens, contact a mentor:

    1. Make sure you have installed python and during the installation you check the box on "Add Python [version] to PATH":

    2. If you are sure that you have installed python but you are still encountering this issue, then find where python is installed on your system:

      1. Usually it is under:

        C:\Users\[Username]\AppData\Local\Programs\Python\Python[version]

      2. For example: C:\Users\Saman\AppData\Local\Programs\Python\Python313

      3. If it is not there:

        1. In VS Code, open the command pallete by hitting ctrl+shit+p.

        2. Type in: Python: Select Interpreter. You should now see at least one option, and a path next to it, like so:

        3. The path is then the path to your python installation.

    3. Now that you know the path to your python installation folder, hit the windows key, search 'environment', and open the 'Edit the system environment variables' page:

    4. Then select:

    5. Now, if you are the main and only user of your computer, take a look at the bottom section (under 'system variables'), otherwise look at the top section (under 'user variables for...').

    6. Find the entry named 'path' and double-click it, a new window should open:

    7. In this new window, click the 'New' button, a new empty entry will be added. Here paste the path to your python installation, it should look something like this: C:\Users\[Username]\AppData\Local\Programs\Python\Python[version]

    8. Click Okay on all windows until they are all closed.

    9. Close VS Code and open it again, then try running python --version in the terminal again.

    10. If this doesn't work, contact a mentor.

Set up a virtual environment

  1. With your project open in VS Code, if the project is open, its path should be displayed in the terminal and the project (folder) name should be displayed at the top of the window, for example:

  2. Now, execute python -m venv venv_name and replace venv_name with what you want your virtual envrionment to be called, lacrime_venv is good for example.

  3. This will create a folder in your project with the same name you just chose, this folder contains:

    1. A new, isolated python installation.

    2. All packages you install in the virtual environment.

    3. Some configuration files etc.

  4. Now we want to let your terminal know you want to use this virtual environment instead of the global python installed on your system. So that when installing packages, you only install them for the project, and not for the entire system. To achieve this, you must activate the virtual enviornment, this is done by running the activate script included in the venv folder.

    1. On windows run: [venv_name]\Scripts\activate (replace [venv_name] with what you named your virtual env). This will most likely cause an error, if so, see the next step.

    2. On mac run: source [venv_name]/bin/activate (replace [venv_name] with what you named your virtual env)

    3. [Only for windows] if the last step causes an error like ...cannot be loaded because the execution of scripts is disabled on this system. then:

      1. Hit the windows key and search 'powershell', there should be an option 'windows powershell', right-click it, and choose 'run as administrator'.

        1. A black or blue terminal should open, here execute Set-ExecutionPolicy RemoteSigned -Scope CurrentUser , Then you will be asked something similar to Yes[Y]/All[A]/No[N].. here type in A and hit enter.

        2. After this step, close VS Code and open it again and try step 4 again, if this still doesn't work, contact a mentor.

  5. Your terminal should look a bit different now, the venv name should show up before the command line:

  6. You can install packages in your venv (virtual environemnt), for pandas for example: pip install pandas

  7. Now we will let jupyter notebook know you want to run your notebooks using the python interpreter present in your virtual environment (which only uses the packages you install in it), to do this:

    1. Open the needed .ipynb (jupyter notebook) file, on the top right you should see a button with 'select kernel' or 'python 9.13.0' or something similar.

    2. Click on it, a little window will open on the top, then click 'python environments':

    3. you should then see a list of python interpreters available on your system, choose the one with the name of your venv on it, the button should now look like this:

    4. you should be good to go! Phew...๐Ÿ˜ฅ

๐Ÿ
๐Ÿ“ฆ