Email or username:

Password:

Forgot your password?
Simon Willison

Miscellaneous thought about Python development environment usability: maybe a good focus could be ensuring that developers don’t have to understand the concept of their $PATH in order to debug problems with their environment

I’m not sure how that could be achieved, but it’s an interesting angle to think about the problem

24 comments
Simon Willison

(This thought brought to you after several lost minutes where it turned out I had the wrong PATH and that’s why tests were failing in weird ways)

Daniel

@simon That is one of the benefits of running in a self-contained dev container.

You can be sure that your system (global installs, env vars, etc) don't interfere with the dev environment.

I always wondered if there is an iteration on python's venv concept where the venv would also restrict filesystem paths, env vars, and more.

Brett Cannon

@simon What was the specific problem? I honestly don't remember the last time I had a PATH problem, but I'm sure I have a blind spot here.

Simon Willison

@brettcannon for the problem I just had it was that thing where I create a brand new pipenv environment and install pytest into it, but when I run pytest it runs a globally installed binary instead - I had to quit out of and re-enter the environment to get the environment-local pytest to run (which could then see my dependencies)

It reminded me how much knowing what a PATH is matters for figuring out errors like that

Glyph

@simon @brettcannon also it's hard to describe the common new-user failure mode, which is "something doesn't work, or it behaves weirdly with tool X, so I install tool Y because maybe that one works". X, Y, Z, A, B C all append a little bit of stuff to your ~/.zshrc or whatever, scattering $PATH configurations into a bunch of different locations that make every IDE and terminal function differently, and even if it's all eminently comprehensible, unwinding is a tedious nightmare

Brett Cannon

@simon So I take it you don't run pytest via `python -m pytest` but instead via `pytest`?

Simon Willison

@brettcannon huh... that's the case, but now you mention it there's no reason I shouldn't start a habit of using "python -m pytest" instead

Simon Willison

@dabeaz @brettcannon I've upgraded all of my cookiecutter templates to use "python -m pytest" instead of just "pytest" now: github.com/simonw/python-lib/i

Stefan Eissing

@simon @dabeaz @brettcannon Python‘s. venv is like Marvel‘s Multiverse. No one ever is positively surprised by any of it.💁🏻‍♂️

Simon Willison

What if Python shipped a standard library module that diagnosed this stuff in as much detail as possible for you?

So you could run something like:

python -m debugenv

And it would print out a whole bunch of useful stuff about what your PATH is, your Python path, what version, any other versions it can find in common locations, if you are in a virtual environment, links to tutorials that will explain more - that kind of thing

Ian

@simon I like the idea though I think "debug" shouldn't be the term used. I feel that should be reserved for actual code fixing, not just inspecting the environment.

Something like "inspect" or "list" or "show" or "dump" might be better?

Colin Dean

@simon something along these lines is quite literally on my plate for the next few weeks of free time at work

Matthew Martin

@simon I started to write that once. The root problem is that the Python run time could be anywhere on the machine, but is likely at a few know places. Or it is at 130 places because that is how many vens are on the machine.

Thomas Vander Wal

@simon This would have saved me two to three hours today.

it really needs to come to life.

Min RK

@simon I’m sure you’ll hear about a number of these tools today, but for work I made a less Python-specific environment report tool, which handles things like HPC system modules, pip, conda, $PATH: github.com/minrk/envreport . It errs on the side of “entirely too much information, send this to support,” probably not very manageable for most directly affected individuals.

Chris Amico

@simon Thinking about my very long set of instructions for setting up a Python environment, I realize that a lot of it could be called $PATH problems.

Jaanus Kase

@simon not only Python

I use other tools, and $PATH is equally annoying there too

Carlton Gibson 🇪🇺

@simon I know @wsvincent has spent a lot of time battling this for his Django for Beginners book. (“First learn some esoterica…”, it feels like.)

capotej

@simon respectfully disagree: $PATH is such a fundamental part to how computers execute programs, we should be educating here, not abstracting

Simon Willison

@capotej sadly I don’t think that works - I think it may be one if those weird pieces of trivia that loses people entirely

(A lot of people these days don’t understand files and folders! I’d rather invest my education efforts in things like that theverge.com/22684730/students)

Go Up