Pipenv has a run and shell, but which one should I use ? That's the same question I've asked myself yesterday. Check out my brief summary about this!

Pipenv shell

Pipenv shell is used mainly as a run it now, and leave.

It will create an active environemnt almost the same way as with source env/bin/activate, but it will also do it within a new shell. That way you cannot use previous commands from history.

There is even a bug about that but the conclusion is that it's not pipenv issue, rather pew problem with sub-shell.

As it's using a sub-shell, it may not be advised to use it within your deployment/management.

For example if you want to make a Dockerfile with Pipenv, you should not use pipenv shell because it will not be activated for the next RUN command or any other command that you may put with && signs.

You could use some type of sub-processing but that's far beyond easy and clean - so as using pipenv --venv that gives you opportunity to reuse underlying virtualenv (by giving you place where is the v-env that you can activate manually).

Pipenv run

Pipenv run is the main purpose for running next python commands. It will automatically activate environment for that command and execute anything you will put to it.

For example to run some specific python file that uses dependency you will:

pipenv run python main.py

That will activate env and run python main.py in the env.

Conclusion

As posted by Dan Ryan(techalchemy) in this issue comment - you can should use pipenv run for 'heavy lifting' and pipenv shell for day-to-day convenience of dev tasks.

Acknowledgements

Thanks!

That's it :) Comment, share or don't :)

If you have any suggestions what I should blog about in the next articles - please give me a hint :)

See you in the next episode! Cheers!



Comments

comments powered by Disqus