Ask HN: Simple but modern Python dev set-up?
Looking to do Django and Flask dev. I want something between using the system Python and a complex tool that manages many different versions.
I've heard good things about poetry, but what about actual Python? Is the homebrew (macOS) Python 3.x good enough?
Thanks!
25 comments
[ 2.5 ms ] story [ 48.2 ms ] thread"The Hitchhiker’s Guide to Python"[^1] does a tour of the tools that would be very useful. Virtual environments, testing, frameworks, etc.
[^1]: https://docs.python-guide.org/
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.
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.
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!
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.
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.
Also check out the FastAPI project. A very expressive framework with smart defaults plays nicely with the tools above and I prefer to django and flask.
https://fastapi.tiangolo.com/
- 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
--
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.
[1] https://medium.com/@henriquebastos/the-definitive-guide-to-s...