用 Jython 安装 Pyodbc?

installing Pyodbc with Jython?

平台:Windows7(64 位),Jython 版本 2.7.10"final release"。
当前使用 java.sql 类 访问 MS Access 数据库。

将来某个时候我想搬到 Linux。将来某个时候我想搬到 MySQL/MariaDB...

我认为使用更 Pythonic 的方式会很好,而且 Pyodbc 似乎是可行的方式。

这是我尝试使用 pip 安装它:

D:\apps\jython2.7.0\bin>pip install pyodbc
Downloading/unpacking pyodbc
  Downloading pyodbc-3.0.10.tar.gz (68kB): 68kB downloaded
  Running setup.py (path:C:\Users\Chris\AppData\Local\Temp\pip_build_Chris\pyodb
c\setup.py) egg_info for package pyodbc

    warning: no files found matching 'tests\*'
    warning: no files found matching 'README.rst'
Installing collected packages: pyodbc
  Running setup.py install for pyodbc
    building 'pyodbc' extension
    error: Compiling extensions is not supported on Jython
    Complete output from command D:\apps\jython2.7.0\bin\jython.exe -c "import s
etuptools, tokenize;__file__='C:\Users\Chris\AppData\Local\Temp\pip_build_
Chris\pyodbc\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).
read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Chri
s\AppData\Local\Temp\pip-xb4a39-record\install-record.txt --single-version-exter
nally-managed --compile:
    running install

running build

running build_ext

building 'pyodbc' extension

error: Compiling extensions is not supported on Jython

----------------------------------------
Cleaning up...
←[31mCommand "D:\apps\jython2.7.0\bin\jython.exe -c "import setuptools, tokenize
;__file__='C:\Users\Chris\AppData\Local\Temp\pip_build_Chris\pyodbc\setu
p.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\
n', '\n'), __file__, 'exec'))" install --record C:\Users\Chris\AppData\Local\Tem
p\pip-xb4a39-record\install-record.txt --single-version-externally-managed --com
pile" failed with error code 1 in C:\Users\Chris\AppData\Local\Temp\pip_build_Ch
ris\pyodbc
←[0m←[31mStoring debug log for failure in C:\Users\Chris\.pip\pip.log
←[0m
D:\apps\jython2.7.0\bin>

有人知道这是否可以 remedied/worked 吗?
有人对使用 Jython 的 Pythonic 访问数据库有替代建议吗?

由于您是 运行 Jython,因此您处于 Java 世界。那将是 JDBC; ODBC 适用于 C (CPython) 世界中的项目。除了使用 pyodbc,你还需要这个:

http://www.jython.org/archive/21/docs/zxjdbc.html

pyodbc 将无法工作,除非您使用 CPython("standard default" 版本)。您使用 Jython 有什么特别的原因吗?大多数人只有在确实需要 JVM 或特定的 JAR/WAR 时才使用它。

当您移动到 ​​Linux 时,您将不再有可用的 Microsoft Access ODBC 驱动程序(仅 Windows)。在非 Windows 平台上使用 Access 数据库还有其他 ODBC 选项,但它们可能不太理想。

对于真正的跨平台解决方案,您可以将 Jython 与 UCanAccess JDBC 驱动程序一起使用,如此处另一个答案中所述:

Read an Access database in Python on non-Windows platform (Linux or Mac)