我从 python 3.6 升级到 python 3.9,现在无法读取现有的 gdbm 文件。抛出以下错误,有什么办法解决这个问题吗?
平台:CentOS Linux 版本 7.9.2009(核心)
Python:3.9.9
使用 Python 3.6 版本,我首先使用如下方式创建了文件:
self.def_id_seq_map_db = dbm.open(str(self.datapath / "def_id_seq_map"), 'c')
self.def_id_seq_map = shelve.Shelf(self.def_id_seq_map_db)
当我尝试使用Python 3.9读取时出现错误:
File "/usr/local/lib/python3.9/dbm/__init__.py", line 91, in open
raise error[0]("db type is {0}, but the module is not "
dbm.error: db type is dbm.gnu, but the module is not available
最佳答案
看来您是从源代码安装的 Python。您的系统上可能没有安装 gdbm-devel。
我会尝试什么:
- 安装 gdbm-devel 并使用
./configure --enable-optimizations &&\make install 配置/安装 python
- 如果不起作用,请在 ./configure 脚本中添加以下修饰符:
--with-dbmliborder=gdbm:ndbm
关于python - 使用 python3.9 的 gdbm 无法打开使用 python 3.6 的 gdbm 创建的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70755659/