Skip to content

Minimalist Python Setup

Published:

I recently installed python on my machine; in this post I’ll walk through my process for managing various python versions and dependencies.

Table of contents

Open Table of contents

Installing pyenv

I suggest walking through the #installation portion of the pyenv README. In my case for WSL/Linux I did the following:

# run the installer
curl https://pyenv.run | bash

# install your version of choice
pyenv install 3.12

# you can optionally set a desired global/default version
pyenv global 3.12

Installing pipenv

pip install --user pipenv

# navigate to your project directory
cd path-of-project

# create a "Pipfile"
pipenv install

# activate pipenv instance in current shell
pipenv shell

Installing direnv

# assuming Ubuntu/Debian
sudo apt install direnv

# create a ".envrc", add logic to automatically apply the pipenv virtualenv in the project/directory
echo "layout pipenv" > .envrc

Final Thoughts

I’d recommend reading up on the pipenv docs. I prefer this approach opposed to using virtualenv for creating/isolating python envs. The big take-away is to use pipenv in place of pip:

pipenv install Flask # or whatever package

You can find the details of the installed package in the Pipfile, as well as the Pipfile.lock; having a similar experience to handling npm dependencies.

Source(s)