title-prefix | pagetitle | author | author-meta | date | date-meta | keywords | ||||
---|---|---|---|---|---|---|---|---|---|---|
Six Feet Up |
Bootstrapping your Local Python Environment |
Calvin Hendryx-Parker, CTO, Six Feet Up |
|
PyCon 2022 |
2022 |
|
Bootstrapping your Local Python Environment {data-background-image="images/david-clode-d0CasEMHDQs-unsplash.jpg"}
:::{.credits} Photo by David Clode on Unsplash :::
$ python -m this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
:::{.credits} Photo by Sean Stratton on Unsplash :::
{data-background-image="https://imgs.xkcd.com/comics/python_environment.png"}
::: notes
April 2018 Randall Munroe posted this comic and admitted he did some bad things to get to this point.
The Python environmental protection agency wants to seal it in a cement chamber, with pictorial messages to future civilizations warning them about the danger of using sudo
to install random Python packages.
:::
- Python provided by OS (macOS, RedHat, Ubuntu)
- Python installed from an App Store (Microsoft Store)
- Python installed from python.org installer
- Python installed from a Package Manager (apt, brew, chocolatey)
- Python installed by a Python Distribution (ActiveState, Anaconda)
::: notes Photo Credit: https://flic.kr/p/9iBvFB :::
So why should you care about all of this? {.r-fit-text data-background-image="images/fermin-rodriguez-penelas-LcJkpSoA0es-unsplash.jpg"}
:::{.credits} Photo by Fermin Rodriguez Penelas on Unsplash :::
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
- Change the global Python version on a per-user basis
- Per-project Python versions
- Override the Python version with an environment variable
- Search commands from multiple versions of Python at a time
https://github.com/pyenv/pyenv#installation
https://pyenv-win.github.io/pyenv-win/
:::notes This may be helpful to test across Python versions with tox.
Pyenv does not work in Windows outside the Windows Subsystem for Linux. :::
Explicit is better than implicit.
:::notes Show global and local Install a python version View installed versions :::
- virtualenv
- virtualenvwrapper
$ brew search pyenv
:::notes pyenv virtualenvs
show global freeze, make a virtualenv, show freeze, install requests
quick demo of virtualenvwrapper :::
$ python -m venv venv
:::notes New in version 3.3.
make sure to show that you can explicitly control which python version via the path to python show interacting with pyenv to set a specific python for the project and creating an env :::
$ brew install pipx
$ pipx ensurepath
pipx is ready to go! ✨ 🌟 ✨
$ pipx install httpie
installed package httpie 2.4.0, Python 3.9.6
These apps are now globally available
- http
- https
done! ✨ 🌟 ✨
:::notes show installing bpytop show installing markdown and injecting pygments :::
$ python -m pip install --user SomePackage
:::notes runs into the same problems as using the global python also, the uninstall does not support --user :::
:::notes
pipenv
seemed promising in the beginning...
asdf
if closest to pyenv, but lacks nice plugins like virtualenv
show poetry
demo if time
:::
Simple is better than complex.
:::notes demo
Create demo foler and venv
Install requests
Freeze to reqs.txt
Add reqs.in
python -m piptools compile --upgrade --no-annotate --no-header --allow-unsafe --generate-hashes --output-file /local/requirements1.txt /local/requirements1.in :::
:::notes
See Moshe's talk earlier today about getting this right and the complexity involved :::