Step-by-Step Guide
- Update the Package Index
Open a terminal and update the package index to ensure you have the latest information about available packages:
sudo apt update
- Install Python
Debian typically comes with Python pre-installed. However, you can install the latest versions of Python using theapt
package manager:
sudo apt install python3 python3-pip
This command installs Python 3 and pip
, the Python package installer.
- Verify Python Installation
Check the Python version to ensure it is installed correctly:
python3 --version
You should see the Python version information displayed.
- Verify pip Installation
Check thepip
version to ensure it is installed correctly:
pip3 --version
You should see the pip
version information displayed.
- Install Virtualenv (Optional)
It’s a good practice to use virtual environments for your Python projects. Installvirtualenv
usingpip
:
sudo pip3 install virtualenv
- Create a Virtual Environment (Optional)
Create a new virtual environment for your project:
virtualenv venv
Activate the virtual environment:
source venv/bin/activate
Your command prompt should change to indicate that the virtual environment is active.
- Install Packages with pip
You can now install Python packages within your virtual environment usingpip
. For example, to install Flask, a popular web framework, use:
pip install flask
- Deactivate the Virtual Environment
When you are done working in the virtual environment, deactivate it:
deactivate
- Create a Simple Python Script
To test your Python installation, create a simple Python script:
nano hello.py
Add the following code to the file:
print("Hello, World!")
Save and close the file.
- Run the Python Script
Execute the script to ensure Python is working correctly:bash python3 hello.py