Setting Up Your AI and Machine Learning Environment: Python, Conda/venv, VS Code, Jupyter, and Git

Welcome to the first official post on this blog! If you are stepping into the fascinating world of Artificial Intelligence (AI) and Machine Learning (ML), you are embarking on an incredible journey. However, before we can train deep neural networks or deploy predictive models, we must lay a rock-solid foundation.

In the realm of software engineering and academic research, reproducibility is paramount. The “it works on my machine” phenomenon is a common pitfall. To avoid this, we need a standardized, isolated, and highly functional development environment.

In this comprehensive guide, we will walk step-by-step through setting up a professional-grade ML environment using Python, Conda (or venv), Visual Studio Code (VS Code), Jupyter Notebooks, and Git.


Step 1: The Foundation – Python and Virtual Environments

Python is the undisputed lingua franca of AI and Machine Learning. However, simply installing Python globally on your operating system is considered bad practice. As you work on different projects, you will inevitably require different versions of libraries (e.g., Project A needs TensorFlow 2.10, while Project B requires PyTorch 2.0).

To solve this dependency hell, we use Virtual Environments. There are two main contenders in the Python ecosystem:

  1. venv (with pip): The built-in Python module. It is lightweight and excellent for standard web development or scripting.
  2. Conda: A cross-platform package and environment manager. For Data Science and ML, Conda is highly recommended. It handles complex, non-Python dependencies (like C++ binaries for NumPy, or CUDA toolkits for GPU acceleration) far more gracefully than pip.

Anaconda is a popular distribution, but it is bloated with hundreds of pre-installed packages you may never use. Instead, we will install Miniconda—a minimal, lightweight version.

  1. Navigate to the official Miniconda download page.
  2. Download the installer specific to your operating system (Windows, macOS, or Linux).
  3. Run the installer. (For Windows users, it is highly recommended to check the box that says “Add Miniconda3 to my PATH environment variable” or use the Anaconda Prompt provided).
  4. Verify the installation by opening your terminal or command prompt and running:
    conda --version
    

Step 2: Creating Your First ML Environment

Now that Conda is installed, let’s create a dedicated, isolated environment for your machine learning projects.

  1. Create the environment: In your terminal, run the following command. We will name our environment ml-env and specify Python 3.10 (a highly stable version for most current ML frameworks).
    conda create --name ml-env python=3.10 -y
    

    (The -y flag automatically says “yes” to installing base dependencies).

  2. Activate the environment:
    conda activate ml-env
    

    You should now see (ml-env) prepended to your terminal prompt.

  3. Install essential ML libraries: Now, let’s populate our environment with the fundamental tools of data science:
    conda install numpy pandas matplotlib scikit-learn -y
    

(Note: If you strongly prefer venv, you can achieve a similar setup by running python -m venv ml-env followed by source ml-env/bin/activate on Mac/Linux or ml-env\Scripts\activate on Windows, and then using pip install).


Step 3: Setting Up the Ultimate Editor – VS Code

While you can write Python in a simple text editor, an Integrated Development Environment (IDE) boosts productivity exponentially. Visual Studio Code (VS Code) is currently the most popular, extensible, and lightweight IDE for Python developers.

  1. Download and Install: Visit the VS Code website and download the appropriate version for your OS.
  2. Install Essential Extensions: Open VS Code. On the left-hand sidebar, click the “Extensions” icon (four squares). Search for and install the following:
    • Python (by Microsoft): Provides syntax highlighting, IntelliSense (code completion), and debugging.
    • Jupyter (by Microsoft): Allows you to run and edit Jupyter Notebooks directly inside VS Code.
    • Pylance: Provides highly performant, type-rich language support.
  3. Link VS Code to your Conda Environment:
    • Open the Command Palette in VS Code (Ctrl+Shift+P on Windows/Linux, Cmd+Shift+P on macOS).
    • Type Python: Select Interpreter and hit Enter.
    • Select the interpreter that corresponds to your Conda environment (it should look something like Python 3.10.x ('ml-env': conda)).

Step 4: Jupyter Notebooks – The Researcher’s Canvas

Machine Learning is an iterative, experimental process. You need to visualize data, run small blocks of code, and inspect outputs dynamically. Jupyter Notebooks (.ipynb files) are the industry standard for this workflow.

Since you installed the Jupyter extension in VS Code, setting it up is incredibly seamless.

  1. First, ensure the Jupyter kernel is installed in your Conda environment. (Keep your terminal open with (ml-env) activated):
    conda install ipykernel -y
    
  2. In VS Code, create a new file and name it test.ipynb.
  3. Open the file. In the top right corner of the VS Code interface, click on “Select Kernel” (or it might display the current Python version).
  4. Choose Jupyter Kernel -> Python Environments, and select your ml-env Conda environment.
  5. Type print("Hello, Machine Learning!") in the first cell and press Shift + Enter to run it. If it prints successfully, your Jupyter setup is complete!

Step 5: Version Control with Git

As you build models, you will write hundreds of scripts, tweak hyperparameters, and refactor code. How do you keep track of all these changes without naming your files model_final_v2_really_final.py? The answer is Git.

Git is a version control system that tracks changes to your files over time, allowing you to revert back to previous states and collaborate with others seamlessly (usually via platforms like GitHub).

  1. Install Git:
    • Windows: Download from git-scm.com.
    • macOS: Open terminal and run git --version (this will prompt an installation if you don’t have it).
    • Linux: Run sudo apt-get install git.
  2. Configure Git: Open your terminal and set your global identity. This information will be attached to every “commit” (save point) you make.
    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
    
  3. Initialize a Repository: Navigate to your project folder in the terminal and run:
    git init
    

    (Pro Tip: Always create a .gitignore file in your project directory to prevent uploading unnecessary files—like virtual environments, .DS_Store on Macs, or large datasets—to your GitHub repository. You can generate one automatically using sites like gitignore.io.)


Conclusion

Congratulations! You have successfully configured a professional, robust, and reproducible development environment. You now have the power of isolated Python environments via Conda, the sleek editing capabilities of VS Code, the interactive experimentation of Jupyter, and the historical tracking of Git.

With this infrastructure in place, you are perfectly positioned to dive deep into the algorithms and mathematics of Artificial Intelligence. In our next post, we will start getting our hands dirty with data manipulation using NumPy and Pandas.

Stay tuned, and happy coding!




Enjoy Reading This Article?

Here are some more articles you might like to read next: