Making and Running a Simple Python Script
Travis Stephens
11/15/20267 min read
A Python script can be as little as a single Python file (.py) inside of a directory, however this ultra simplified structure doesn’t allow much room for expansion of the project, is terribly inefficient for larger projects, and worst of all, may clutter up your global Python installation to the point that you run into incompatibility issues when trying to run Python programs or scripts.
In order to keep things simple and clean, this article is going to show a stripped-down bare minimums version of a larger project structure. If you’re brand new to Python or you’re looking for something to just get you up and going with the most basics of scripts, this is a good place to start. In a later article I’ll go over what to add to this project structure to grow the project and/or make an importable Python Package.
The following set of instructions assume that you already have Python and Visual Studio (VS) Code installed either directly inside of the Windows operating environment or Ubuntu through WSL2. See “Setting up Python with Visual Studio Code for Engineering Analysis” to install Python and Visual Studio Code if you have not done so already. Once Python and VS Code have been installed, you are ready to proceed with the following steps. If you are working inside of the Windows Environment exclusively (most likely work setup), then just follow the instructions for “Configuration 1: Windows PowerShell.” Follow Configuration 2 if you are using Ubuntu through WSL2. These commands may also work on other Linux distributions and macOS, but installation and configuration steps may differ.
1. Create the Project Directory
The first thing we need to do is make a root directory to store our Python Project/Script file inside of. You could just put your file inside of any directory, but if there is other stuff inside of that directory, you are effectively making it part of your Python project. It’s therefore best for each of your Python Projects/Scripts to have their own folder.
Configuration 1: Windows PowerShell
Create a new folder using the Windows File Explorer the same as you would any other folder. Then, open that folder, right click inside of it, and select “Open in Terminal”


Type:
code .
and Visual Studio Code will open with the project folder loaded after you hit enter.


Note: “Add to PATH” had to been selected during VS code installation (see “Setting up Python with Visual Studio Code for Engineering Analysis”) for the “code .” command to work. If this wasn’t completed it can be added by:
Press the Win key + s
Search “Edit environment variables for your account”
Under “User variables…” select “Path” and then click the “Edit” button
Click the “New” button and then enter: “C:\Users\YOUR_USERNAME\AppData\Local\Programs\Microsoft VS Code\bin” exist.
Click “Ok” on all open Windows and then restart your terminal.
Configuration 2: Ubuntu (WSL2)
Create a Project Folder:
mkdir myProject
Note: When using WSL2, it is recommended to keep active development projects inside the Ubuntu filesystem rather than under /mnt/c. This generally provides better file access performance.
Once the directory has been created, open it in Visual Studio Code.
cd myProject
code .
Verify that VS Code indicates WSL: Ubuntu in the lower-left corner. This confirms that you are connected to Ubuntu rather than working directly in Windows. You may see a message about "Installing VS Code Server". VS Code is installing a small server on the Linux side that the desktop VS Code will then talk to. That server will then install and host extensions in WSL, so that they run in the context of the tools and frameworks installed in WSL. In other words, your language extensions will run against the tools and frameworks installed in WSL, not against what is installed on the Windows side.
2. Create Project Subdirectories
Inside of Visual Studio Code, select “Terminal” and then “New Terminal”


In the terminal window enter the following commands:
Configuration 1: Windows PowerShell
mkdir src
mkdir src\ProjectPackage
Configuration 2: Ubuntu (WSL2)
mkdir -p src/ProjectPackage
The directory structure now looks like this:


Take note here that “src” is a typical name to use for your source code directory but “ProjectPackage” is a generic name. Use whatever name you want your “ProjectPackage” to be called for the “ProjectPackage” folder.
3. Create and Activate Python Virtual Environment (.venv)
A virtual environment provides an isolated Python environment for an individual project. This is important because different projects may require different Python packages or even different versions of the same package. For example, one application might require NumPy version 1.x, while another requires NumPy version 2.x. Virtual environments allow both projects to maintain their own dependencies without interfering with each other.
Another thing to note is by installing packages in the virtual environment, it keeps the global Python installation clean. Anytime you install a package it is a good idea to be inside of a virtual environment. This includes creating a virtual environment to work or run projects from other people.
The virtual environment is created using python’s “venv” tool. Use the following commands to make the virtual environment inside of your project.
Configuration 1: Windows PowerShell
python -m venv .venv
Configuration 2: Ubuntu (WSL2)
python3 -m venv .venv
If Ubuntu reports that the venv module is missing, install it first:
sudo apt update
sudo apt install python3-venv
After running the venv command, the .venv directory will appear and contain the Python interpreter and supporting files for the virtual environment. The environment is ready to use immediately after creation. However, it is generally easiest to activate it before installing packages or running scripts. Activation modifies the terminal's environment so that commands such as python and pip use the project's virtual environment rather than the system-wide Python installation. You generally should not modify the contents of the .venv directory manually.


