Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 搁置模块不工作_Python - Fatal编程技术网

Python 搁置模块不工作

Python 搁置模块不工作,python,Python,在我重新安装Python以将其从AppData文件夹移动到程序文件后,shelve模块似乎不再工作,我在调用shelve.open()时收到以下错误 请帮忙 >>> import shelve >>> myShelf = shelve.open('data') Traceback (most recent call last): File "C:\Program Files\Python\lib\dbm\dumb.py", lin

在我重新安装Python以将其从AppData文件夹移动到程序文件后,shelve模块似乎不再工作,我在调用
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'
    >>> 
导入搁置 >>>myShelf=shelve.open('data') 回溯(最近一次呼叫最后一次): 文件“C:\Program Files\Python\lib\dbm\dumb.py”,第81行,在创建 f=_io.open(self._datfile,'r',encoding=“拉丁语-1”)
FileNotFoundError:[Errno 2]没有这样的文件或目录:“data.dat” 在处理上述异常期间,发生了另一个异常: 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 myShelf=shelve.open('data') 打开文件“C:\Program Files\Python\lib\shelve.py”,第243行 返回DbfilenameShelf(文件名、标志、协议、写回) 文件“C:\Program Files\Python\lib\shelve.py”,第227行,在_init中__ Shelf.\uuuu init\uuuuu(self,dbm.open(文件名,标志),协议,写回) 文件“C:\Program Files\Python\lib\dbm\\uuuuu init\uuuuuu.py”,第94行,打开 返回mod.open(文件、标志、模式) 文件“C:\Program Files\Python\lib\dbm\dumb.py”,第303行,打开 返回_数据库(文件、模式、标志=标志) 文件“C:\Program Files\Python\lib\dbm\dumb.py”,第69行,在\uuu init中__ 自创建(标志) 文件“C:\Program Files\Python\lib\dbm\dumb.py”,第83行,在创建 将_io.open(self._datfile,'w',encoding=“Latin-1”)作为f: PermissionError:[Errno 13]权限被拒绝:“data.dat” >>>
错误“FileNotFoundError:[Errno 2]没有这样的文件或目录:'data.dat'”显示,它找不到data.dat,请检查文件位置

我在使用Windows 10时遇到了这个问题。我通过将工作目录更改为我的配置文件下的文件夹解决了这个问题

os.chdir('C:\\Users\\Nat\\Documents\\Python\\Project 1')

我假定我没有权限写入文件“Program Files”。

“FileNotFoundError:[Errno 2]没有这样的文件或目录:'data.dat'”。搁置模块工作正常,您只需要确保要读取的文件在那里;建议,因为您的错误中拒绝了权限。如果文件不在那里,Evert-shelve.open应该创建该文件。psuedoAJ-不确定使用sudo运行意味着什么,请详细说明一下好吗?我想,@psuedoAJ表示Linux系统下的管理员。如果您使用Windows,请检查您的帐户是否具有管理员权限,该权限允许您创建和写入文件。