2013-04-14 240 views
16

我完全新的Python,當我嘗試導入bsdddb安裝bsddb包 - 蟒蛇

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bsddb/__init__.py", line 67, in <module> 
    import _bsddb 
ImportError: No module named _bsddb 

所以我也跟着thisthis我有這樣的消息,所以我下載了這個包bsddb3-4.5.0.tar.gz。我想用它做什麼,我試圖運行python install setup.py int在右側目錄(我使用的是osx)中的bsddb3-4.5.0。然後我得到

Can't find a local BerkeleyDB installation. 
(suggestion: try the --berkeley-db=/path/to/bsddb option) 

有人可以幫忙嗎?

回答

15

bsddb是deprecated since 2.6。理想的是使用the bsddb3 module

我的建議,是迄今爲止最簡單的選擇,就是安裝Homebrew並用它來獲取的BerkeleyDB您的系統上:

brew install berkeley-db 

使用pip

pip install bsddb3 

或下載此安裝bsddb3後source並正常安裝。

python setup.py install 
+7

直接安裝pip並不適合我,我只好進入bsddb3的源碼目錄並執行python setup.py install --berkeley-db = $(brew --prefix)/ berkeley-db /5.3.21/ –

+0

看起來它可能已經在brew中再次移動,擴展Chmouel的評論: 'python setup.py install --berkeley-db = \'find $(brew --prefix)/ */berkeley-db/5 * -name berk * \'' – Sean

+8

這對小牛使用Apple的'python'和Homebrew的'pip'和'berkeley-db'都有效(以root身份):'BERKELEYDB_DIR = $(brew --cellar) /berkeley-db/5.3.28 pip install bsddb3'(詳情請參閱http://chriszf.posthaven.com/getting-berkeleydb-working-with-python-on-osx) –

8

我也有類似的問題,但沒有任何的建議,工作對我來說,因爲我無法用AGPL許可證或從Oracle商業伯克利許可證。

BERKELEYDB_DIR=$(brew --cellar)/berkeley-db/6.1.26 pip install bsddb3 
Collecting bsddb3 
Using cached bsddb3-6.1.1.tar.gz 
Complete output from command python setup.py egg_info: 
Trying to use the Berkeley DB you specified... 
Detected Berkeley DB version 6.1 from db.h 

******* COMPILATION ABORTED ******* 

You are linking a Berkeley DB version licensed under AGPL3 or have a commercial license. 

AGPL3 is a strong copyleft license and derivative works must be equivalently licensed. 

You have two choices: 

    1. If your code is AGPL3 or you have a commercial Berkeley DB license from Oracle, please, define the environment variable 'YES_I_HAVE_THE_RIGHT_TO_USE_THIS_BERKELEY_DB_VERSION' to any value, and try to install this python library again. 

    2. In any other case, you have to link to a previous version of Berkeley DB. Remove Berlekey DB version 6.x and let this python library try to locate an older version of the Berkeley DB library in your system. Alternatively, you can define the environment variable 'BERKELEYDB_DIR', or 'BERKELEYDB_INCDIR' and 'BERKELEYDB_LIBDIR', with the path of the Berkeley DB you want to use and try to install this python library again. 

Sorry for the inconvenience. I am trying to protect you. 

More details: 

    https://forums.oracle.com/message/11184885 
    http://lists.debian.org/debian-legal/2013/07/ 

******* COMPILATION ABORTED ******* 

但是,回到舊版本修復它。

與沖泡安裝伯克利分貝的舊版本

brew install berkeley-db4

隨後的建議與PIP

pip install bsddb3

然後

BERKELEYDB_DIR=$(brew --cellar)/berkeley-db4/4.8.30 pip install bsddb3

安裝bsddb

(從斯特凡·施密特的評論修改引用老的Berkeley-DB version目錄)

最後申請描述here到dbhash.py補丁。

6

@bamdan的答案使用的Berkeley DB的舊版本,如果你仍然想使用最新,Berkeley DB的,

  • 首先,安裝最新的Berkeley DB

    pip install berkeley-db 
    
  • 二,設置一個環境變量YES_I_HAVE_THE_RIGHT_TO_USE_THIS_BERKELEY_DB_VERSION,表示您有執照

    BERKELEYDB_DIR=$(brew --cellar)/berkeley-db4/6.1.26 YES_I_HAVE_THE_RIGHT_TO_USE_THIS_BERKELEY_DB_VERSION=yes pip install bsddb3 
    
+0

版本不可知版本:'BERKELEYDB_DIR = $(brew --prefix berkeley-db)YES_I_HAVE_THE_RIGHT_TO_USE_THIS_BERKELEY_DB_VERSION = yes pip安裝bsddb3' –