Made with ♥ by Polyglot.
A short guide curating the best information on how to install a working python on a MacBook without completely breaking the entire fucking system. Seems like it would be easy to do, but it's not as easy as one would think. Ultimately, you need a way to manage the installed python version and depedencies per project.
This guide assumes you've got a MacBook with a relatively recent OS (YMMV), homebrew (brew
), and you understand how $PATH
and your $SHELL
works at the most basic level
- In order to connect to PostgreSQL servers, SQL Alchemy needs
libpg
; however, the best known way to do this is tobrew install postgresql
; however, that includes the server. Sometimes this is OK; however, there are legitimate reason for not wanting to do this, so in that case, instead of installingsqlalchemy + psycopg2
you'd installsqlalchemy + pg8000
and your connection string prefix changes frompostgresql://
topostgresql+pg8000://
.
- Module: a file containing python code
- Package: a directory of python modules
- Distribution: an archived package
❯ brew update
❯ brew install pyenv
configures poetry to create virtual environments inside the project's root directory
❯ curl -fsSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
❯ poetry config virtualenvs.in-project true
Place the following or the equivalent into your shell's equivalent initialization file
❯ cat ~/.config/fish/conf.d/python-setup.fish
source ~/.poetry/env
status --is-interactive; and source (pyenv init -|psub)
❯ pyenv install 3.8.0
❯ pyenv global 3.8.0
❯ pyenv version
❯ poetry new yet-another-api-client
❯ cd yet-another-api-client
❯ poetry add requests sqlalchemy pg8000 tabulate
❯ poetry add --dev pytest black flake8
prints table data in ascii/pgsql format to screen
poetry run python3
~
Python 3.8.0 (default, Oct 7 2020, 17:23:33)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from sqlalchemy import create_engine, text, inspect
>>> from tabulate import tabulate
>>> engine = create_engine('postgresql+pg8000://scott:tiger@localhost/todos', future=True, echo=True, echo_pool='debug')
>>> connection = engine.connect()
>>> stmt = text('SELECT * FROM todos')
>>> result = connection.execute(stmt)
>>> records = result.fetchall()
>>> print(tabulate(records, headers=result.keys(), tablefmt='psql'))
~
List Configuration
⪼ poetry config --list
~
cache-dir = "/Users/wilmoore/Library/Caches/pypoetry"
experimental.new-installer = true
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/wilmoore/Library/Caches/pypoetry/virtualenvs
/var/folders/nr/8s8lg_7s0q581yjmssrvywph0000gn/T
~