python -m pip install leveldb 如果成功,那就什么都不用管了 我在centos 上用这个命令直接安装成功
pip install leveldb
失败的解决办法
-
编译安装,编译安装比较麻烦,我也没有试过,下面是别人的经验 Windows上编译安装py-leveldb
-
直接将编译好的放入即可 Python2.7: Google Drive, Baidu Yun
Python3.6: Google Drive, Baidu Yun
上面对应的版本自己对号入座! 下载的安装包里面 有个文件 leveldb.pyd,将这个文件放入 你的环境/Lib/site-packages 文件夹中就好了
import leveldb
db = leveldb.LevelDB('./db')
# single put
db.Put(b'hello', b'hello world')
print(db.Get(b'hello').decode('utf-8'))
# multiple put/delete applied atomically, and committed to disk
batch = leveldb.WriteBatch()
batch.Put(b'hello', b'world')
batch.Put(b'hello again', b'world')
batch.Delete(b'hello')
db.Write(batch, sync = True)
上面是测试代码,直接运行,如果输出是hello world 那就没问题了
为了避免误人子弟,我吧原本的地址也给大家 py-leveldb-windows
如果需要 leveldb 编译的文件 点击这里leveldb 编译的文件 如果没有会员,可以找我要文件
微信号:xuanfengmodi