6

Directories listed in my .pth configuration file aren't appearing in sys.path.

The contents of configuration file, named some_code_dirs.pth:

/home/project

Paths to the file:

/usr/lib/python2.6/site-packages/some_code_dirs.pth
/usr/lib/python2.6/some_code_dirs.pth

Check on sys variables in the python interpreter:

>>> print sys.prefix 
'/usr'
>>> print sys.exec_prefix
'/usr'

All this seems as required in the Python documentation, but sys.path doesn't include the /home/project directory.

Note that the interpreter does add the directory after:

>>> site.addsitedir('/usr/lib/python2.6/site-packages') 

What am I missing here?

Esteban Küber
  • 36,388
  • 15
  • 79
  • 97
chernevik
  • 3,922
  • 9
  • 41
  • 55

2 Answers2

4

What OS are you using? On my Ubuntu 9.04 system that directory is not in sys.path. Try putting it into /usr/lib/python2.6/dist-packages. Notice that it is dist instead of site.

Isaiah
  • 4,201
  • 4
  • 27
  • 40
  • Yeah, Ubuntu does some strange and convoluted things with Python's library paths to try to make it fit their packaging system. Very little is in the same place compared to a standard default-compile Python installation. :-( – bobince Sep 03 '09 at 00:37
  • 1
    That worked -- with the .pth file in dist-packages, /home/project_root shows up in sys.path in the interpreter. /usr/lib/python2.6 _is_ in sys.path, and a copy of the .pth file is in that directory, so I don't understand why python doesn't pick that up. I suppose that too is a Ubuntu configuration issue. I am but an egg, but this seems like a strange set of choices by the Ubuntu folks. – chernevik Sep 03 '09 at 15:08
  • Well, I don't think that the python interpreter imports .pth files from every path in sys.path. – Isaiah Sep 03 '09 at 16:01
0

I had a similar problem a while ago. Check the encoding of your pth-file. It seems that pth-files are silently ignored if encoded in UTF-8 with BOM.

Community
  • 1
  • 1
wierob
  • 4,299
  • 1
  • 26
  • 27
  • That would be understandable, since “UTF-8 with BOM” is bogus and not compatible with ASCII (which is what pth files are)! Odd to see on a linux box though since it is usually only broken Windows apps that produce them. – bobince Sep 03 '09 at 00:33