HACKER Q&A
📣 peruvian

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!


  👤 thijsvandien Accepted Answer ✓
Start out with just pyenv. It's not complicated and helps a lot if you don't want system-wide updates to mess with your virtual environments (you don't). Even though pip may not be ideal, it works well enough. So far, more advanced alternatives for me created at least as many problems as they supposedly solved. See for yourself what issues you'll have (if any) and then pick the tools that solve them best. The editor/IDE is a personal thing. PyCharm is popular, but I never felt much chemistry with it. Currently enjoying VSCodium with the Python plugin. It will suggest to install some more packages for things like linting. Consider throwing in mypy. All that should get you pretty far. Better to start lean and build it out later, as needed.

👤 ralston3
My $0.02

--

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.


👤 joshvm
Any virtual environment will take precedence over either the system or homebrew Python. Since you want to deal with multiple versions (or Python? Or Django/Flask? Both?) you'll definitely be wanting some kind of isolated environment. It's nice to have Homebrew as a base since it'll be more recent than the system install, but it doesn't make a difference.

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.


👤 s1t5
Venv is the simplest - it comes in the Python standard library and gives you the basic tools to manage virtual environments. You can start with it and see how far it gets you. If you need to manage multiple versions of Python then try pyenv or conda.

👤 scottwernervt
I plan on trying https://jacobian.org/2019/nov/11/python-environment-2020/ which uses pyenv and poetry.

👤 dhruvkar
pyenv, pyenv virtualenv (built-in to pyenv) and pip.

- 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 )

- Create a directory with the same name (mkdir )

- cd into it and do pyenv local 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


👤 Jugurtha
Has your current Python development setup failed you yet? Are Python versions preventing you from producing useful software? Are you looking to explore and experiment with setups, or is shipping useful software what counts?

"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/


👤 miguendes
I follow this guide[1] every time I need to setup python from scratch.

[1] https://medium.com/@henriquebastos/the-definitive-guide-to-s...


👤 heavyset_go
PyCharm, IPython and Jupyter make writing, testing and debugging Python tolerable. Packaging has always been a pain no matter what you use, but just try to avoid pipenv.

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.


👤 raizinho
I use conda through miniconda. It comes with great support for reproducible virtual environments.

👤 potta_coffee
Virtualenv / virtualenv wrapper is what I've been using for years. I tried PyEnv at one point, didn't care for it. Sublime Text for editor, Sublime REPL plugin is nice.

👤 Nextgrid
My workflow is latest Python 3 installed through Homebrew, then pyenv and pyenv-virtualenv on top. Projects each get their own Python version and virtualenv independent of the Homebrew Python.

👤 BrandonBradley
pyenv and pyenv-virtualenv

👤 sigjuice
Homebrew python3 and no virtual environments. pip install —-user works great and keeps things simple.

👤 vfg1234
Just use Pycharm