python3 ImportError: No module named mysql.connector return file_list.read().decode(“utf-8”).split(u“
”)
尝试在python 3.2.3上导入python-mysql.connector并接收奇数堆栈。我怀疑我的Ubuntu 12.04安装中配置不正确。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | vfi@ubuntu:/usr/share/pyshared$ python3 Python 3.2.3 (default, Sep 25 2013, 18:22:43) [GCC 4.6.3] on linux2 Type"help","copyright","credits" or"license" for more information. >>> import mysql.connector Traceback (most recent call last): File"", line 1, in ImportError: No module named mysql.connector Error in sys.excepthook: Traceback (most recent call last): File"/usr/share/pyshared/apport_python_hook.py", line 66, in apport_excepthook from apport.fileutils import likely_packaged, get_recent_crashes File"apport/__init__.py", line 1, in from apport.report import Report File"apport/report.py", line 20, in import apport.fileutils File"apport/fileutils.py", line 22, in from apport.packaging_impl import impl as packaging File"apport/packaging_impl.py", line 20, in import apt File"apt/__init__.py", line 24, in from apt.package import Package File"apt/package.py", line 1051 return file_list.read().decode("utf-8").split(u" ") ^ SyntaxError: invalid syntax Original exception was: Traceback (most recent call last): File"", line 1, in ImportError: No module named mysql.connector |
以下是我的电脑上的相关模块状态:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | vfi@ubuntu:/usr/share/pyshared$ sudo aptitude search python3-apt i python3-apt - Python 3 interface to libapt-pkg p python3-apt:i386 - Python 3 interface to libapt-pkg p python3-apt-dbg - Python 3 interface to libapt-pkg (debug extension) p python3-apt-dbg:i386 - Python 3 interface to libapt-pkg (debug extension) v python3-apt-dbg:any - v python3-apt-dbg:any:i386 - v python3-apt:any - v python3-apt:any:i386 - vfi@ubuntu:/usr/share/pyshared$ sudo aptitude search python-apt i python-apt - Python interface to libapt-pkg p python-apt:i386 - Python interface to libapt-pkg i python-apt-common - Python interface to libapt-pkg (locales) p python-apt-dbg - Python interface to libapt-pkg (debug extension) p python-apt-dbg:i386 - Python interface to libapt-pkg (debug extension) v python-apt-dbg:any - v python-apt-dbg:any:i386 - p python-apt-dev - Python interface to libapt-pkg (development files) p python-apt-doc - Python interface to libapt-pkg (API documentation) v python-apt-p2p - v python-apt-p2p-khashmir - v python-apt:any - v python-apt:any:i386 - i python-aptdaemon - Python module for the server and client of aptdaemon p python-aptdaemon-gtk - Transitional dummy package i python-aptdaemon.gtk3widgets - Python GTK+ 3 widgets to run an aptdaemon client p python-aptdaemon.gtkwidgets - Python GTK+ 2 widgets to run an aptdaemon client i python-aptdaemon.pkcompat - PackageKit compatibilty for AptDaemon p python-aptdaemon.test - Test environment for aptdaemon clients vfi@ubuntu:/usr/share/pyshared$ sudo aptitude search python-mysql.connector pi python-mysql.connector - pure Python implementation of MySQL Client/Server protocol |
号
希望你能帮忙!
谢谢
终于明白了我的问题所在。
python-mysql.connector不是一个py3包,apt-get和aptitude都没有提出这样的版本。
我设法用pip3安装它,这在Ubuntu12.04上不是那么简单,因为它只与Ubuntu捆绑在一起,从12.10开始,包在pip下没有相同的名称…
1 2 3 4 5 6 7 | vfi@ubuntu:$sudo apt-get install python3-setuptools vfi@ubuntu:$sudo easy_install3 pip vfi@ubuntu:$ pip --version pip 1.4.1 from /usr/local/lib/python3.2/dist-packages/pip-1.4.1-py3.2.egg (python 3.2) vfi@ubuntu:$sudo pip install mysql-connector-python |
这在Centos 6.5上对我有用
1 | sudo yum install mysql-connector-python |
号