如何使用 Python 3 访问 MS SQL Server?
我正在使用 Linux 机器制作一个小 python 程序,需要将其结果输入到 SQL Server 2000 DB 中。
我是 python 新手,所以我很难找到使用 python 3 连接到数据库的最佳解决方案,因为我看到的大多数库只能在 python 2 中工作。
作为一个额外的奖励问题,完成的该版本将使用 py2exe 编译为 Windows 程序。有什么我应该注意的吗?需要做出什么改变吗?
谢谢
I'm using a linux machine to make a little python program that needs to input its result in a SQL Server 2000 DB.
I'm new to python so I'm struggling quite a bit to find what's the best solution to connect to the DB using python 3, since most of the libs I looked only work in python 2.
As an added bonus question, the finished version of this will be compiled to a windows program using py2exe. Is there anything I should be aware of, any changes to make?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(3)
一种选择是尝试使用 pyodbc 分支 来支持 python 3。我想有些人已经报告成功了,但您可能想在pyodbc 讨论组中进行咨询。
如果您坚持使用 python 库的平台独立部分(大部分),那么在 Windows 上使用 py2exe 应该不会有任何问题。
One option would be trying the pyodbc branch for python 3 support. I think some people have reported success, but you might want to inquire at the pyodbc discussion group.
If you stick to platform independent parts of the python library (most of it), you shouldn't have any issues on windows with py2exe.
我无法直接回答您的问题,但考虑到许多流行的 Python 包和框架尚未在 Python 3 上完全支持,您可能会考虑仅使用 Python 2.x。当然,除非 Python 3 中有一些你绝对离不开的功能。
从您的帖子中并不清楚您是计划仅部署到 Windows,还是部署到 Windows 和 Linux。如果只是 Windows,那么您可能应该从 Windows 上开始开发:最新版本中包含本机 MSSQL 驱动程序,因此您无需安装任何额外的东西,并且它为您提供了更多选项,例如 adodbapi。
I can't answer your question directly, but given that many popular Python packages and frameworks are not yet fully supported on Python 3, you might consider just using Python 2.x. Unless there are features you absolutely cannot live without in Python 3, of course.
And it isn't clear from your post if you plan to deploy to Windows only, or Windows and Linux. If it's only Windows, then you should probably just develop on Windows to start with: the native MSSQL drivers are included in most recent versions so you don't have anything extra to install, and it gives you more options, such as adodbapi.
如果您想要可移植的 mssql 服务器库,您可以尝试 www.pytds.com 中的模块。它适用于 2.5+ AND 3.1,有良好的存储过程支持。它的 api 更加“实用”,并且具有一些在其他地方找不到的好功能。
If you want to have portable mssql server library, you can try the module from www.pytds.com. It works with 2.5+ AND 3.1, have a good stored procedure support. It's api is more "functional", and has some good features you won't find anywhere else.