GDBM不适用于Python 3.6和anaconda

编程入门 行业动态 更新时间:2024-10-27 22:21:27
本文介绍了GDBM不适用于Python 3.6和anaconda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在anaconda环境中使用Python 3.6. 我用

I use Python 3.6 in an anaconda environment. I installed GDBM with

conda install gdbm

安装顺利,但是我不能使用Python中的dbm.gnu:

The installation went well, however I can't use dbm.gnu from Python:

ModuleNotFoundError: No module named '_gdbm'

它表明即使实际安装了GDBM,Python也不包含_gdbm模块.

It seams that Python doesn't include the _gdbm module, even if GDBM is actually installed.

这是一个已知问题吗?我该如何解决?

Is this a known problem? How can I fix it?

谢谢!

推荐答案

我也遇到了这个问题.这可能不是理想的方法,但它可以工作. 我做了以下操作来解决这个问题-

I faced this issue as well. This is probably not the ideal way, but it works. I did the following to resolve this -

sudo apt-get install python3-gdbm

这将为python3安装gdbm库,但是由于apt-get和anaconda是两个独立的程序包管理器;这不会解决您的问题.我们这样做主要是为了保留.so共享库,我们将把它们放在anaconda安装中的正确文件夹中.接下来,我们使用-

This installs the gdbm library for python3, however since apt-get and anaconda are two independent package managers; this isn't going to solve your problem. We primarily do this to get a hold of the .so shared library which we will place in the right folder in our anaconda installation. Next we find the location of the .so file using -

dpkg -L python3-gdbm

这将为我们提供以下输出-

This gives us the following output -

/. /usr /usr/lib /usr/lib/python3.5 /usr/lib/python3.5/lib-dynload /usr/lib/python3.5/lib-dynload/_gdbm.cpython-35m-x86_64-linux-gnu.so /usr/share /usr/share/doc /usr/share/doc/python3-gdbm /usr/share/doc/python3-gdbm/copyright /usr/share/doc/python3-gdbm/changelog.Debian.gz /usr/share/doc/python3-gdbm/README.Debian

我们需要的文件在这里-

The file we require is here -

/usr/lib/python3.5/lib-dynload/_gdbm.cpython-35m-x86_64-linux-gnu.so

将此文件复制到anaconda安装的lib-dynload文件夹中;对我来说是-

Copy this file to the lib-dynload folder of your anaconda installation; for me this was -

cp /usr/lib/python3.5/lib-dynload/_gdbm.cpython-35m-x86_64-linux-gnu.so /home/username/anaconda3/lib/python3.5/lib-dynload

请注意,这仅在将.so复制到的目录位于python的sys.path中时才有效.假设您处于激活的conda环境中,要查找要复制到的正确目录,请运行:

Note, that this will only work if the directory the .so was copied to is in python's sys.path. To find the correct directory to copy to, assuming you're inside the activated conda environment, run:

python -c 'import sys; [print(x) for x in sys.path if "lib-dynload" in x]'

例如,在我的情况下,该目录位于环境路径内,而不位于anaconda主库中. ~/anaconda3/envs/myenvname/lib/python3.7/lib-dynload

For example, in my case, the directory was inside the environment path and not in the anaconda main library. ~/anaconda3/envs/myenvname/lib/python3.7/lib-dynload

现在尝试在python中导入模块-

Now try importing the module in python -

from _gdbm import *

或从命令行对其进行测试:

or testing it from the command line:

python -m dbm.gnu

这应该已经解决了您的问题.

This should have fixed your problem.

请注意,我的是Ubuntu-16.06操作系统,我的python版本是3.5.2. .so文件也可以与python3.6一起使用,如果不能,则可以尝试安装python3.6-gdbm,尽管快速搜索ubuntu 16.04并没有任何结果.

Please note, mine is an Ubuntu-16.06 OS and my python version is 3.5.2. The .so file may work with python3.6 as well, if not you can try installing python3.6-gdbm, although a quick search for ubuntu 16.04 didn't give me any results.

更多推荐

GDBM不适用于Python 3.6和anaconda

本文发布于:2023-07-04 06:39:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1019759.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不适用于   GDBM   Python   anaconda

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!