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:
Click Tools → Options
Select Interpreter → New virtual environment
Click Ok
Navigate to your project folder
Create a new folder called
venv
Select the
venv
folder
Wait for the process to finish then click Ok
Your shell should now identify the your new virtual environment as the interpreter.
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:
Click View → Files
Navigate to your project folder → right mouse click on your venv folder → Activate virtual environment
Your shell should now identify the your new virtual environment as the interpreter.
Deactivating virtual environments¶
To return to the normal Python interpreter:
Click Tools → Options
Choose Interpreter → Python executable dropdown
Select the \Thonny\python.exe option
Click OK