-
Download the Installer:
- Go to the official Python website: python.org.
- Navigate to the "Downloads" tab and click on "Python 3.x.x" (where "x.x" is the latest version number).
-
Run the Installer:
- Once the installer is downloaded, run it.
- Make sure to check the box that says "Add Python 3.x to PATH" before clicking "Install Now".
-
Verify Installation:
- Open Command Prompt by pressing
Win + R, typingcmd, and pressingEnter. - Type
python --versionand pressEnterto verify the installation.
- Open Command Prompt by pressing
-
Update Package List:
- Open a terminal and run:
sudo apt update
- Open a terminal and run:
-
Install Python:
- Run the following command to install Python 3:
sudo apt install python3
- Run the following command to install Python 3:
-
Verify Installation:
- Type
python3 --versionin the terminal to verify the installation.
- Type
-
Install Homebrew (if not already installed):
- Open a terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Open a terminal and run:
-
Install Python:
- Once Homebrew is installed, run:
brew install python
- Once Homebrew is installed, run:
-
Verify Installation:
- Type
python3 --versionin the terminal to verify the installation.
- Type
A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated environments for them. This is particularly useful when you have projects that rely on different versions of the same package.
- On Windows, you can use Command Prompt or PowerShell.
- On macOS and Linux, you can use Terminal.
Navigate to the directory where you want to create your project and create a new directory for it.
mkdir my_project
cd my_projectUse the venv module to create a virtual environment. Replace myenv with the name you want for your virtual environment.
python -m venv myenvOn Windows:
myenv\Scripts\activateOn macOS and Linux:
source myenv/bin/activateOnce activated, your terminal prompt should change to show the name of the virtual environment. For example:
(myenv) user@hostname:~/my_project$You can now install packages using pip without affecting the global Python installation.
pip install <package_name>When you're done working in the virtual environment, you can deactivate it by simply running:
deactivate