For years Python has recommended the use of virtualenv, however I have never really liked the workflow that it offers. So I was happy when one of our instructors, @marineepo87, came across Pipenv, which allows you to manage your python dependencies in a more straightforward manner. The steps for using it are below:
If you're on a mac and have brew installed, run the command:
brew install pipenv
If you're on a PC you can install it via pip with the command:
pip install pipenv
To start a project, change into the directory that you want to use as the root of your project. If you want to build a Python 3 project (recommended), run the command:
Assuming that you have Python 3 on your system, it will build the full environment and use Python 3 as the version. If that command works it should provide the following output:
A few key items to notice in the output:It generated a Pipfile, that is where you can keep track of all of the project's dependencies, along with the version of Python that you're using. It creates a virtualenv automatically, mine is stored here: /Users/admin/.local/share/virtualenvs/python-env-Fa5mmZ2G
Now you can install any of the dependencies that you want, so if you want to install the numpy and requests Python libraries, you can do so with commands such as:
pipenv install numpy
pipenv install requests
Notice that I'm not using pip directly, instead I'm using the pipenv command. This will add the libraries and their set of dependencies to the Pipfile along creating a Pipfile.lock that manages attributes such as dependency version numbers and checksums.
From there you can activate the virtualenv session with the command:
And to confirm that it's all working, you can run the command:
To see that the project is using python from the virtualenv instead of the normal system path.
To 'de-activate' the pipenv shell session, you can type 'exit' or ctrl+d to end the session.