Blender3D and MySQL - does not connect?? WHY!

Hi

I’m trying to connect to a MySQL database from blender3d but seem to be running into problems. I’m using the MySQLdb interface module, but whenever I try to run my code I get the following error


Traceback (most recent call last):
  File "Text.001", line 3, in ?
AttributeError: 'module' object has no attribute 'connect'

The code error occurs when I try to call the MySQLdb.connect function, it doesn’t seem to be able to locate the function.

I ran dir(MySQLdb) and it returned a small list of attributes but no functions.

However if I try to run my exact same code in python from the command prompt DOS it runs perfectly. What am I doing wrong here - bcoz there isn’t anything worng with my code and I am importing the module.

I would appreciate any form of help available for this.

Do you have a full Python install for the Python version that Blender uses?

Blender 2.37a uses Python 2.3
Blender 2.40alpha uses Python 2.4

Which Python version are you running from your console?

I’ve had MySQL running with Blender Python for a while. Please post your whole script, and I’ll take a look at it.

From the error msg, it looks you do not have an instance of a MySQLdb object. Hard to say more without seeing both the code and the complete output.

From my console it says

Using Python Ver 2.3

My code is as follows but it doens’t cause any troubles when I run it seperately from python command prompt it only causes trouble in blender3d python


import MySQLdb

db = MySQLdb.connect(host="localhost", user="root", passwd="root",
db="tms")

cursor = db.cursor()

cursor.execute("SELECT * FROM users")

result = cursor.fetchall()

for record in result:
        print record[0] , " - ", record[1]


How do you get MySQl to run with Blender3d python?

I for got to mention I already have a seperate python installation ver 2.4 to be xact. I am a noob to Blender3d in this respect though.

Does Blender3d share the same directory path as my seperate python installation, because from teh looks of things I can’t import any files in my default python directory into Blender3d python.

The issue isn’t so much of MySQLDb not being detected… the problem is that I can’t access any functions or methods of any file I import. I even tried to import a file containing arbitrary functions even after importing the file into Blender3d python after running a dir on it it only returned some attributes and not teh methods and functions I defined.

Blender uses Python 2.3. It sounds like you are running Python 2.4 from the command line.

You need to install MySQL using Python 2.3 for Blender to be able to use it. Python 2.3 and Python 2.4 use separate paths to find their modules. The modules are not normally interchangable.

Note: the next version of Blender ( the current alpha version ) will use Python 2.4

You need to see the sticky posts about setting your Blender PythonPath correctly, which can be found at the top of this very forum.

Ok I got it figured out. I just uninstalled blender3d and my python installation and reinstalled first python2.3, then teh MySQL for python extension and then blender3d, now its working fine.

It seemed to be a conflict with the version of python that was initially instaled and the version of python that blender supported - initially I had python 2.4 and I guess blender3d supported just 2.3.

Thanks for the help guys. :smiley: