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:

  1. Install `pipenv`:
    pip install pipenv
  2. Create a project directory and navigate to it in your terminal.
  3. Initialize a virtual environment (remember to replace `3.x` with your desired Python version):
    pipenv --python 3.x
  4. Install your dependencies:
    pipenv install package_name
  5. Execute the scripts within the virtual environment using the following line of code:
    pipenv run script_name
  6. 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





Write an answer...

Cancel

Please follow our  Community Guidelines

Can't find what you're looking for?