Search code examples
pythonvirtualenvpycharmberkeley-dbshelve

Pycharm with virtualenv, use Shelve module: No module named _bsddb


I receive the error "No module named _bsddb". I installed berkeley-db4 using Brew. I load up the virtualenv and use "pip install bsddb3 --install-option="--berkeley-db='/usr/local/opt/berkeley-db4'" but I can't get passed this in any way I can think of:

Collecting bsddb3
  Using cached bsddb3-6.1.1.tar.gz
    Complete output from command python setup.py egg_info:
    Can't find a local Berkeley DB installation.
    (suggestion: try the --berkeley-db=/path/to/bsddb option)

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/g6/j96dym1x0jx9ydrdkfs4dhnr0000gn/T/pip-build-676fDz/bsddb3

Solution

  • This is probably OS X only, because the shipped Python has something broken regarding berkeley-db and/or bsddb.

    The solution:

    1. Install brew and use brew to install python

    2. After this 'which python' should pount to '/usr/local/bin/python'

    3. Create a new virtualenv using Terminal OUTSIDE OF PYCHARM
    4. In Pycharm's Project Interpreter settings choose 'Add Local'
    5. Select the python bin inside your virtualenv directory