Virtual Environments using PipEnv
PipEnv is a new way to create Virtual Environments in Python that allows for Environment Agnostic dependency installation.
The following information will help you install PipEnv to get started.
Start with installing Python 3.x (I used Python 3.7.1 as of this writing.)
Once you have
python3 installed. Use
pip to install PipEnv.
At the terminal write:
Because I have both
python 2.7 and
python 3.7 installed, I had to use
pip3 to install pipenv for
You might have to update the
PATH environment variable in order for the command to run from the terminal. For more information about setting your OS’s Environment Variable click here.
For more information on how to install PipEnv go to the documentation site at: pipenv.readthedocs.io/en/latest/
Next, we are going to set up the
requirements.txt file to make sure you have all the necessary dependencies for the rest of the book.
Versions – Requirements.txt File
The versions that you will need to follow this tutorial is provided for you by the following
The instructions that you need to follow are also provided and should work on any Operating System. Here is the
requirements.txt file that we are going to use:
Copy and Paste the above in a file labeled
requirements.txt in the root directory of your app. Make sure you are inside of that directory. Then, run the following command:
Using Pip inside your virtual environment
An alternative to the
requirements.txt file above is to use
pip inside your Virtual Environment.
Once it’s finished, you should have a
PipFile file and a
Congratulations! You installed PipEnv and you have an environment that is ready to go for the development for the rest of the book.
Everytime you sit at the computer you should do this…
When you’re ready to sit down and work on your project, you should do the following:
Open up your terminal and go to the directory with the
PipFile file and a
PipFile.lock file. Then, type:
Your shell should be changed – it should be noticeably different. Mine looks like this:
Yours should be similar, although what is inside of the parentheses might be different.
Everytime you are done working on your app you should do this…
When you’re done working, you should
deactivate the Virtual Envionment by running the following two commands:
This will kick you out of the Virtual Environment so you don’t mess up the virtual environment for later.