How can I use pipenv to manage my Python project's virtual environment and dependencies?
Asked 7 months ago
I'm a newbie Python developer juggling multiple projects, and I'm looking for an efficient way to manage virtual environments and dependencies. How can I make the most of pipenv to simplify this process and keep my project structure clean?
Filip Dimkovski
Tuesday, October 03, 2023
In essence, `pipenv` is a Python packaging tool that simplifies virtual environment management and dependency handling in Python projects. To use it, do the following:
- Install `pipenv`:
pip install pipenv
- Create a project directory and navigate to it in your terminal.
- Initialize a virtual environment (remember to replace `3.x` with your desired Python version):
pipenv --python 3.x
- Install your dependencies:
pipenv install package_name
- Execute the scripts within the virtual environment using the following line of code:
pipenv run script_name
- Review the dependency graph and lock the dependencies:
pipenv lock
This will generate a `Pipfile.lock` to record exact versions for reproducibility. You can then enter the virtual environment shell with:
pipenv shell
Please follow our Community Guidelines