Loading video player…

Setting Up the Environment

00:00 Now that you understand what command-line applications are and the tools you need to build your own, it’s time to get started. You can work with any code editor of choice.

00:09 I will be using Visual Studio Code, also known as VS Code for the rest of this course. To get started, you can create your CLI application’s project folder in any location of choice on your machine.

00:21 I’ll be creating mine on my desktop and calling it rptodo_project.

00:28 And once you’ve created your main project directory, it’s time to open that directory in Visual Studio Code or your code editor of choice.

00:37 Great. It’s time to get started. For development, it’s always a great idea to work in virtual environments. These are isolated environments that allow you to install project-specific dependencies that won’t interfere with your global system installations.

00:53 And to work with virtual environments and Python, you can work with Python’s built-in venv module to create virtual environments. If you are on Linux or macOS, in your terminal, you can run python3 -m venv ./venv.

01:12 You should see a directory called venv now in your project directory. To activate this virtual environment, if you are on Linux or macOS, you can run source venv /bin/activate. Running this should activate the virtual environment and you should see an indicator in your terminal.

01:33 In my case, now I see (venv) in parentheses.

01:39 If you are in a Windows environment, this is a command to run to activate your virtual environment. You’d start with python -m venv and then the name of the environment, venv, to create the virtual environment called venv.

01:55 And then to activate `venv\Scripts` activate.bat. To confirm that you are indeed in your virtual environment, in your terminal, you can type which python3 to see what Python interpreter is going to be used when you execute programs with this virtual environment activated.

02:17 And you should see the path to the Python 3 interpreter in your created virtual environment. Now with this virtual environment activated, whatever package installation or program execution you’re going to run is going to happen from your isolated virtual environment.

02:32 Now that you have your virtual environment set up, let’s look at the dependencies you’re going to need to build your CLI application with Typer.

02:41 Typer is the main dependency needed for this project. And to install it in your terminal, you’d run the following command: python -m pip install typer==0 .13.0. With Python virtual environments, to keep track of installed dependencies, you can store them in a file called requirements.txt.

03:03 And to do that, you’ll run the command python -m pip freeze > requirements.txt. This will write out the installed dependencies into the requirements.txt file.

03:18 Now to do that in your terminal, first confirm your virtual environment is activated to avoid installing the dependencies in your global environment. Then you can type python3 -m pip install typer== 0.13.0.

03:40 This should install Typer as a dependency in your isolated virtual environment and along with Typer, all the needed sub-dependencies will get installed.

03:51 Now to capture all the installed dependencies into a requirements.txt file, in your terminal run python3 -m pip freeze > requirements.txt.

04:07 This will create a requirements.txt file and in there write all the dependencies and sub-dependencies needed to build a Typer CLI application.

04:16 To confirm this, in your virtual environment, you could run python3 -m pip list. You would see that you now have all the dependencies and sub-dependencies installed in your virtual environment.

04:32 Now your development environment is fully ready to start working with Typer.

Become a Member to join the conversation.