![]() |
Managing dependencies becomes crucial to ensure smooth development and deployment processes. In this article, we will explore various methods for managing Python dependencies, from the basics of using How to Manage Dependencies in PythonBelow are some of the ways by which we can manage Python dependencies: Manage Python Dependencies Using PipPip is the package installer for Python, and it comes pre-installed with Python versions 3.4 and above. To check if you have it installed, run: pip --version
If not installed, you can install it using the following: python -m ensurepip --default-pip
Step 1: Install a PackageTo install a package, use the following command, Replace pip install package_name
pip install requests
Step 2: Managing PackagesTo list installed packages and their versions, To uninstall a package: pip list
pip uninstall package_name
Manage Python Dependencies Using VirtualenvVirtualenv is a tool to create isolated Python environments, preventing conflicts between project dependencies. It can be installed via pip: pip install virtualenv
Step 1: Create a Virtual EnvironmentNavigate to your project directory and run: python -m venv env
Step 2: Activate the Virtual EnvironmentOn Windows: venv\Scripts\activate
Step 3: Install Packages within VirtualenvWith the virtual environment activated, install packages as usual with pip, To exit the virtual environment: pip install package_name
deactivate
Manage Python Dependencies Using PipenvPipenv is a higher-level tool that simplifies dependency management and adds functionality like a Pipfile for package specification. Step 1: Install PipenvInstall Pipenv using pip: pip install pipenv
Step 2: Create and Activate Virtual EnvironmentNavigate to your project directory and run, To install a package: pipenv install
pipenv install package_name
Step 4: Deactivate the Virtual EnvironmentTo exit the virtual environment: exit
Alternative Solutions
Example : In this example, we have a Python script script.py that imports the NumPy library as np. We perform a simple operation to calculate the sum of the array using the NumPy’s np.sum() function. Python
Output: Sum: 15
|
Reffered: https://www.geeksforgeeks.org
Python |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 17 |