Python is one of the most popular programming languages used for web application development, data science, artificial intelligence, and system automation. To start programming with Python on Ubuntu, we need to set up a development environment that simplifies coding, testing, and package management. This article will walk you through setting up Python, virtual environments, the Visual Studio Code editor, and a simple test by creating your first Python application.
1. Install Python
By default, Python is already installed on Linux distributions, including Ubuntu. What you need to install are pip (Python package manager) and virtualenv (virtual environment):
sudo apt install python3 python3-pip python3-dev virtualenv -yCheck the installed versions of Python and pip to verify the installation:
python3 --version
pip3 --version
virtualenv --version2. Install Git
Git is a version control system that is essential for developers to track code changes, collaborate in teams, and synchronize with online repositories (such as GitHub or GitLab).
Install Git:
sudo apt install git -yCheck the Git version:
git --versionInitial Git configuration, add your global identity:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"3. Install Visual Studio Code
Visual Studio Code (VS Code) is a popular editor for application development, supporting various programming languages including Python.
Download the VS Code .deb package:
wget 'https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64' -O code.debInstall the VS Code .deb package:
sudo dpkg -i code.deb
sudo apt install -fVS Code supports extensions, which are plugins to enhance functionality for application development. Launch VS Code and install several Python-related extensions. Extensions can be accessed via the sidebar → click the Extensions icon (Ctrl+Shift+X) → search for the extension name.
- Python, provides linting, debugging, and IntelliSense.
- Pylance, enhances IntelliSense performance and accuracy.
- Black Formatter or autopep8, to maintain consistent code style.
Extensions for Git:
- GitLens, simplifies viewing commit history, blame, and code contributions.
- GitHub Pull Requests, enables direct integration with GitHub.
4. Test a Python Application
Create a directory to store your Python project:
mkdir myproject
cd myprojectCreate a virtual environment named venv and activate it:
python3 -m venv venv
source venv/bin/activateIf using Fish shell, activate it with:
source venv/bin/activate.fishIf successful, the terminal will display (venv) before the prompt:
(venv) user@hostname:~/myproject$Open the myproject directory in VS Code:
code .Create an app.py file to verify that the environment is working correctly:
# app.py
def main():
print("Hello, Python on Ubuntu is ready to use!")
print("Let’s start coding with Python")
if __name__ == "__main__":
main()Run the program:
python3 app.pyOutput:
Hello, Python on Ubuntu is ready to use!
Let’s start coding with PythonInitialize a repository in the project:
git init
git add .
git commit -m "Initialize first Python project"After following the steps above, you now have a complete Python development environment on Ubuntu: starting from the Python interpreter, pip, virtual environment, Visual Studio Code with popular extensions, to Git integration for version control. This setup will greatly support your development workflow, whether working individually or in a team, for small projects to large-scale applications.




