Notes and usage with Pipenv
What I Used To Do
After selecting my prefered Python version with
pyenv I would install
pip install virtualenv and then proceed with more steps to create the virutalenv, run the virtualenv, and install packages. This pattern was ok, but quite tedious as I summarize all of the commands below. Eventually, I would have to freeze the packages and build a lock file to select the versions of the packages which were compatible for the project I was working on.
- pyenv local 5.8.6
- pip install virtualenv
- virtualenv .env
- source .env/bin/activate
- pip install -r requirements.txt
While this seems very straight forward, many things got better when moving to
What I Do Now
Now, I select my Python version with
pipenv and then run
pipenv shell. This is vastly much easier and allowes for better automation by using:
pipenv run cmd-to-run
If I want to add a package to the
Pipenv file, I just install it with:
pipenv install pkg-name
I have this already placed in Libsh but I will also share the install instructions by the creator:
Commands I Use
This does all the work of creating the virtualenv into a temporary directory and launching a sub-shell of the project
Installes all of the packages from the Pipfile.lock
Executes a command within the
pipenv environment saving steps of sourcing other functions before executing.
pipenv --python #.#
Creates a new project with the
#.# version of Python!
I really have come to enjoy
pipenv very much and its now my default tool for almost every Python project I work on. I really like
raw focused tools that help out multiple projects by solving specific issues. This is one of thoes tools.