Activate the Virtual Environment
Enter the following commands to active the project’s virtual environment:
Configuration 1: Windows PowerShell
.\.venv\Scripts\Activate.ps1
If PowerShell blocks the activation script because of its execution policy, you can allow scripts for the current terminal session with:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Then run the activation command again.

Configuration 2: Ubuntu (WSL2)
source .venv/bin/activate

Once activated, you should see (.venv) at the beginning of your terminal prompt. This indicates that the virtual environment is active.
You can deactivate it at any time using:
deactivate
Important: You will need to activate the virtual environment whenever you open a new terminal to work on the project. Activate it using the same commands as shown above. Do not run venv again if the folder (environment) already exists.
4. Select the Python Interpreter
Now that the project's virtual environment has been created, Visual Studio Code needs to be set to use it. VS Code uses the selected Python interpreter when running Python files, debugging, and providing features such as code completion. Although VS Code can often automatically detect the project's virtual environment, it's a good idea to verify that the correct interpreter is selected
To select the project's virtual environment:
In Visual Studio Code, press Ctrl + Shift + P to open the Command Palette.
Type ‘Python: Select Interpreter’ and select that command.
Find and select the Python interpreter located inside the project's .venv directory.



The interpreter will be located in one of the following locations, depending on your operating environment:
Configuration 1: Windows PowerShell
.venv\Scripts\python.exe
Configuration 2: Ubuntu (WSL2)
.venv/bin/python
Once selected, VS Code will use this interpreter for the project. When opening a new terminal, VS Code will generally activate the selected virtual environment automatically.
Note: If you already have a terminal open, you may need to close it and open a new terminal for the environment to activate automatically. You should see (.venv) at the beginning of the terminal prompt.
You can verify that the correct Python interpreter is being used by entering the following command:
Configuration 1: Windows PowerShell
python -c "import sys; print(sys.executable)"
Configuration 2: Ubuntu (WSL2)
python3 -c "import sys; print(sys.executable)"
The resulting path should point to the Python interpreter inside your project's .venv directory.
5. Create and Runing Python Files
At this point you have everything you need to start making and running basic Python Script Files. All script files should be kept inside of the “ProjectPackage“ folder (with the exception of test script files which will be discussed more in a later article).
To make a Python file in the “ProjectPackage” folder, run the following commands:
Configuration 1: Windows PowerShell
ni "src\ProjectPackage\FileName.py"
Configuration 2: Ubuntu (WSL2)
touch src/ProjectPackage/FileName.py
You can also make a new file by right-clicking “ProjectPackage” and selecting “New File” Inside of the VS Code Explorer tree, or selecting inside of the “ProjectPackage” folder and clicking the “New File” button icon.
Once the file has be created, click on it in the VS Code explorer tree to edit the file. The following is what the simplest of scripts could look like.






After you are finished editing the file, save it by going to “File” à “Save” or holding down the ‘Ctrl’ key and then hitting the ‘s’ key. You can also do “File” à “Save All” (Ctrl + k s) which saves everything currently open inside of the editor.


After the file has been saved, it is ran using the terminal.
Configuration 1: Windows PowerShell
python “src\ProjectPackage\FileName.py”

Configuration 2: Ubuntu (WSL2)
python3 src/ProjectPackage/FileName.py

Insights
Delivering FAA compliant solutions and taking your team to the next level.
CONTACT
For Services Inquiries
higheraviation@gmail.com
618-713-7890
© 2025 Benny Aero LLC. All rights reserved.
