Lesson 35 of 55 · Python
Virtual Environments and pip
Duration: 20 minutes
Lesson 35 of 55 · Python
Duration: 20 minutes
bash\n# Create a virtual environment named .venv\npython -m venv .venv\n\n# Activate (Linux/macOS)\nsource .venv/bin/activate\n\n# Activate (Windows)\n.\\venv\\Scripts\\activate\n\n# Upgrade pip inside the env\npip install --upgrade pip\n\n# Install a library, e.g., requests\npip install requests\n\n# Freeze exact versions for reproducibility\npip freeze > requirements.txt\n\n\nWhenever you start work on the project, activate the environment first. Deactivate with the deactivate command or simply close the terminal.\n