FlashKeepers

Python · Python

Python Virtual Environments and Pip

Creating and managing virtual environments and installing dependencies with pip, each explained with a short example.

30 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone
What is a Python virtual environment?
An isolated Python installation on your system that has its own set of installed packages and Python version, separate from the system Python.
Why should you use a virtual environment?
To avoid package version conflicts between projects. Each project can have different versions of the same package without interfering with each other.
What is pip?
Python's package installer. It downloads and installs Python packages from the Python Package Index (PyPI).
How do you create a virtual environment named 'myenv' using venv?
python -m venv myenv
How do you activate a virtual environment on macOS or Linux?
source myenv/bin/activate
How do you activate a virtual environment on Windows?
myenv\Scripts\activate
How do you deactivate a virtual environment?
deactivate
What is the difference between venv and virtualenv?
venv is Python's built-in module (Python 3.3+), while virtualenv is a third-party package that works on older Python versions and has more features.
How do you install a package called 'requests' using pip?
pip install requests
How do you list all packages installed in your virtual environment?
pip list
How do you create a requirements.txt file from your current environment?
pip freeze > requirements.txt
How do you install all packages listed in a requirements.txt file?
pip install -r requirements.txt
How do you upgrade an installed package to the latest version?
pip install --upgrade package_name
How do you uninstall a package?
pip uninstall package_name
How do you check the version of an installed package?
pip show package_name

15 more cards in the app