43

What is the difference between using pipenv install <package> compared to using pip install <package> after activating an environment using pipenv shell.

I know pipenv install <package> will

  1. Create the virtual environment if it is not created yet.
  2. Runs pipenv lock command automatically.

Apart from these, is there any other difference between these two?

darkavenger
  • 675
  • 1
  • 5
  • 11
  • 1
    Some seconds on google gave me this: [why python devs should use pipenv](https://opensource.com/article/18/2/why-python-devs-should-use-pipenv) – gkhaos Jan 15 '19 at 11:22
  • 1
    Yeah, I already use pipenv and when you use pipenv, there are two ways to install a package. First way is going to the directory and executing the command `pipenv install ` directly from the directory and in this case, you don't have to activate the virtual environment. Another method is activating the virtual environment and using the command `pip install ` as we usually do in python. – darkavenger Jan 16 '19 at 05:11

1 Answers1

29

If you are installing using a pipenv environment you should always install your packages using pipenv, this way it will update your pipfile.lock file. Also be careful because pip install <package> will pretty much work anywhere, it's not installing packages to your virtual environment, it's installing them into your computer. Pipenv will update your Pipfile.lock and actually install into your pipenv virtual enviroment if you have one open.

It's rarely a good idea to pip install <package> outside of a virtualenv.

Sewagodimo Matlapeng
  • 2,136
  • 2
  • 11
  • 12
  • 2
    So the main point is that the pipfile.lock file will also be updated which is the sole purpose of using pipenv in the first place. Thank You. – darkavenger Jan 25 '19 at 10:03
  • 7
    This answer is incorrect. If you use `pip install` it will install to your *current* virtual environment. It will only install to your computer if you have not activated any virtual environment. – John Henckel Oct 01 '21 at 17:37
  • @darkavenger no the `Pipfile.lock` isn't the sole purpose of useing `pipenv`. E. g. it's also pretty easy and convenient to create your virtual environments with it. – raphael_mav Nov 17 '21 at 10:28