PIP
pip
is the Package Installer for Python, allowing to easily manage libraries and dependencies for projects.
Installing a Package
To install a specific package, use the following command:
For example, to install requests
, run:
In some cases, a package can be installed directly from its Git repository using the following command:
For example, to install Flask directly from GitHub, run:
Installing Packages from a Requirements File
If you have a requirements.txt
file that lists the packages for your project, you can install all dependencies with:
This command will read the file and install all the packages specified.
Uninstalling a Package
To uninstall a specific package, use the following command:
For example, to uninstall requests
, run:
Uninstalling All Packages
To remove all installed packages in your environment, use:
This command will list all installed packages and uninstall them in a single operation.
Listing Installed Packages
To list all installed packages in your virtual environment, use:
This will display a list of all packages and their respective versions.
An alternative, more user-friendly version of this command is:
Managing Dependencies with requirements.txt
The requirements.txt
file is a standard way to list all the dependencies for your Python project.
It allows to easily share and install the exact versions of the packages needed for a project.
You can generate a requirements.txt
file using the following command:
This command will list all the installed packages and their versions in the current environment and save them to the requirements.txt
file.
To install all the dependencies listed in a requirements.txt
file, use:
This will automatically install the exact versions of the packages specified in the file, ensuring your environment is set up exactly as required.