FAQ
Hi.

I just installed the MySQLdb module and I have been able to get it to
run in my command line interpreter.

I am running Mac Leopard, and Python 2.5.

I have tested importing and actually connecting and using a MySQL
database, although it issues some warning:

SnakeBite:MySQL-python-1.2.2 Snake$ python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import MySQLdb
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg/_mysql.py:3:
UserWarning: Module _mysql was already imported from /Library/
Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/
MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg/_mysql.pyc, but /Library/
Python/MySQL-python-1.2.2 is being added to sys.path
import sys, pkg_resources, imp
>>>


However, while writing a .py script (with Komodo Edit) I try to simply
import the module and the in-Komodo interpreter returns an error:
Traceback (most recent call last):
File "/Users/Snake/Documents/NPS/Thesis/Source_Code/Genetics/
mysql_connect_test.py", line 11, in <module>
import MySQLdb
ImportError: No module named MySQLdb

This script does, however, run fine when I call it from the command-
line interpreter. I don't really know much about Paths or anything,
all I Know is that to get Komodo to run my Python scripts, I had to
tell it that an interpreter is located at /usr/bin/pythonw

My goal is to use Komodo (or some simple IDE with syntax checking, and
function hinting, and an embedded interpreter - so if you know of any
others for Mac Leopard) to write and debug scripts.

-Jake


# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# >>>>>
# >>>>> This file tests the connection to a mysql database
("gene_test") on localhost:3306
# >>>>> it gets all of the data from the table "3_weeks" and prints it
# >>>>>
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


# import MySQL module
import MySQLdb

# connect
db = MySQLdb.connect(host="localhost", user="customer",
passwd="customer", db="gene_test")

# create a cursor
cursor = db.cursor()

# execute SQL statement
cursor.execute("SELECT * FROM 3_weeks")

# get the resultset as a tuple
result = cursor.fetchall()

# iterate through resultset
for record in result:
print record[0] , "-->", record[1]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-list/attachments/20080402/6e286654/attachment.htm

Search Discussions

  • Trent Mick at Apr 3, 2008 at 5:54 pm

    Jacob Davis wrote:
    I just installed the MySQLdb module and I have been able to get it to
    run in my command line interpreter.

    I am running Mac Leopard, and Python 2.5.

    I have tested importing and actually connecting and using a MySQL
    database, although it issues some warning:

    SnakeBite:MySQL-python-1.2.2 Snake$ python
    Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
    [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    import MySQLdb
    /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg/_mysql.py:3:
    UserWarning: Module _mysql was already imported from
    From that message it looks like this "python" is /usr/local/bin/python
    (i.e. a separate installation than Apple's system python at
    /usr/bin/python and /System/Library/Frameworks/Python.framework).

    You can tell for sure by doing:

    $ which python
    However, while writing a .py script (with Komodo Edit) I try to simply
    import the module and the in-Komodo interpreter returns an error:
    Traceback (most recent call last):
    File
    "/Users/Snake/Documents/NPS/Thesis/Source_Code/Genetics/mysql_connect_test.py",
    line 11, in <module>
    import MySQLdb
    ImportError: No module named MySQLdb
    I suspect that this is because your run of Komodo Edit doesn't have
    "/usr/local/bin" on its PATH and is using "/usr/bin/python" instead of
    the one you typically use on the command line.

    You can configure Komodo to know about /usr/local/bin by adding a "PATH"
    setting in the "Environment" prefs panel. Arguably Komodo should just
    add /usr/local/bin to its runtime PATH by default, but unfortunately it
    currently doesn't. Komodo doesn't pick up your normal bash shell
    environment because of problems trying to get that information in general.

    Please let me know (or on the komodo-discuss list [^1] or Komodo bug
    database [^2]) if you have any problems getting that going.

    Cheers,
    Trent

    [1]: http://listserv.activestate.com/mailman/listinfo/Komodo-discuss
    [2]: http://bugs.activestate.com/query.cgi?product=Komodo

    --
    Trent Mick
    trentm at activestate.com
  • Jacob Davis at Apr 15, 2008 at 7:28 pm

    On Apr 3, 2008, at 10:54 AM, Trent Mick wrote:
    Jacob Davis wrote:
    I just installed the MySQLdb module and I have been able to get it
    to run in my command line interpreter. I am running Mac Leopard,
    and Python 2.5.
    I have tested importing and actually connecting and using a MySQL
    database, although it issues some warning:
    SnakeBite:MySQL-python-1.2.2 Snake$ python
    Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC 4.0.1 (Apple
    Computer, Inc. build 5341)] on darwin
    Type "help", "copyright", "credits" or "license" for more
    information.
    import MySQLdb
    /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
    site-packages/MySQL_python-1.2.2-py2.5-macosx-10.3-fat.egg/
    _mysql.py:3: UserWarning: Module _mysql was already imported from
    From that message it looks like this "python" is /usr/local/bin/
    python (i.e. a separate installation than Apple's system python at /
    usr/bin/python and /System/Library/Frameworks/Python.framework).

    You can tell for sure by doing:

    $ which python
    However, while writing a .py script (with Komodo Edit) I try to
    simply import the module and the in-Komodo interpreter returns an
    error:
    Traceback (most recent call last):
    File "/Users/Snake/Documents/NPS/Thesis/Source_Code/Genetics/
    mysql_connect_test.py", line 11, in <module>
    import MySQLdb
    ImportError: No module named MySQLdb
    I suspect that this is because your run of Komodo Edit doesn't have
    "/usr/local/bin" on its PATH and is using "/usr/bin/python" instead
    of the one you typically use on the command line.

    You can configure Komodo to know about /usr/local/bin by adding a
    "PATH" setting in the "Environment" prefs panel. Arguably Komodo
    should just add /usr/local/bin to its runtime PATH by default, but
    unfortunately it currently doesn't. Komodo doesn't pick up your
    normal bash shell environment because of problems trying to get that
    information in general.

    Please let me know (or on the komodo-discuss list [^1] or Komodo bug
    database [^2]) if you have any problems getting that going.

    Cheers,
    Trent

    [1]: http://listserv.activestate.com/mailman/listinfo/Komodo-discuss
    [2]: http://bugs.activestate.com/query.cgi?product=Komodo

    --
    Trent Mick
    trentm at activestate.com
    Thanks, that seems to have worked. I added "/usr/local/bin" to the
    PATH in the preferences Environment panel in Komodo. Then in
    preferences I went into the Python pane and changed my selected
    interpreter from "/usr/bin/pythonw" to the now available "/usr/local/
    bin/pythonw".

    Thanks again,

    Jake

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedApr 2, '08 at 11:09p
activeApr 15, '08 at 7:28p
posts3
users2
websitepython.org

2 users in discussion

Jacob Davis: 2 posts Trent Mick: 1 post

People

Translate

site design / logo © 2022 Grokbase