当前位置:首页 » 编程语言 » mysqlforpython27

mysqlforpython27

发布时间: 2022-09-13 15:30:32

1. mysql5.7.12可以和python2.7兼容吗

这两个完全兼容,没问题的。

python连接mysql常用的库如下:
1,mysql-python也就是MySQLdb;
2,PyMySQL。支持jython,IronPython,CPython等;
3,MySQL Connector/Python。纯python实现的MySQL接口,由Oracle维护;

2. python2.7中如果脚本文件放在中文目录下,pymysql连接数据库会报错,怎么解决(不要修改中文目录名为英文)

解决方法为:

创建数据表时指定charset=utf8,如:

usehongxiudb;
createtableifnotexistshongxiu(
nametext,
authortext,
introtext
)engine=InnoDBdefaultcharset=utf8;

3. 如何安装python的MySQLdb模块

到官方下载MySQL for Python

然后解压,打开README:

里面有安装过程:

$tarxfzMySQL-python-1.2.1.tar.gz
$cdMySQL-python-1.2.1
$#editsite.cfgifnecessary
$pythonsetup.pybuild
$sudopythonsetup.pyinstall#orsufirst

不过在python setup.py build时报错:

ImportError: No mole named setuptools

ubuntu下安装:

sudo apt-get install python-setuptools

python-setuptools : Python Distutils Enhancements (setuptools compatibility)

然后再次python setup.py build,又报错:

EnvironmentError: mysql_config not found

因为mysql_config是属于MySQL开发用的文件,而使用apt-get安装的MySQL是没有这个文件的,于是在包安装器里面寻找

sudo apt-get install libmysqld-dev

libmysqld-dev : MySQL embedded database development files

再次运行python setup.py build,报错:

building ‘_mysql’ extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,’final’,0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-i686-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
In file included from _mysql.c:29:0:
pymemcompat.h:10:20: fatal error: Python.h: No such file or directory

解决方案,

sudo apt-get install python-dev

python-dev : header files and a static library for Python (default)

然后就按照README里的:

$ python setup.py build
$ sudo python setup.py install

测试:

>>>import MySQLdb

没有报错即可。

4. python怎么安装mysqldb

在配置Django时,选择的是mysql数据库,要安装MySQLdb模块,不过安装过程中,遇到了很多errors,记录一下。
系统:ubuntu 11.10
mysql:直接apt-get安装的,version:5.1.62
到官方下载MySQL for Python
然后解压,打开README:
里面有安装过程:
tarxfzMySQL?python?1.2.1.tar.gz cd MySQL-python-1.2.1# edit site.cfg if necessary# edit site.cfg if necessary python setup.py build$ sudo python setup.py install # or su first不过在python setup.py build时报错:
ImportError: No mole named setuptools
ubuntu下安装:
sudo apt-get install python-setuptools
python-setuptools : Python Distutils Enhancements (setuptools compatibility)然后再次python setup.py build,又报错:
EnvironmentError: mysql_config not found
因为mysql_config是属于MySQL开发用的文件,而使用apt-get安装的MySQL是没有这个文件的,于是在包安装器里面寻找sudo apt-get install libmysqld-dev
libmysqld-dev : MySQL embedded database development files再次运行python setup.py build,报错:
building ‘_mysql’ extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,’final’,0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-i686-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUXIn file included from _mysql.c:29:0:
pymemcompat.h:10:20: fatal error: Python.h: No such file or directory解决方案,
sudo apt-get install python-dev
python-dev : header files and a static library for Python (default)然后就按照README里的:
pythonsetup.pybuild sudo python setup.py install测试:
>>>import MySQLdb
没有报错即可。

5. Python2.7安装mysql-python报错,求教

# script to register python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/procts/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/[email protected]/msg10512.html

import sys

from _winreg import *

# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix

regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
installpath, installpath, installpath
)

def RegisterPy():
try:
reg = OpenKey(HKEY_CURRENT_USER, regpath)
except EnvironmentError as e:
try:
reg = CreateKey(HKEY_CURRENT_USER, regpath)
SetValue(reg, installkey, REG_SZ, installpath)
SetValue(reg, pythonkey, REG_SZ, pythonpath)
CloseKey(reg)
except:
print "*** Unable to register!"
return
print "--- Python", version, "is now registered!"
return
if (QueryValue(reg, installkey) == installpath and
QueryValue(reg, pythonkey) == pythonpath):
CloseKey(reg)
print "=== Python", version, "is already registered!"
return
CloseKey(reg)
print "*** Unable to register!"
print "*** You probably have another Python installation!"

if __name__ == "__main__":
RegisterPy()

6. mac环境下安装mysql for python失败

你需要安装 Xcode 的 Command Line Tools 后才行。
下载地址 https://developer.apple.com/downloads/index.action
需要用 Apple Developer 帐号登录
同时要确保机器上安装的 mysql 时正常的,否则安装 MySQL-python 又会出现另一个错误

7. 如何在mac上安装mysql for python

在 Mac OS X 下安装 python-mysql方法如下:
1、先把之前装的卸载干净:
pip uninstall mysql-python
brew uninstall mysql-connector-c
2、现在设置下mysql_config路径:
首先修改系统配置文件vim ~/.bash_profile或者有些人是 ~/.profile,export PATH=$PATH:/Applications/MAMP/Library/bin
这里/Applications/MAMP/Library/bin是MAMP的mysql配置文件路径
3、安装brew install mysql-connector-cpip install mysql-python即可。

8. 如何用python的pip安装mysqldb

如何用python的pip安装mysqldb
python2.7和python3.4你可以看成是两个软件,你在一个里装了,另一个里当然不能用,你需要在python3.4里也安装mysqldb才可以,你可以通过pip install mysql-python,或者python3 setup.py install 来安装。

到官方下载MySQL for Python
然后解压,打开README:
里面有安装过程:
$ tar xfz MySQL-python-1.2.1.tar.gz
$ cd MySQL-python-1.2.1
$ # edit site.cfg if necessary
$ python setup.py build
$ sudo python setup.py install # or su first

9. mysql5.6支持python2.7吗

python 2.7是万能的,能不能支持要看你用的模块,目测pymysql 和mysqldb模块应该都是支持的

热点内容
手机怎样给程序加密软件 发布:2025-01-12 06:47:11 浏览:824
地平线最高画质笔记本要什么配置才能玩 发布:2025-01-12 06:47:10 浏览:369
原神过主线任务脚本 发布:2025-01-12 06:34:51 浏览:514
医保电子密码在哪里找到 发布:2025-01-12 06:34:38 浏览:349
安卓手机有网却不能使用怎么办 发布:2025-01-12 06:25:20 浏览:213
arm存储器映射 发布:2025-01-12 06:25:12 浏览:250
安卓系统个人字典有什么用 发布:2025-01-12 06:13:37 浏览:929
geventpython安装 发布:2025-01-12 06:13:34 浏览:339
放松解压助睡眠直播 发布:2025-01-12 06:13:00 浏览:829
车载wince和安卓哪个好用 发布:2025-01-12 05:58:18 浏览:840