No argument there!
I agree with this to an extent, but I think there’s a lot of mitigation that can be done here. One obvious one is the prompt manipulation so you’re always seeing (myenv) ~/myproject#
, which I think is already pretty common and helpfully forces the idea of the environment right in front of the user’s face at all times.
But your comment about “open a terminal from the GUI” again makes me think the solution to that is twofold:
- Make the default environment not be the system environment. The biggest problems come not from the fact that people didn’t manipulate the intended environment (e.g., by installing a package), but from the fact that they did manipulate an unintended environment, and those problems are exacerbated if the one they did manipulate is really important (e.g., needed to run core OS functions). If opening a terminal puts you into some kind of “scratchpad” environment and you accidentally install stuff, that’s not such a catastrophe as accidentally mucking up your system. You can just do
activate env_i_meant_to_use
and redo whatever you did. - Make it so you cannot use Python without an environment. In other words, if you open up a terminal and your prompt does not say
(someenv)
and you typepython
(or evenpython3
) you should get “command not found”. If you really want to use the system python you should be typingactivate systempython
first, or using something calledsyspython
, or using aconda run
type thing that lets you run a command in a specified environment without a separate activation step, or whatever.
Of course, the problem with #2 is that it’s really a matter of how the system installs Python than anything directly under Python’s control. But still I think that’s the direction we should shoot for. I was heartened to see (on some github issue I can’t find now) that some progress was actually made getting “python-full” as a debian package, and there was even talk about going further so that python
gives you, well, Python, and some other package like system-python
gives you the locked-down version that has no pip or virtualenv. More pressure should be applied in that direction.
OS-level tools should not be using a Python that is exposed as python
on the global system path. No one should be using anything that is exposed as python
on the global system path. Every usage of Python should be gated through some kind of environment. [1] And the “default” environment (if one is created on install) should be a basically empty one. People can of course still get themselves in a tangle by installing everything willy-nilly into that default, but least they’ll be able to create a new environment and instantly have a clean slate, without having mucked up any system-critical stuff in the process.
On Windows, where there is no system Python, I think this is much easier: just make the official Python.org installers not install Python to the path, but instead install a full-featured environment manager to the path, so that people literally cannot start to use Python without understanding that they must first decide what environment to use it in.
I agree to some extent, but I’m a bit skeptical that the DWIM can be made good enough to cover more than a small proportion of cases, at least with the current ways of guessing. Are there any existing ways of auto-determining the environment other than checking the current working directory or using a third-party tool that internally stores environment info (e.g., an IDE where you can save a “project” that knows which environment it’s supposed to run in)? The former is pretty coarse, and the latter isn’t generalizable because it’s inherently not guessing an environment but just “saving my choice of what environment to use for this thing”.
We do, but I think it’s important to consider whether we can improve the core-provided feature so it offers more of the benefits of other environment managers.
-
I’m talking here about systems where users actually run programs directly. It might be different in a context like Python embedded in some device, but my impression is that people setting up that kind of thing already wind up having to diverge from the standard Python setup as provided by Python.org, Linux distros, etc. ↩︎