关于linux 安装 python pymssql模块
需要先安装freetds
是一个开源的C程序库,它可以实现在Linux系统下访问操作微软的SQL数据库。可以用在Sybase的db-lib或者ct-lib库,在里面也包含了一个ODBC的库。允许许多应用软件连接到Sybase或者微软的SQL服务器。
配置文件 默认安装在 /usr/local/etc/freetds.conf
[global]
# TDS protocol version
tds version = 7.0
client charset = UTF-8
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
; dump file = /tmp/freetds.log
; debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
# A typical Sybase server
[Server2012]
host = 10.20.17.102
port = 1433
tds version = 7.0
client charset = UTF-8
# A typical Microsoft server
[egServer70]
host = ntmachine.domain.com
port = 1433
tds version = 7.0
测试命令 tsql -S Server2012 -U sa (注意只能用配置文件配置的主机,不能直接写地址)
如果出现编码不一致的错误 尝试更改client charset
安装pymssql
测试代码
import pymssql
conn=pymssql.connect(host='10.20.17.102',database='webdata',user='sa',password='***',charset="cp936")
cur=conn.cursor()
cur.execute("SELECT TOP 10 * FROM sys_Codes")
for i in cur.fetchall():
print i
conn.close()
(pymssql 2.1.0 时读取数据库中文字符数据时报如下错(不知到是环境的原因还是版本的原因) )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pymssql.pyx", line 515, in pymssql.Cursor.fetchall (pymssql.c:8022)
File "pymssql.pyx", line 467, in pymssql.Cursor.getrow (pymssql.c:7035)
File "_mssql.pyx", line 418, in _mssql.MSSQLRowIterator.__next__ (_mssql.c:4317)
File "_mssql.pyx", line 1069, in _mssql.MSSQLConnection.fetch_next_row (_mssql.c:10650)
File "_mssql.pyx", line 1235, in _mssql.MSSQLConnection.get_row (_mssql.c:12131)
File "_mssql.pyx", line 758, in _mssql.MSSQLConnection.convert_db_value (_mssql.c:7762)
File "/usr/local/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc2 in position 0: invalid continuation byte
可以尝试将 charset参数设置为 cp936
如果程序使用sqlalchemy 读取数据 要在 create_engine时 的charset参数设置为 cp936,不是连接字符串的charset,后面传给pymssql
create_engine(self.conn_str,
connect_args={'charset':'cp936', 'appname': 'test', 'timeout': 10},
echo=False, convert_unicode=True,
pool_recycle=-1, pool_size=100, max_overflow=50)
SQLAlchemy 0.9.7 与SQLAlchemy0.8.x不兼容 (undefe()最新版中需要求传参数)
----------------------
pymssql 2.1.0 不兼容sql语句中文注释
pymssql-2.0.0b1-dev-20111019
关于linux 安装 python pymssql模块的更多相关文章
- centos7 安装 Python netsnmp模块
由于模块的安装过程中有点艰难(其实挺简单,只是参照网上的教程很多都装不成功,花了很多时间...),所以记下来备忘. 先装一下python-devel 模块,执行命令 yum install pytho ...
- Linux 安装python爬虫框架 scrapy
Linux 安装python爬虫框架 scrapy http://scrapy.org/ Scrapy是python最好用的一个爬虫框架.要求: python2.7.x. 1. Ubuntu14.04 ...
- day4 linux安装python
linux 安装 python centos6 默认安装的是2.6,如果需要安装更高版本需要手动下载安装 下载源码包wget https://www.python.org/ftp/python/3.5 ...
- Linux 下 安装Python第三方模块工具箱pip,以及用pip安装的方法
下载文件 wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate 执行安装 python get-pip.py 可以做一个软连 ...
- linux 安装python,pip,
Linux下python升级步骤 http://www.cnblogs.com/lanxuezaipiao/archive/2012/10/21/2732864.html 在 https://www. ...
- linux安装python并安装pip
因为最近要在linux环境下进行python编程,所以就试着去安装了一下,但是网上关于python以及pip的安装说实话有点混乱,所以我今天就把前辈的经验再次总结一下,希望可以给大家提供帮助. pyt ...
- 安装python第三方模块
下载 第三方模块的下载地址:https://pypi.python.org/pypi 其他版本的第三方模块下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs ...
- 明明pip安装python的模块了,pycharm还是找不到的解决方案
以前pycharm的安装包和python的环境一直都不能融合在一起,到了今天才知道,原来他们都是有自己的工作环境的 自己的工作环境(虚拟解释器)和安装python的工作环境(基本解释器)不是一个环境, ...
- Linux 安装Python和Django
1.下载python源码包 网址: https://www.python.org/ 在Downloads中打开Source code 由于 Django1.11.15不兼容3.7版本的python 所 ...
随机推荐
- 地形混合shader
1.四个贴图混合 Shader "Custom/BlendTex_surface" { Properties { _RTexture("Red Channel Textu ...
- thinkPHP5.0的学习研究【序言】
2017年6月19日13:19:151.ThinkPHP V5.0——为API开发而设计的高性能框架2.ThinkPHP是一个免费开源的,快速.简单的面向对象的轻量级PHP开发框架,是为了敏捷WEB应 ...
- 在linux下解压缩 tar.gz文件
解压:tar -xzvf 文件名 压缩 tar czf xx.tar.gz xxxx文件名
- python查询IP地址所属地
1.linux命令行版 #!/usr/bin/python #-*- coding: utf-8 -*- import json import urllib import sys def get_da ...
- 低秩近似 low-rank approximation
- LigerUI隐藏列
frozen: true 加入这个属性,此列不会在页面显示
- 教你管理SQL数据库系列(1-4)
原文 教你管理 SQL Server 数据库(1)数据库的结构 http://bbs.51cto.com/thread-1084951-1.html教你管理 SQL Server 数据库(2)系统数 ...
- Linux改动hostname的两个办法
假设你想把主机名改为 linux的话.两中方法: 1. # hostname linux 这样改动了以后马上生效.可是重新启动后就没了 2. # vi /etc/sysconfig/network 改 ...
- 帝国cms数据表中文说明
本文介绍下,帝国cms中各数据表的用途,有需要的朋友,参考下吧. 帝国cms各数据表及用途说明. phome_ecms_infoclass_news 新闻采集规则记录表 phome_ecms_info ...
- rails 字符串 转化为 html
simple_format http://apidock.com/rails/v4.0.2/ActionView/Helpers/TextHelper/simple_format http://api ...