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

Alex new_name at mit.edu
Sun Jun 24 19:07:16 CEST 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.

Alex.

Example:

athena$ cd /tmp
athena$ mkdir test
athena$ cd test
/tmp/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/site.py
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/os.py
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/posixpath.py
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/stat.py
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/UserDict.py
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/site.py", line 82, in ?
    dir = makepath(dir)
  File "/mit/python/lib/python2.1/site.py", line 70, in makepath
    return os.path.normcase(os.path.abspath(dir))
  File "/mit/python/lib/python2.1/posixpath.py", 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