I'm using Berkeley DB in a python project, and I am wondering if I can make the libraries available to python without specifically installing berkeley DB.
How can you embed Berkeley DB in an application generally?
Has anyone done this with python and bsddb3?
You can't... at least not without installing something. You'd have to statically link BDB into the python interpreter. But, then you'd have a custom python binary you'd need to install.
Related
MySQLdb as I understand doesn't support Python 3. I've heard about PyMySQL as a replacement for this module. But how does it work in production environment?
Is there a big difference in speed between these two? I asking because I will be managing a very active webapp that needs to create entries in the database very often.
PyMySQL is a pure-python database connector for MySQL, and can be used as a drop-in replacement using the install_as_MySQLdb() function. As a pure-python implementation, it will have some more overhead than a connector that uses C code, but it is compatible with other versions of Python, such as Jython and PyPy.
At the time of writing, Django recommends to use the mysqlclient package on Python 3. This fork of MySQLdb is partially written in C for performance, and is compatible with Python 3.3+. You can install it using pip install mysqlclient. As a fork, it uses the same module name, so you only have to install it and Django will use it in its MySQL database engine.
There are Python libraries that allow to communicate with a database. Of course, to use these libraries there should be an installed and running database server on the computer (python cannot communicate with something that does not exist).
My question is whether the above written is applicable to the sqlite3 library. Can one say that this library does not need any database to be installed (and running) on the computer? Can one say that sqlite3 needs only a file system?
SQLite only needs a filesystem, yes, it is not a standalone server. Instead, SQLite is an embedded database. The whole database driver is contained in a shared library loaded together with the Python executable, as needed.
You do need to have the libsqlite3 shared library installed; Python itself only includes the Python integration for that library.
For Ubuntu, for example, you'd install the libsqlite3-0 package; but since the Python package already depends on this this is not something you need to worry about, usually. Mac OS X already comes with the shared library installed, and on Windows I believe the Python Windows installer bundles the library with it. The ActiveState Python Windows distribution certainly does, for example.
If you want to compile Python from source, you'll have to install (at the very least) the SQLite development headers to enable compilation of the sqlite3 package.
No, sqlite package is part of Python standard library and as soon as you have Python installed, you may use sqlite functionality.
MartijnPieters noted, the actual shared library is not technically part of Python (this was my a bit oversimplified answer) but comes as shared library, which has to be installed too.
Practically speaking, if you manage installing Python, you have the sqlite available for your Python code.
As OP asked for for a need to install sqlite separately, I will not speculate on how to install Python, which is not able to work with it.
I'm making an installation package which is to be used on windows and includes a sqlite3 database (which is not read-only).
When then package has been installed the sqlite3 database has become read-only for some reason. By the way, I'm using python 2.7.3 (with sqlite3 lib) to read/write from it.
My question is, is there away for me to unlock the sqlite database to become read/write through a python script, bat script, or the inno setup script perhaps?
Or is there a way for me to modify my inno setup script to keep the sqlite database from becoming read-only in the first place?
I've tried searching the forums and googling for an answer but haven't succeeded in finding one.
THanks in advance!
On Windows, anything inside the Program Files folder is meant to be read-only during normal use. Data files should be installed elsewhere. See here for more advice on where to put them:
Does Microsoft have a best practices document regarding the storage of App Data vs User Data on different Windows Platforms?
I'm creating an application using python and sqllite3. Are the users required to install sqllite manually?
How do I create the tables and do initialization while installing?
The sqlite3 module is part of the python standard library and shipped with python itself. Having sqlite installed is a requirement, but (at least on linux) package managers take care of installing sqlite (I can't say anything about windows here).
You can create your tables on the first run of your application. To make sure you're not trying to create them twice, use CREATE TABLE IF NOT EXISTS ... (cf. the docs) which will only create the table if it doesn't already exist.
I was using Python 2.6.5 to build my application, which came with sqlite3 3.5.9. Apparently though, as I found out in another question of mine, foreign key support wasn't introduced in sqlite3 until version 3.6.19. However, Python 2.7 comes with sqlite3 3.6.21, so this work -- I decided I wanted to use foreign keys in my application, so I tried upgrading to python 2.7.
I'm using twisted, and I couldn't for the life of me get it to build. Twisted relies on zope.interface and I can't find zope.interface for python 2.7 -- I thought it might just "work" anyway, but I'd have to just copy all the files over myself, and get everything working myself, rather than just using the self-installing packages.
So I thought it might be wiser to just re-build python 2.6 and link it against a new version of sqlite3. But I don't know how--
How would I do this?
I have Visual Studio 2008 installed as a compiler, I read that that is the only one that is really supported for Windows, and I am running a 64 bit operating system
download the latest version of sqlite3.dll from sqlite website and replace the the sqlite3.dll in the python dir.
sqlite3 is not a built-in module; it's an extension module (the binary is C:\Python26\DLLs_sqlite3.pyd (on my machine)). A pyd is a DLL with a different filename extension and only 1 entry point. There's also a sqlite3.dll, which contains the SQLite code. python.exe is not linked against either of those, and thus rebuilding python.exe has no point.
The next idea is to go to the pysqlite2 download site, and get the latest Windows installer for Python 2.6. Unfortunately there's no docs about which version of SQLite it contains; one needs to install it and then muck about:
>>> import sqlite3 as standard
>>> from pysqlite2 import dbapi2 as latest
>>> for m in (standard, latest):
... print m.sqlite_version
...
3.5.9
3.6.2
>>>
So, it contains only SQLite version 3.6.2, which doesn't have the real foreign key support that you want.
I suggest that you check the mailing list to see if your question is answered there, and if not ask about the possibility of a Python 2.6 installer containing a later SQLite (e.g. the one included with Python 2.7).
I decided I'd just give this a shot when I realized that every library I've ever installed in python 2.6 resided in my site-packages folder. I just... copied site-packages to my 2.7 installation, and it works so far. This is by far the easiest route for me if this works -- I'll look further into it but at least I can continue to develop now.
I won't accept this answer, because it doesn't even answer my question, but it does solve my problem, as far as I can tell so far.