2 Project Setup and Installation
2.0.1 Learning Objectives
- Set up your development environment
- Create and activate a virtual environment
- Organize your project directory structure for a Python package
- Create your python packaging file and understand its sections
- Install your package in development mode and verify installation
- Set up your OpenAI API key for use in the project
2.0.2 IDE and Required Software
2.0.2.1 Choosing an IDE
Before we dive into building our AI agent, let’s take a moment to set up a comfortable and efficient development environment. The right tools will make our coding journey much more enjoyable and productive.
For this tutorial, we will use an Integrated Development Environment (IDE) to write and test our code. While any text editor could work, a proper IDE will provide helpful features like code completion, syntax highlighting, and debugging tools that make development much easier.
You can use any IDE you’re comfortable with, but here are some excellent options if you don’t have a preference:
VS Code is the popular free, open-source editor from Microsoft with excellent Python support and a rich extension ecosystem including AI coding assistants like Github Copilot and Cline.
windsurf and cursor are newer AI-powered IDEs. Cursor is forked from VSCode. Windsurf offers a VSCode plugin but also has its standalone editor.
2.0.2.2 Required Software
- Python 3.10 or newer
- Git for version control
2.0.3 Set up a virtual environment
Create a new project directory:
mkdir market-mind-agent-tutorial
cd market-mind-agent-tutorialIf you ran the quick start from the Introduction, you already have the repo cloned. You can follow along in that directory, or start fresh here to build from scratch.
Let’s proceed to create a virtual environment:
A virtual environment is an isolated Python environment that allows you to install packages for a specific project without affecting your system-wide Python installation. This isolation helps avoid dependency conflicts between different projects and makes your project more reproducible.
We will use UV, a more modern and extremely fast Python package and project manager, compared to other alternatives like pip, poetry, pyenv etc.
# Install UV if not already installed
curl -LsSf https://astral.sh/uv/install.sh | sh # for macOS/Linux
# On Windows: powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Create a virtual environment
uv venv
# Activate the virtual environment
source .venv/bin/activate # On Windows: .venv\Scripts\activateAfter activating the virtual environment, you can verify which Python interpreter you’re using and its version with:
which python # On Windows: where python
python --versionYou should see that Python is now being used from the .venv directory you just created, confirming you’re working in the new environment.
2.0.4 Create Basic Directory Structure
Now, let’s create our basic directory structure:
# Create the src directory and module subdirectories
mkdir -p src/common src/agent_from_scratch src/openai_agent_sdk src/cli
# Create __init__.py files to make the directories valid Python packages
touch src/__init__.py
touch src/common/__init__.py
touch src/agent_from_scratch/__init__.py
touch src/openai_agent_sdk/__init__.py
touch src/cli/__init__.py
# Create minimal CLI files so the entry points can be found
echo "def main():
print('MarketMind CLI - coming soon!')
if __name__ == '__main__':
main()" > src/cli/main.py2.0.5 Set up the Project Configuration File
Let’s create a basic pyproject.toml file to define our project structure and dependencies:
[project]
name = "market-mind-agent-tutorial"
version = "0.1.0"
authors = [
{name = "Agenteer"},
]
description = "A hands-on tutorial for building AI agents"
requires-python = ">=3.10"
dependencies = [
"openai>=1.0.0",
"yfinance",
"python-dotenv",
"click",
]
[project.scripts]
market-mind = "src.cli.main:main"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
# tells the build system to include the 'src' directory
[tool.hatch.build.targets.wheel]
packages = ["src"]This file tells Python:
- Project metadata: Name, version, description, etc.
- Dependencies: External packages our project needs. For example, here we will use:
openaipackage for calling the OpenAI modelsyfinancefor retrieving stock datapython-dotenvpackage for loading environment variablesclickpackage for command line arguments
- Entry points: Command-line scripts that will be available after installation, we specify them for our various Agent implementations, and they must point to actual Python modules that exist
- Build system configuration: Specifies how to build the package (we use
hatchling)
The file follows the PEP 621 standard for Python package metadata, making our project compatible with all modern Python packaging tools.
If you try to install your package without creating the proper directory structure or without the correct build configuration, you’ll get errors.
In our case, we added the [tool.hatch.build.targets.wheel] section with packages = ["src"], which explicitly tells the build system to include the src directory in the package.
When do we not need to do this?
- If you’re using a
srclayout, and you have a directory that matches your specified package name, in our case, it will besrc/market_mind_agent_tutorial - If you have a directory that matches your specified package name - in our case
market_mind_agent_tutorial- directly at the root of your project
Then the build system will be able to find them automatically and you don’t need to explicitly tell the build system to include it.
2.0.6 Install Your Package
Now you can install the package in development mode:
uv pip install -e .When you install a package in development mode (using the -e flag), you’re telling Python to use the code directly from your project directory rather than copying it to the Python site-packages directory. This means:
- Any changes you make to the code will immediately take effect without needing to reinstall the package
- The package will be available to import in Python just like any other installed package
- Command-line scripts defined in the package will be available in your environment
uv pip install -e .
When you run this command:
- The installation process reads your
pyproject.tomland uses the specified build backend (hatchling) - The build backend looks for the package structure defined in
pyproject.toml - It needs to find all the modules and entry points referenced in the configuration
- The build backend creates a package based on your configuration
- Dependencies listed in your
pyproject.tomlare installed - A special link is created in your Python environment pointing to your project directory (the
-eflag) - Entry points defined in
project.scriptsare installed as executable commands
The output shows all the packages being installed, including your own package and its dependencies.
After installing the package, you can verify that your package was installed correctly and the command-line scripts are available:
# List installed packages
uv pip list | grep market-mind
# Check that the command-line scripts are available
which market-mind # On Windows: where market-mind-sdk
# Try running the CLI commands
market-mind
# Should output: "MarketMind CLI - coming soon!"2.0.7 OpenAI API Key Setup
The MarketMind agent requires an OpenAI API key to function. You must complete this step before running the agent in later chapters.
If you do not have an OpenAI API key yet, follow the instructions at OpenAI API Key to get your API key.
Once you have your key, create a .env file in your project root directory (the market-mind-agent-tutorial folder):
# Create a .env file for your API key
echo "OPENAI_API_KEY=your_api_key_here" > .envMake sure to replace your_api_key_here with your actual OpenAI API key.
Never commit your .env file to version control. Add .env to your .gitignore file:
# Add .env to .gitignore (creates the file if it doesn't exist)
echo ".env" >> .gitignore2.0.8 Next Steps
Now that we’ve set up our project and understood what we’re building, we’re ready to dive into implementation. In the next chapter, we’ll start by building the financial tools that will form the foundation of our MarketMind agent.