简体   繁体   English

在macOS上将dbm.gnu用于Python 3.6.8

[英]Using dbm.gnu for Python 3.6.8 on macOS

I am having some problems using dbm.gnu for Python 3.6.8 on macOS. 在macOS上将dbm.gnu用于Python 3.6.8时遇到一些问题。 I have installed gdbm in my Python virtual environment with conda... but I got the following error message when trying to invoke dbm.gnu: 我已经在conda的Python虚拟环境中安装了gdbm ...,但是在尝试调用dbm.gnu时收到以下错误消息:

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-2-11fcf8fc693c> in <module>
      1 # Downloads the HI data in a fits file format
      2 hi_datafile = download_file('http://cdsarc.u-strasbg.fr/vizier/ftp/cats/J/A+A/594/A116/CUBES/GAL/TAN/TAN_C14.fits',
----> 3                             cache = True, show_progress = True)

/anaconda3/envs/py36-stable/lib/python3.6/site-packages/astropy/utils/data.py in download_file(remote_url, cache, show_progress, timeout)
   1010         if cache:
   1011             # We don't need to acquire the lock here, since we are only reading
-> 1012             with shelve.open(urlmapfn) as url2hash:
   1013                 if url_key in url2hash:
   1014                     return url2hash[url_key]

/anaconda3/envs/py36-stable/lib/python3.6/shelve.py in open(filename, flag, protocol, writeback)
    241     """
    242 
--> 243     return DbfilenameShelf(filename, flag, protocol, writeback)

/anaconda3/envs/py36-stable/lib/python3.6/shelve.py in __init__(self, filename, flag, protocol, writeback)
    225     def __init__(self, filename, flag='c', protocol=None, writeback=False):
    226         import dbm
--> 227         Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
    228 
    229 

/anaconda3/envs/py36-stable/lib/python3.6/dbm/__init__.py in open(file, flag, mode)
     89     elif result not in _modules:
     90         raise error[0]("db type is {0}, but the module is not "
---> 91                        "available".format(result))
     92     else:
     93         mod = _modules[result]

error: db type is dbm.gnu, but the module is not available

Is there any reliable way to make it work? 有什么可靠的方法可以使它工作? I can turn off cache by setting cache = False when calling download_file from astropy... But I really would want to set cache = True . 我可以通过从astropy调用download_file时通过设置cache = False来关闭缓存。但是我真的想设置cache = True Any help would be much appreciated. 任何帮助将非常感激。

So I ended up with doing something inadvisable but works, which was to change the only line in "/anaconda3/envs/py36-stable/lib/python3.6/dbm/gnu.py" from 因此,我最终做了一些不可取的但可行的事情,那就是将“ /anaconda3/envs/py36-stable/lib/python3.6/dbm/gnu.py”中的唯一一行更改为

from _gdbm import *

to

from _dbm import *

... That did the trick for me. ...对我来说成功了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM