5 ms·
I wish there was a way to lock the global python so you couldn't install packages to it by accident
by cmcconomy 4y ago
I wish there was a way to lock the global python so you couldn't install packages to it by accident
- dragonwriter 4y agoOn unixy systems, won't the system Python usually require root/sudo to install packages, whereas the ones in your environments will be owned by a less-privileged user? And on Windows, you may have a globally installed Python (though there is little reason to have one instead of the Py launcher), but even if you do it's not a system Python that system components are relying on.
- remram 4y agoUnfortunately the pip developers had the genius idea to add a "user install" mode which pip will default to in this situation. So if you're not root, you won't be able to mess up your system-global Python, but you can still mess up your user-global Python (deleting some ~/.local subfolders takes care of this).
- mixmastamyk 4y agoUseful feature that should have existed from the beginning. If it did, the sudo mistake wouldn’t have happened.
- __mharrison__ 4y agoYou can do this in UNIX systems by dropping a line like this in your ~/.bashrc . /home/matt/envs/menv/bin/activate
- kstrauser 4y agoI have: $ cat ~/.pip/pip.conf [global] require-virtualenv = true ...which makes pip refuse to install anything unless I'm in an activated virtualenv. That, plus running as a regular user that doesn't have write permission to /usr, goes a long way.
- bravetraveler 4y agoI love this, pip is an absolute nightmare on systems with a restricted umask. Newly created files/directories lack permissions for regular users... essentially breaking the interpreter for everyone [if /usr, sudo, etc]
- primax 4y agoThis is great, thank you!
- 0x008 4y agothen you cannot upgrade pip :D
- kstrauser 4y agoI do sometimes have to disable that, but at least then it's because I'm very deliberately doing it for a specific reason. But if you're in a virtualenv, you can use the venv's pip to upgrade the venv's pip. :-)