Integrated Development Environments

We will be looking at two IDEs (Integrated Development Environments):

  • Visual Studio Code

  • Thonny

Visual Studio Code

Create virtual environment

To create a virtual environment in Visual Studio Code, you will need to open the Terminal Pane.

In the terminal type, ensure that you are in your folder directory (it’s in the prompt) then type:

Windows

python -m venv .venv

macOS

python3 -m venv .venv

This will create a virtual environment called .venv

Activate virtual environment

Once the virtual environment is created, it may need to be activated. When a virtual environment is activated, it’s name will be at the start of the prompt eg. (.venv).

To activated the virtual environment, enter the following at the terminal:

Windows

.venv/Scripts/Activate.ps1

The first time you run this command you may get an execution policy error.

Follow these instructions to resolve this problem.

macOS

source venv/bin/activate

Installing a package

In VSCode we use pip to install packages.

The example package we will install is PyQt6.

Windows

python -m pip install PyQt6

macOS

pip3 install PyQt6

Thonny

Create virtual environment

To create a virtual environment in Thonny:

  1. Click ToolsOptions

Thonny Venv 1

  1. Select InterpreterNew virtual environment

Thonny Venv 2

  1. Click Ok

  2. Navigate to your project folder

  3. Create a new folder called venv

  4. Select the venv folder

Thonny Venv 3

  1. Wait for the process to finish then click Ok

  2. Your shell should now identify the your new virtual environment as the interpreter.

Thonny venv 4

Activating virtual environment

If you prompt is not showing you virtual environment interpreter or you have the error below, you will need to activate you virtual environment.

To do this:

  1. Click ViewFiles

Thonny venv 6

  1. Navigate to your project folder → right mouse click on your venv folder → Activate virtual environment

Thonny venv 7

  1. Your shell should now identify the your new virtual environment as the interpreter.

Thonny venv 4

Deactivating virtual environments

To return to the normal Python interpreter:

  1. Click ToolsOptions

Thonny Venv 1

  1. Choose InterpreterPython executable dropdown

  2. Select the \Thonny\python.exe option

  3. Click OK

Thonny Venv 5