2 ms·
if on Linux, NEVER touch the system Python! If you can, you should use the package manager of your distro to install the desired python version. If not availabl
by gchamonlive 7y ago
if on Linux, NEVER touch the system Python! If you can, you should use the package manager of your distro to install the desired python version. If not available, or you don't trust a third party ppa, compile from source and install using make altinstall:
https://docs.python.org/3/using/unix.html#building-python https://docs.python.org/3/using/unix.html#building-python
Next, install pip for your user!
`curl https://bootstrap.pypa.io/get-pip.py https://bootstrap.pypa.io/get-pip.py -o get-pip.py`
`python get-pip.py --user`
Now you should have `python` which is the system one and `python3.x` for alternate versions. Installing modules from pip can also be harmful, so always use `pip install --user` for tools written in python (like aws cli). Those tools are installed in ~/.local/bin, so make sure to add that to your PATH.
Next, you can use virtual environments to prevent your .local/bin from becoming bogged, if you are dealing with many dependencies from different projects. A nice virtual environment management tool helps a lot. Take your pick, virtualenv + wrapper, pyenv, pipenv, conda... whichever you choose, stick to virtualenv for development!
In a nutshell
1. never touch your system python!
2. install tools from pipy using pip's --user flag
3. install different python versions using make altinstall, if building from source
4. virtual environments for development
This should be enough to keep your Linux installation healthy while messing around with python.
Also, docker containers could simplify this whole process, although this is another tech you are adding to your stack
- Spivak 7y agoI wish Linux distros would take the system python out of the default path, put it in /usr/libexec, and patch python dependent packages to use that path manually for exactly that reason. There desperately needs to be a separation between the Python that's intended to support the OS and Python that's intended to be used by users. These should have never been mixed and there's so much headache caused by it.
- sigjuice 7y agoNever ever type pip as root. Then there is no risk of messing up the system python by forgetting —user. This strategy works fine on Linux. I haven’t quite gotten the hang of doing this on macOS where I forget —user from time to time and bludgeon my Homebrew python.
- p1esk 7y agoOr just use conda.