System Python is not for you

Kamal Mustafa - Apr 15 '18 - - Dev Community

If you already did some python development or just getting started, one of the advice you would always get is to never mess with the system python - the python version that come with your distro. For example on Ubuntu or Debian based system, python that was installed by sudo apt-get install python. At first I didn't really understand what this mean, why you can't use something that already comes for free ?

The answer to that question is because that version of python actually meant for the distro itself. Most distro would in some place used python, maybe for some configurations script. In Ubuntu, lot of their own applications are written with python. If we upgrade some of the libraries not through the standard package manager, there's a chance it would break these apps. So that's what the python they provided is for. It's for their own use, not us. Once I realized this, I have a feeling that distro should ship the python that they need separately from the python that would be used by the users.

For development purpose, I always run virtualenv $HOME to setup virtualenv environment in my home directory. Under Ubuntu, $HOME/bin is under $PATH so which python would always point to /home/kamal/bin/python rather than /usr/bin/python. This allow me to freely use easy_install and it would install it to my $HOME/lib/python2.5 instead of system wide lib directory. For something specific like developing a django project, I prefer to use Buildout to further isolate the environment. More on Buildout later.

To 'get' your own Python, you can use tools that provide multiple python interpreter such as Conda, Pyenv or Nix package manager.

There's one exception. If you're fine with the Python version that come with your OS and only care about the packages that you install, pip has --user flag that install all the packages to your $HOME directory. Just make sure your $HOME/.local/bin in your $PATH and $HOME/.local/lib/python3.x/site-packages appeared first in sys.path, you pretty much have an isolated environment from the system python. In fact, this is my current setup so far as I don't need much a fancy python other than the system python.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player