Libo Li

View Original

Simply setting up Python and Jupyter with Pipenv

Python is a fun language to learn and can do amazing things. Maybe due to this incredible usefulness, you can find Python in a variety of environments to be used in a variety of ways. This makes things confusing for someone starting out, especially if you’re in architecture and starting through Dynamo and Grasshopper. Sometimes just setting up a simple place to analyze some local data or test some code is all you need. This is a simple 3 step Jupyter notebook setup that I go back to constantly to start projects.

1. Set up Python

This step should feel fairly straight forward. Go to python.org, download the latest python release and install it.

During the install, make sure that pip is installed. It should be checked by default.

After the install, open up your command line (terminal on mac, cmd or powershell on PC) and type in

python —version

you should receive a comforting message.

2. Set up pipenv

pipenv is a simple way to manage a virtual environment for your project. For beginners, handling dependencies and conflicts is a complexity that is a serious blocker to progress. Pipenv works by helping us create a “project environment” around the project directory. There are some deeper functionality that will become essential down as you learn.

with pip you can install pipenv with the install command in pipenv docs.

pip install —user pipenv

3. Set up a project directory and Jupyter

We’re now ready for a project directory. Create a folder where you want your project files to live and navigate to that folder in the command line.

To initiate our project and install Jupyter, we can simply use:

pipenv install jupyter

Note that we used pipenv and not pip. This ensures that everything associated with this project is inside the project directory we made and not in a shared location between projects.

Enjoy

That’s basically all there is to it. To bootup your fresh jupyter project just do

pipenv run jupyter notebook

To install additional packages like requests, pandas, or matplotlib, just run “pipenv install ______” in the project directory. They will be made available to your notebooks and any modules you create inside the project.

There are many other ways to set up python environments or run Jupyter notebooks. If you’re just getting started however, this is one way to cut the noise and focus on the code.