ImportError: No module named 'pysqlite2' when running tests in Python 3 Ubuntu

后端 未结 2 602
遇见更好的自我
遇见更好的自我 2021-01-04 22:01

Some background: we have a codebase written in Python 3 that uses Pyramid and the SqlAlchemy ORM to persist to a mysql database. To write tests for our classes using the ORM

相关标签:
2条回答
  • 2021-01-04 22:28

    Running Debian Buster, I discovered the same problem with python3.6, even though, python3.5 successfully imported sqlite3. And even though the sqlite3 module was installed and should have been available to python3.6. My solution was to run

    export PYTHONPATH=$PYTHONPATH:/usr/lib/python3.6/lib-dynload
    

    For some reason I have not yet determined, the module directory for python3.6 does not get loaded correctly for sqlite3. This solution worked both inside and outside of virtual environments.

    0 讨论(0)
  • 2021-01-04 22:42

    You are missing the sqlite3 Python module, which you can verify with:

    bin/python -c 'import sqlite3'
    

    The which sqlite3 command only shows you have the sqlite3 command line tool installed; this is not what Python uses. It uses the libsqlite3 shared library (which the command line tool also uses). If missing, it means Python was not able to find the SQLite development headers when you built Python.

    On Ubuntu, you need to install libsqlite3-dev to get those headers.

    You may be missing other dependencies; on Ubuntu I'd install:

    libreadline6-dev
    libbz2-dev
    libssl-dev
    libsqlite3-dev
    libncursesw5-dev
    libffi-dev
    libdb-dev
    libexpat1-dev
    zlib1g-dev
    liblzma-dev
    libgdbm-dev
    libmpdec-dev
    

    Some of these are accelerator packages; Python will work without them but some modules will be slower (e.g. decimal without the mpdecimal library).

    You may want to verify the Ubuntu Python 3.4 source package dependencies for your Ubuntu version.

    0 讨论(0)
提交回复
热议问题