Python 2 and Python 3 on the same maschine install MySQL Connector

Asked by George

Hello

I have a little question. I have FreeBSD 8 server, installed Python 2.7.3 and Python 3.3.0 on it.
Then I installed MySQL Connector/Python v 1.0.9 (from dev.mysql.com ) with instructions.

When i run Python 2 and use: "import mysql.connector", everything is ok. But with Python 3 i have an error:

>>> import mysql.connector
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./mysql/connector/__init__.py", line 33, in <module>
    from mysql.connector.connection import MySQLConnection
  File "./mysql/connector/connection.py", line 125
    except Exception, err:
                    ^
SyntaxError: invalid syntax

Can someone help to solve this issue? Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
MySQL Connector/Python Edit question
Assignee:
No assignee Edit question
Solved by:
George
Solved:
Last query:
Last reply:
Revision history for this message
George (omatic-hacker) said :
#1

I think MySQL Connector is not installing with Python 3.
I make default Python version in FreeBSD in /etc/make.conf

PYTHON_VERSION= 2.6
PYTHON_DEFAULT_VERSION= 2.6

but it didn't helped, i used command: python setup.py install -v

console output:

running install
running build
running build_py
running install_lib
running install_egg_info
Removing /usr/local/lib/python2.7/site-packages/mysql_connector_python-1.0.9-py2.7.egg-info
Writing /usr/local/lib/python2.7/site-packages/mysql_connector_python-1.0.9-py2.7.egg-info

Any ideas how to manually install connector to Python 3.3.0?

Revision history for this message
George (omatic-hacker) said :
#2

Sorry, there is mistake on my comment, i used:

PYTHON_VERSION= 3.3
PYTHON_DEFAULT_VERSION= 3.3

Revision history for this message
George (omatic-hacker) said :
#3

Ok, i try to install manually with Pyton3, command:

python3 setup.py install -v
running install
running build
running build_py
running install_lib
byte-compiling /usr/local/lib/python3.3/site-packages/mysql/connector/connection.py to connection.cpython-33.pyc
  File "/usr/local/lib/python3.3/site-packages/mysql/connector/connection.py", line 125
    except Exception, err:
                    ^
SyntaxError: invalid syntax

byte-compiling /usr/local/lib/python3.3/site-packages/mysql/connector/constants.py to constants.cpython-33.pyc
  File "/usr/local/lib/python3.3/site-packages/mysql/connector/constants.py", line 47
    raise TypeError, "Can not instanciate from %s" % cls.__name__
                   ^
SyntaxError: invalid syntax

byte-compiling /usr/local/lib/python3.3/site-packages/mysql/connector/conversion.py to conversion.cpython-33.pyc
  File "/usr/local/lib/python3.3/site-packages/mysql/connector/conversion.py", line 260
    except ValueError, e:
                     ^
SyntaxError: invalid syntax

byte-compiling /usr/local/lib/python3.3/site-packages/mysql/connector/cursor.py to cursor.cpython-33.pyc
  File "/usr/local/lib/python3.3/site-packages/mysql/connector/cursor.py", line 235
    except StandardError, e:
                        ^
SyntaxError: invalid syntax

byte-compiling /usr/local/lib/python3.3/site-packages/mysql/connector/errors.py to errors.cpython-33.pyc
  File "/usr/local/lib/python3.3/site-packages/mysql/connector/errors.py", line 148
    except Exception, err:
                    ^
SyntaxError: invalid syntax

byte-compiling /usr/local/lib/python3.3/site-packages/mysql/connector/network.py to network.cpython-33.pyc
  File "/usr/local/lib/python3.3/site-packages/mysql/connector/network.py", line 101
    except Exception, err:
                    ^
SyntaxError: invalid syntax

byte-compiling /usr/local/lib/python3.3/site-packages/mysql/connector/protocol.py to protocol.cpython-33.pyc
  File "/usr/local/lib/python3.3/site-packages/mysql/connector/protocol.py", line 49
    except Exception, err:
                    ^
SyntaxError: invalid syntax

byte-compiling /usr/local/lib/python3.3/site-packages/mysql/connector/utils.py to utils.cpython-33.pyc
  File "/usr/local/lib/python3.3/site-packages/mysql/connector/utils.py", line 87
    if i < 0 or i > 4294967295L:
                              ^
SyntaxError: invalid syntax

running install_egg_info
Removing /usr/local/lib/python3.3/site-packages/mysql_connector_python-1.0.9-py3.3.egg-info
Writing /usr/local/lib/python3.3/site-packages/mysql_connector_python-1.0.9-py3.3.egg-info

and also had errors...

Revision history for this message
Geert JM Vanderkelen (geertjmvdk) said :
#4

You will need to remove the build directory when you are installing Python v2 and 3. Otherwise Python will just install what was already build.

shell> python2 setup.py install
shell> rm -Rf build/ dist/
shell> python3 setup.py install

Revision history for this message
George (omatic-hacker) said :
#5

Thank's , I delete those, and /__pycache__ , mysql connector installed properly.