在研究gdb-python突然出现的一个奇怪错误时,我将其简化为:
C:\Users\User>python -i
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win 32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> dir(os.path)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'path'
>>> dir(os)
['__builtins__', '__doc__', '__file__', '__name__', '__package__']查看其他一些'module' object has no attribute答案,最常见的建议是在sys.path中的某个地方一定有另一个流氓os.py,并且它是被加载的,而不是内置的。但是我检查了PYTHONPATH环境变量,并且在当前目录中,没有任何其他os.py。
因此,我寻找一种方法来查找定义实体的文件的名称,毫不奇怪,Python以inspect模块的形式拥有such a facility。
>>> inspect.getsourcelines(os)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Programs\Python273\lib\inspect.py", line 690, in getsourcelines
lines, lnum = findsource(object)
File "C:\Programs\Python273\lib\inspect.py", line 527, in findsource
sourcefile = getsourcefile(object)
File "C:\Programs\Python273\lib\inspect.py", line 451, in getsourcefile
if os.path.exists(filename):
AttributeError: 'module' object has no attribute 'path'所以inspect依赖于os.path,然后我的想法就用完了。
我最近没有安装任何新的东西。唯一发生的事情是我必须执行强制关机,这可能与运行Python脚本同时发生,因为当机器变得没有响应并发生强制关机时,我正在循环中重复运行一个简短的Python脚本。
发布于 2017-06-21 04:36:47
我也有同样的问题,C:\Python27\Lib\os.py根本没有readlink()函数。搜索了Lib,发现有6步,它正在使用,但没有定义:
win32上的Python2.7 (r27:82525,2010JUL 4,09:01:59) MSC v.1500 32位(英特尔)
C:\Python27\Lib\pdb.py(1194): dirname = os.readlink(dirname)
C:\Python27\Lib\platform.py(952): os.path.join(os.path.dirname(filepath),os.readlink(filepath)))
C:\Python27\Lib\posixpath.py(386): resolved = os.readlink(path)
C:\Python27\Lib\rexec.py(146): ok_posix_names = ('error', 'fstat', 'listdir', 'lstat', 'readlink',
C:\Python27\Lib\shutil.py(183): linkto = os.readlink(srcname)
C:\Python27\Lib\tarfile.py(1873): linkname = os.readlink(name)https://stackoverflow.com/questions/21640794
复制相似问题