How to use sqlite3 in python on FreeBSD 10.3?

Nan Xiao nan at
Thu Jun 16 00:18:04 UTC 2016

Hi Dean, Eir, and all,

Thanks very much for your kind help and time!

After using "pkg info | grep py", I find I have installed "databases/sqlite3" not "databases/py-sqlite3"! 

I am very sorry for my stupid fault, anyway, thanks very much for all help again!

Best Regards
Nan Xiao (肖楠)
Skype: xiaonan19830818
Jabber/XMPP: nanxiao at 
Telegram: nanxiao
Personal website (Chinese): 
Personal website (English): 
Chinese DTrace website: 
From: Dean E. Weimer
Date: 2016-06-15 20:56
To: Nan Xiao
CC: freebsd-questions; owner-freebsd-questions
Subject: Re: How to use sqlite3 in python on FreeBSD 10.3?
On 2016-06-15 5:32 am, Nan Xiao wrote:
> Hi all,
> Greetings from me! I am a newbie of FreeBSD, and want to use sqlite3
> in python on my FreeBSD 10.3. After installing python, it prompts I
> should install the following additional packages:
> ......
> ===========================================================================
> Note that some standard Python modules are provided as separate ports
> as they require additional dependencies. They are available as:
> bsddb           databases/py-bsddb
> gdbm            databases/py-gdbm
> sqlite3         databases/py-sqlite3
> tkinter         x11-toolkits/py-tkinter
> ===========================================================================
> From this post, it seems after installing above 4 packages, the
> sqlite3 should be able to work. But "impore sqlite3" still reports
> following errors:
>>>> import sqlite3
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/local/lib/python2.7/sqlite3/", line 24, in 
> <module>
>     from dbapi2 import *
>   File "/usr/local/lib/python2.7/sqlite3/", line 28, in 
> <module>
>     from _sqlite3 import *
> ImportError: No module named _sqlite3
> Could anyone help on this issue? Thanks very much in advance!
> Have a nice day!
> P.S., I also submit this issue on SO, but unfortunately, I can't get
> any help from there, so I repost the question here, thanks!
use "pkg info | grep py" and verify that the packages did install 
correctly, from one of my systems running Python with py-sqlite3, it 
works fine. I am running WeeWX on this system which even though I am 
using mySQL for most of the data, it still has some dependency on 
sqlite3, so not only does it import, but I have applications using 
pkg info | grep py
py27-Babel-2.3.4               Collection of tools for 
internationalizing Python applications
py27-Jinja2-2.8                Fast and easy to use stand-alone template 
py27-MarkupSafe-0.23           Implements XML/HTML/XHTML Markup safe 
string for Python
py27-MySQLdb56-1.2.5           Access a MySQL database through Python
py27-alabaster-0.7.6           Modified Kr Sphinx theme
py27-cheetah-2.4.4_1           HTML template engine for Python
py27-configobj-5.0.6_1         Simple but powerful config file reader 
and writer
py27-dnspython-1.12.0          DNS toolkit for Python
py27-docutils-0.12             Python Documentation Utilities
py27-imagesize-0.7.1           Python image size library
py27-markdown-2.6.5            Python implementation of Markdown
py27-pillow-3.1.1_1            Fork of the Python Imaging Library (PIL)
py27-pip-8.0.2                 Tool for installing and managing Python 
py27-pycurl-7.21.5             Python interface to libcurl
py27-pygments-2.1.3            Syntax highlighter written in Python
py27-pystemmer-1.3.0_1         Snowball Stemming Algorithms for 
Information Retrieval
py27-pytz-2016.4,1             World Timezone Definitions for Python
py27-setuptools27-20.0         Python packages installer
py27-six-1.10.0                Python 2 and 3 compatibility utilities
py27-snowballstemmer-1.2.0_1   Snowball stemming library collection for 
py27-sphinx-1.4.1              Python documentation generator
py27-sphinx_rtd_theme-0.1.9    Mobile-friendly py-sphinx theme
py27-sqlite3-2.7.11_7          Standard Python binding to the SQLite3 
library (Python 2.7)
py27-tkinter-2.7.11_6          Python bindings to the Tk widget set 
(Python 2.7)
py27-usb-1.0.0b1_1             Python wrapper around libusb
pyephem-,1              Scientific-grade astronomical 
computations for Python
python-2.7_2,2                 The "meta-port" for the default version 
of Python interpreter
python2-2_3                    The "meta-port" for version 2 of the 
Python interpreter
python27-2.7.11_2              Interpreted object-oriented programming 
python3-3_3                    The "meta-port" for version 3 of the 
Python interpreter
python34-3.4.4_2               Interpreted object-oriented programming 
root at weewx:/ # python
Python 2.7.11 (default, Jun 10 2016, 09:38:24)
[GCC 4.2.1 Compatible FreeBSD Clang 3.4.1 (tags/RELEASE_34/dot1-final 
208032)] on freebsd10
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
make sure that the py27_sqlite3 or py34-sqlite3 depending on which you 
are trying to use is installed. I have Python 2.7 set as system default 
do to some requirements on the software. But also have Python 3.4 
installed for some custom system maintenance scripts I have written, 
those fortunately don't require any other python dependencies so it 
seems to work OK having both installed.
    Dean E. Weimer

More information about the freebsd-questions mailing list