2

I'm trying to get the pymysql module working with python3 on a Macintosh. Note that I am a beginning python user who decided to switch from ruby and am trying to build a simple (sigh) database project to drive my learning python.

In a simple (I thought) test program, I am getting a syntax error in confiparser.py (which is used by the pymysql module)

def __init__(self, defaults=None, dict_type=_default_dict,
             allow_no_value=False, *, delimiters=('=', ':'),
             comment_prefixes=('#', ';'), inline_comment_prefixes=None,
             strict=True, empty_lines_in_values=True,
             default_section=DEFAULTSECT,
             interpolation=_UNSET):

According to Komodo, the error is on the second line. I assume it is related to the asterix but regardless, I don't know why there would be a problem like this with a standard Python module.

Anyone seen this before?

David
  • 5,991
  • 5
  • 33
  • 39
  • Where did you get the pymysql module from and how are you running Python? Anything official ought to work and `*` is perfectly valid in Python 3 but not in 2, so perhaps you're just using the wrong version or got your import paths mixed up. –  May 24 '11 at 20:47
  • Wow --- thanks for quick response --- as far as I know (but I will verify), I am running python 3.2 on my Mac through the Komodo IDE. Your comment about the * being valid in 3 but not 2 is clearly an important hint about the probable cause. By the way, the pymysql came from http://code.google.com/p/pymysql/ – David May 24 '11 at 20:50
  • `import sys; print (sys.version)` (before the imports) would be a simple and relatively failsafe way to confirm the script is in fact executed with Python 3. –  May 24 '11 at 20:53
  • Sigh, you're dead right --- Komodo seems to be running the python 2 interpreter even though I have it configured (supposedly) to be running python 3. I'll go hunt that down, and many thanks for your instant response. I don't know how to mark your comment as the accepted answer. – David May 24 '11 at 20:56
  • Comments can't be accepted, answers can. I summarized the comments into an answer. –  May 24 '11 at 20:59

2 Answers2

3

You're most certainly running the code with a 2.x interpreter. I wonder why it even tries to import 3.x libraries, perhaps the answer lies in your installation process - but that's a different question. Anyway, this (before any other imports)

import sys
print(sys.version)

should show which Python version is actually run, as Komodo Edit may be choosing the wrong executable for whatever reason. Alternatively, leave out the parens and it simply fails if run with Python 3.

  • The mechanism for controlling whether Komodo runs with python3 or python2 is rather obscure. But in case anyone else has that issue, please see http://community.activestate.com/forum/howto-set-python-version-project-komodo-ide-6x – David May 24 '11 at 21:04
1

In Python 3.2 the configparser module does indeed look that way. Importing it works fine from Python 3.2, but not from Python 2.

Am I right in guessing you get the error when you try to run your module with Komodo? Then you just have configured the wrong Python executable.

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251