Should "import site" fail if the cwd no longer exists?

Alex new_name at
Sun Jun 24 13:07:16 EDT 2001

On RH linux 6.2, if the cwd is removed, and python is started, "import
site" fails with an OSError.  Perhaps this exception could be caught,
instead, as it's quite confusing, otherwise.



athena$ cd /tmp
athena$ mkdir test
athena$ cd test
athena$ rmdir /tmp/test/
athena$ pyth
python     python1.5  python2.1  
athena$ python2.1 -v
# /mit/python/arch/i386_linux22/lib/python2.1/site.pyc matches /mit/python/arch/i386_linux22/lib/python2.1/
import site # precompiled from /mit/python/arch/i386_linux22/lib/python2.1/site.pyc
# /mit/python/arch/i386_linux22/lib/python2.1/os.pyc matches /mit/python/arch/i386_linux22/lib/python2.1/
import os # precompiled from /mit/python/arch/i386_linux22/lib/python2.1/os.pyc
import posix # builtin
# /mit/python/arch/i386_linux22/lib/python2.1/posixpath.pyc matches /mit/python/arch/i386_linux22/lib/python2.1/
import posixpath # precompiled from /mit/python/arch/i386_linux22/lib/python2.1/posixpath.pyc
# /mit/python/arch/i386_linux22/lib/python2.1/stat.pyc matches /mit/python/arch/i386_linux22/lib/python2.1/
import stat # precompiled from /mit/python/arch/i386_linux22/lib/python2.1/stat.pyc
# /mit/python/arch/i386_linux22/lib/python2.1/UserDict.pyc matches /mit/python/arch/i386_linux22/lib/python2.1/
import UserDict # precompiled from /mit/python/arch/i386_linux22/lib/python2.1/UserDict.pyc
'import site' failed; traceback:
Traceback (most recent call last):
  File "/mit/python/lib/python2.1/", line 82, in ?
    dir = makepath(dir)
  File "/mit/python/lib/python2.1/", line 70, in makepath
    return os.path.normcase(os.path.abspath(dir))
  File "/mit/python/lib/python2.1/", line 380, in abspath
    path = join(os.getcwd(), path)
OSError: [Errno 2] No such file or directory
Python 2.1 (#3, Jun 22 2001, 14:35:17) 
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "copyright", "credits" or "license" for more information.

More information about the Python-list mailing list