Creating a Python Project
To create a Python project and run a Python program, you must have Python installed on your computer. You may also find it beneficial to install a Python code editor, such as Visual Studio Code, to streamline project development. If you haven't already, I recommend following this guide for installation.
Follow the steps below to create and run a Python project:
- Open a terminal and create a folder with your project name using the command as shown in the example below:
- Launch the Visual Studio Code.
- Add your project folder to the Visual Studio Code Explorer: Go to File > Add Folder to Workspace and add the project folder into the IDE.
- After loading your project in the Visual Studio Code Explorer, right-click on the project folder. From the toolbar, select New File and enter a filename of your choice (e.g., main.py). A Python file has a .py extension.
- Inside the file, add your code. Here's a simple example that prints "Hello, World!" in the console:
- Next, to run the code, right-click on your file (e.g,. main.py) and from the toolbar options, select Run Python File in Terminal. In the IDE console, you will see the output as shown below:
You can also run a Python file from the command prompt or terminal. Simply navigate to the directory where your Python file is located and execute the command as shown in the example below:
cd my_project python your_file.py