Ask HN: Simple but modern Python dev set-up?
I've heard good things about poetry, but what about actual Python? Is the homebrew (macOS) Python 3.x good enough?
Thanks!
I've heard good things about poetry, but what about actual Python? Is the homebrew (macOS) Python 3.x good enough?
Thanks!
What was most important to me was predictable builds and you can roughly accomplish this by using pip-compile:
pip-compile -n --generate-hashes requirements.txt 2> requirements-compiled.txt
Update this and commit to your repository whenever you add a new project. It keeps track of the hashes that each package uses which isn't perfect but is a good stop-gap. Then install packages using requirements-compiled.txt only.
Other pure pip/python suggestion welcomed!
--
1. Download python3.8 (if you're on a Mac, just use brew install python3.8)
Now you have a virtualenv via `python3.8 -m venv`
Didn't have to install _any_ dependencies. This is clean.
From there just use your favorite editor (Sublime, VS Code, Vim, etc) and you're good to go.
A lot of other recommendations are saying install some other slightly more complicated things that you _absolutely do not need_. If you're doing standard Python dev, you literally just need a virtual environment and an editor.
Miniconda/conda is pretty good. It's a lot more stable than it used to be. I use a plain old venv to run Django on a production server.
Poetry is good for packaging, I've not tried it as a virtual environment manager. It seems more fiddly to me than just running `conda create -n blah python=3.8; conda activate blah`. Sometimes I just want a system-wide "good" environment and Poetry's more suited to single folder/project configurations that you might eventually want to release as a standalone package (I may be wrong here). For easy publishing to PyPI though, Poetry is great.
Of course there are tools out there which will automagically download the right python version when creating a venv but in my opinion that's neither easier nor harder.
- Install pyenv (curl https://pyenv.run | bash)
- Install python version(s) with pyenv (pyenv install 3.7.3)
- Create virtualenv with pyenv virtualenv. (pyenv virtualenv <version> <name-to-give-it>)
- Create a directory with the same name (mkdir <name-to-give-it>)
- cd into it and do pyenv local <name-to-give-it> for auto activating virtualenvs.
- Install packages with pip.
This isn't the most elegant solution available, but it keeps everything nice and segregated.
edited to add clarity
"The Hitchhiker’s Guide to Python"[^1] does a tour of the tools that would be very useful. Virtual environments, testing, frameworks, etc.
I couldn't leave it at that and added one resource recommendation. Then I removed the part in the middle, and the result of removing that is straight out of an infomercial.
[1] https://medium.com/@henriquebastos/the-definitive-guide-to-s...
Homebrew or XCode updates seemed to nuke my virtualenvs on macOS, whereas I've been able to use the same virtualenvs on Linux for half of a decade.