Software
Overview
Setting up our development environment correctly is vital for smooth and successful coding. In this stage, we'll go through all the necessary installations and configurations.
Installing Python
Before getting started with Griptape, you'll need to install Python. We currently recommend a Python version greater than 3.9.
Windows or Linux
- Head over to the official Python downloads page
- Click on the button that says "Python 3.12.x" (or the most recent 3.12 version) to download the installer
- Run the installer, and make sure to check the box that says "Add Python to environment variables" before you click "Install"
macOS
If you have Homebrew installed:
- Open your terminal
- Run the command
brew install python@3.12
- After the installation is complete, run
brew link python@3.12
Info
If you don't have Homebrew, you can install Python from the official website as mentioned above.
You did it!
Congratulations, you've got Python!
Visual Studio Code
Installing
Visual Studio Code (VS Code) provides the perfect environment for our Python coding.
- Go to the VS Code download page
- Download the version appropriate for your OS (Windows, Linux, or macOS)
- Run the installer and follow the prompts
Success
VS Code is now installed!
Creating the Project Folder
Before we dive into coding, let's create a dedicated space for our project. Having a clean organized directory structure makes coding and managing your projects much easier.
First, you'll want to create a new folder on your computer where all the code for this project will live. You can create this folder anywhere you like. Here's how you can do it via your Terminal:
This creates a new folder called "griptape-starter" and moves into it.
Alternatively, feel free to open up Visual Studio Code and create a new folder:
- Choose File -> Open Folder..
- Choose New Folder
- Enter the name of your new folder. Example:
griptape-starter
- Choose Create
- Double-click on the newly created folder to open it.
Python
Installing VS Code Python Extension
The Python extension for Visual Studio Code provides rich support for the Python language, including features like IntelliSense, linting, debugging, code formatting, and more. It really makes life easier for Python developers.
- With VS Code open, go to the Extensions tab, or choose View --> Extensions
- Search for
Python
, or go to Python in your web browser. - Choose
Install
. - Open the command Palette (
Ctrl
+Shift
+P
on Windows/Linux,Cmd
+Shift
+P
on macOS), or choose View --> Command Palette.. - Type
Python
and you should see a list of specific commands for Python. This will confirm that the install was successful.
Virtual Environments
Using VS Code's Python Environment Manager
Python virtual environments are essential tools for keeping your projects organized and isolated. They allow each project to have its own set of dependencies, ensuring that different projects won't interfere with each other, which is vital when different projects require different versions of the same library. By using virtual environments, you can maintain a clean, conflict-free workspace for each project, making it easier to manage your code and troubleshoot any issues.
Many developers use their terminal to manage their Python virtual environments. As this is a beginner level course, we'll use an Extension inside VS Code instead because it makes this a little bit easier.
- With VS Code open, go to the Extensions tab, or choose View --> Extensions
- Search for
Python Environment Manager
, or go to Python Environment Manager in your web browser. - Choose
Install
. - Open the Command Palette (
Ctrl
+Shift
+P
on Windows/Linux,Cmd
+Shift
+P
on macOS), or choose View --> Command Palette.. -
Search for
Python: Create Environment
and you should see it come up at the top of the command list. -
Hit return with that item selected and choose
.Venv: Creates a '.venv' virtual environment in the current workspace
- Then choose a python version.
Note: This will create the virtual environment for you within the current directory.
- This creates a new virtual environment in a folder called
.venv
and activates the environment for you.
Now you've set up your Python environment for this project. This way, anything you install or change in Python won't affect other projects.
Confirm it's working
To be sure that your virtual environment is set up correctly, we'll check by opening a Terminal. If everything is set correctly, you'll see .venv
in your terminal prompt.
- Open the terminal in VS Code by clicking on
Terminal -> New Terminal
Note
You should see .venv
in your prompt. If you don't see it, please run through the previous documentation to try again, or check out the TroubleShooting section of this tutorial.
Troubleshooting
Execution Policy
On some Windows systems, you may get an error that says something similar to:
Failure
.venv\Scripts\Activate.ps1 cannot be loaded because running scripts is disabled on this system.
This is due to an execution policy. Don't worry, it's pretty easy to resolve.
- With the Terminal open, execute the following command:
-
This will give the current user the ability to run scripts from within Visual Studio Code.
-
Verify this worked by closing the Terminal and re-opening it. You should be able to execute scripts now without any errors.
Info
You can learn more about Windows Execution Policies in the Set-ExecutionPolicy documentation.
Next Step
You now have Python and VS Code installed, and you've got a working virtual environment! In the next section, we'll set up your OpenAI API key so you can communicate with their large language model.