我重新安装Python后将其从AppData文件夹移动到Program Files,看起来搁置模块不再有效,我在调用shelve.open()
时收到以下错误。
请帮忙!
>>> import shelve
>>> myShelf = shelve.open('data')
Traceback (most recent call last):
File "C:\Program Files\Python\lib\dbm\dumb.py", line 81, in _create
f = _io.open(self._datfile, 'r', encoding="Latin-1")
FileNotFoundError: [Errno 2] No such file or directory: 'data.dat'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
myShelf = shelve.open('data')
File "C:\Program Files\Python\lib\shelve.py", line 243, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "C:\Program Files\Python\lib\shelve.py", line 227, in __init__
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
File "C:\Program Files\Python\lib\dbm\__init__.py", line 94, in open
return mod.open(file, flag, mode)
File "C:\Program Files\Python\lib\dbm\dumb.py", line 303, in open
return _Database(file, mode, flag=flag)
File "C:\Program Files\Python\lib\dbm\dumb.py", line 69, in __init__
self._create(flag)
File "C:\Program Files\Python\lib\dbm\dumb.py", line 83, in _create
with _io.open(self._datfile, 'w', encoding="Latin-1") as f:
PermissionError: [Errno 13] Permission denied: 'data.dat'
>>>
答案 0 :(得分:0)
错误“FileNotFoundError:[Errno 2]没有这样的文件或目录:'data.dat'”显示你,它找不到data.dat,请检查文件位置。
答案 1 :(得分:0)
我在Windows 10上遇到了这个问题。我通过将工作目录更改为个人资料下的文件夹来解决了这个问题。
os.chdir('C:\\Users\\Nat\\Documents\\Python\\Project 1')
我想我没有写文件“ Program Files”的权限。