miércoles, 18 de septiembre de 2024

Python Virtual Environment

Step 1: Install Python

First, ensure you have Python installed. You can check by running:

python3 --version

If it's not installed, you can install it using:
sudo apt update sudo apt install python3 python3-venv python3-pip

Step 2: Create a Project Directory

Navigate to your desired project directory (or create a new one):

mkdir my_project cd my_project

Step 3: Create a Virtual Environment

Create a virtual environment named myenv (you can choose a different name if you prefer):

python3 -m venv myenv

Step 4: Activate the Virtual Environment

Activate the virtual environment with:

source myenv/bin/activate

You should see the environment name in your terminal prompt, indicating that it’s active.

Step 5: Install Packages

Install any packages you need using pip. For example:

pip install requests flask

Step 6: Generate a Requirements File

To create a requirements.txt file that lists all installed packages and their versions, run:

pip freeze > requirements.txt

Step 7: List Installed Packages

To see all installed packages in the virtual environment, use:

pip list

Step 8: Deactivate the Virtual Environment

When you're done working in the virtual environment, deactivate it by running:

deactivate


No hay comentarios:

Publicar un comentario