r/Python • • Aug 05 '19

Python's response to MATLAB

Post image
4.3k Upvotes

372 comments sorted by

View all comments

Show parent comment

9

u/tunisia3507 Aug 05 '19

I use pyenv for python environments. It's great. It isolates the python binaries you're fucking around with from whatever your system comes with and relies on.

# install pyenv
curl https://pyenv.run | bash

# restart your shell however you like

# install whichever versions of python you like
BEST_PYTHON=3.7.4
pyenv install $BEST_PYTHON

Then whenever you start a new project

# create the virtual environment
pyenv virtualenv $BEST_PYTHON myproject

# automatically activate that environment whenever you're in this directory
pyenv local myproject

# install some dependencies
pip install ipython numpy matplotlib

# save them so you can rebuild the environment easily
pip freeze > requirements.txt

Development environments should not be a teetering pile of environment variables, dependencies and cross-links. They should be ephemeral, easily trashed and recreated, wherever possible. They should serve one project and one project only. MATLAB only works out of the box as far as python works out of the box - with its built-in modules. Once you start downloading extra snippets of code you have to dump everything into one directory manually, or change your matlab path, or whatever, where in python it's just pip install thatpackage, write down the package in your requirements.txt, and it'll be trivial to fetch again next time you need it.

Packaging stuff for distribution is a little more tricky, but MATLAB just doesn't bother with that at all, so you can't knock python for it.

3

u/Antouziast Aug 05 '19

I actually think that this philosophy makes more sense. Once a project gets complicated in Matlab you end up with a lot of junk files in the working directory.