Can't change system default SQLite binary - python

Using Django and SQLite I want to run most recent SQLite version; most recent SQLite binary, not the SQLite Python library. I have an SQLite binary that is not the system default and can't change the default version.
I'm not using Django's ORM but replaced it with a standalone SQLAlchemy version. Related (but has to do with running the most recent Python SQLite library).

The simplest option if you just need a recent version of SQLite from python is now to install the pysqlite3 package:
pip install pysqlite3-binary
This comes with a recent version of SQLite statically-linked. You can use it in a venv without affecting any other package.
You can use it like this:
from pysqlite3 import dbapi2 as sqlite3
print(sqlite3.sqlite_version)
If you happen to be using peewee, it will pick it up automatically.
If you need a specific version of SQLite, you can build this package, as suggested in Aaron Digulla's answer.

Python can't use the sqlite3 binary directly. It always uses a module which is linked against the sqlite3 shared library. That means you have to follow the instructions in "How to upgrade sqlite3 in python 2.7.3 inside a virtualenv?" to create a version of the pysqlite module in your virtualenv.
You can then use this import
from pysqlite2 import dbapi2 as sqlite
to shadow the system's default sqlite module with the new one.
Another option would be to get Python's source code, compile everything and copy the file sqlite.so into your virtualenv. The drawback of this approach is that it's brittle and hard to repeat by other people.

Try this easy route first if you're on windows: grab the dll from the sqlite download page (it will be under the "Precompiled Binaries for Windows" heading) and add it to Anaconda's dll path (like C:\Users\YourUserName\Anaconda3\DLLs). The new versions there come with goodies like FTS5 already enabled.
If you're on Linux, then refer to Install Python and Sqlite from Source and Compiling SQLite for use with Python Applications

Related

Python: pip looking in the wrong folder

Short version of the question: How can I get pip to install pyodbc in my Python 3.6 folder instead of seeing that it already exists in my 3.5 folder?
Because we have customers with various versions of Python, I have various versions on my computer. Also, we have been using the ancient adodb provider via COM, and using the win32com package to talk to it. Therefore, we have been using 32-bit versions of Python.
A new customer requires that we write to their Oracle database. They installed an Oracle ODBC driver in their server. However, it's a 64-bit ODBC driver, and when we run 32-bit Python, the driver will not be found.
A couple of years ago, I wrote a set of database wrapper classes based on adodb (and therefore on win32com) to meet our specific needs. I recently learned about pyodbc, and rewrote those classes to use pyodbc and remove reliance on adodb and win32com.
For this customer, I would like to use my new pyodbc classes. I tried to use pip to install pyodbc in my Python 3.6 installation, but it told me that the requirement is already satisfied because I have pyodbc in my Python 3.5 installation. I can copy it into 3.6, but I'd like to be able to use pip. What do I need to do?
Thank you.

Python3 connecting to MSSQL

I am writing Python3 and we have a database(mssql).
I have some strings and want to put these strings into db table. But I could not handle connecting to DB. Some people suggested using pyodbc but my python version is 3.4.4 and pyodbc is not supporting it. I am writing my codes in PyCharm IDE and I am not using anyother IDE such as Visual Studio, Eclipse, etc. DB is created and the table exists.
Which programs or libraries do I need?
Which lines that I should write to code (like import pypmssql)
Language: Python3 version 3.4.4
IDE: PyCharm latest version
DB: MSSQL
If you work on a Linux distribution, try to install pip3 (python dependency manager for python 3) then run
pip install pymssql
Then read the library documention to learn how to use it at http://pymssql.org/en/latest/

How do I install and use MySQLdb for Python 3 on Windows 10?

My various searches seem to come up with very old posts or a mention of how to do this under cygwin. I had python 3.5 installed and then installed Anaconda3. I have python 3.5 (Cpython) installed in my user directory. I tried changing the order of how things appear in my Windows Environment Variables path, so that I could try both the Anaconda version of Python and the other version of python that I have.
Currently, I am a bit confused as to the package name that I should use. Is it python-mysqldb, or MySQLdb, or mysqldb, mysqlclient. I believe that when I had Anaconda3 in my global path (and the other version of python in my user path), I was able to install mysqlclient.
Initially, I am just trying to follow a tutorial from a training site that covers databases and uses peewee.
So, can the mysql driver for peewee be installed for python3? Or on Windows specifically?
It is easy enough to use sqlite3, one doesn't use that in production, is that right?
Can someone help me? Provide some guidance?
Also, one source of confusion is when other forms of installation of a python package are listed in the google results (many point to stack overflow), such as using easy_install, or cloning something from git. When I see instructions that are from 2010 and they reference easy_install, I had been thinking that now we can just use pip instead? Also, sometimes I see use of the conda command. Does that work the same as pip?
Thanks in advance,
Bruce
You could use pymysql. "The goal of PyMySQL is to be a drop-in replacement for MySQLdb". Check the docs here. Install the following libraries
pip install mysqlclient pymysql
Once these libraries are installed, just add the lines in the manage.py file in your project and use the database settings for mysql.
import pymysql
pymysql.install_as_MySQLdb()
Now any files that import MySQLdb will work.

python installation can't find psycopg2 ImportError

I'm calling on psycopg2 with
import psycopg2
I get the std error
ImportError: No module named psycopg2
I installed my copy with macports, so I'm curious why it wouldn't work because all of the dependencies should be downloaded as well.
I don't have any experience with Postgresql, nor this module, so I don't know what could be going wrong. Fact is, another project I'm trying to get built calls upon it, so if I could avoid using this I would. :)
I'm sure that postgresql is installed, but that has little to do with the fact that my installation can't find psycopg2. Any suggestinos would be appreciated.
$ which python
reveals
/Library/Frameworks/Python.framework/Versions/Current/bin/python
and
$ python --version
reveals
Python 2.7.3 -- EPD_free 7.3-2 (32-bit)
I don't necessarily want the version of EPD_free, but I had to install it for (somewhat) unrelated reasons.
MacPorts installs its own version of Python alongside Apple's version. You can manage the active version of Python (the one that gets run when you type in python at the command line or by /usr/bin/env) by using the port select command. See this question.

Python pysqlite2 dbapi2 problem

I'm having an issue with the line:
from pysqlite2 import dbapi2 as sqlite
The error i'm getting is:
ImportError: /usr/lib/python2.4/site-packages/pysqlite2/_sqlite.so: undefined symbol: sqlite3_enable_shared_cache
What can I do to solve this problem?
Thanks!
Sounds like _sqlite.so was compiled against a newer version of sqlite than you have installed. That function wasn't added to SQLite's API until version 3.5.0.
The easiest way around this problem is to get the AS package Python 2.6 or later from Activestate and install that. It comes with SQLITE in the standard library.
The AS package is a tarball and you install it in a user directory by running a shell script after unpacking the archive. This does not touch any of the Python bits installed with your system, and gives you a fully controlled Python environment that is easy to replicate on other systems regardless of the distro.
Python's packaging system doesn't interoperate well with Linux distro package systems, especially because the Linux distros can be considerably out of date.

Categories