0

I recently was in a situation when the software center on my Ubuntu installation was not starting. When I tried to launch it from console, I found that python was unable to find Gtk, although i hadn't removed it.

from gi.repository import Gtk,Gobject


ImportError: cannot import name Gtk

I came across a closely related question at Stackoverflow( i am unable to provide link to the question as of now).The solution accepted(and also worked for me) was to remove the duplicate installation of gtk from /usr/local as Gobject was present in this directory but not Gtk. So, I removed it and again launched software-center and it launched.

While I am happy that the problem is solved, I would like to know if removing files from /usr/local can cause severe problems. Also, echo $PATH onn my console gives:

/home/rahul/.local/bin:/home/rahul/.local/bin:/home/rahul/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/rahul/.local/bin:/home/rahul/.local/bin

which tells that /usr/local/bin is searched for before /usr/bin . Should $PATH be modified such that the order of lookup is reversed? If yes, then how?

rahulmishra
  • 620
  • 1
  • 13
  • 29
  • Python doesn't use `$PATH` to find its modules. See http://stackoverflow.com/questions/3144089/expand-python-search-path-to-other-source (which is a duplicate of your question, methinks) – Hans Lub Jan 22 '15 at 11:30
  • @HansLub , though i was searching for some different answer, your comment gave me some new information. thanks :) – rahulmishra Jan 22 '15 at 12:10

1 Answers1

1

You actually don't want to change that.

/usr/local is a path that, according to the Linux Filesystem Hierarchy Standard is dedicated to data specific to this host. Let's go a bit back in time: when computers were expensive, to use one you had to go to some lab, where many identical UNIX(-like) workstations were found. Since disk space was also expensive, and the machines were all identical and had more or less the same purpose (think of a university), they had /usr mounted from a remote file server (most likely through the NFS protocol), which was the only machine with big enough disks, holding all the applications that could be used from the workstation. This also allowed for ease of administration, where adding a new application or upgrading another to a newer version could just be done once on the file server, and all machines would "see" the change instantly. This is why this scheme permaned even as bigger disks become inexpensive.

Now imagine that, for any reason, a single workstation needed a different version of an application, or maybe a new application was bought with with only a few licenses and could thus be run only on selected machines: how to handle this situation? This is why /usr/local was born, so that single machines could somehow override network-wide data with local data. For this to work, of course /usr/local must point to a local partition, and things in said path must come first than things in /usr in all search paths.

Nowadays, UNIX-like Linux machines are very often stand-alone machines, so you might think this scheme no longer makes senses, but you would be wrong: modern Linux distributions have package management systems which, more or less, play the role that of the above-mentioned central file server: what if you need a different version of an application that what is available in the Ubuntu repository? You could install it manually, but if you put it in /usr, it could be overwritten by an update performed by the package management system. So you could just put it in /usr/local, as this path is usually granted not to be altered in any way by the package management system. Again, it should be clear that in this case you want anything in /usr/local to be found first than anything in /usr.

Hope you get the idea :).

SukkoPera
  • 621
  • 4
  • 8
  • I understand that searching for a version that we manually installed should be preferred. But in my case, I had a single installation of software-center and instead of finding for gtk in /usr it was searching for it in /usr/local leading to error.. – rahulmishra Jan 22 '15 at 11:56
  • That happens exactly because what you install in /usr/local is supposed to override what is in /usr, so the whole mechanism is working correctly. The root problem is that you actually *don't want* to override what is in /usr, so just remove what you have in /usr/local. – SukkoPera Jan 22 '15 at 12:00
  • Suppose i had two installations of software-center. Now I would like both of them to run independently, but according to your explanation, I don't think it would be possible since, the older version would always look for files in /usr/local and which might not be compatible for it. – rahulmishra Jan 22 '15 at 12:08
  • I don't know exactly how software-center works, but having multiple versions of a library/applications is generally possible, with careful handling. That's how, for instance, GTK 1.x, 2.x and 3.x can co-exist on a single system. If you need different versions of an application, you can try to install it under some directory in `/opt`. – SukkoPera Jan 22 '15 at 13:38