Blender 2.6, Python 3.3 and Mysql

Hello Internet!

I’ve run into a problem dealing with Database connection in blender.
I’m currently running Blender 2.6, Python 3.3 and MySQL 5 on Windows 7 Home x64

Using MySQL Connector/Python I am able to connect to a database on localhost and query tables, run stored procedures and do other useful things.

When I tried to do the same in blender, the Command prompt wouldn’t let me import mysql.

>>> import mysql.connector
Traceback (most recent call last):
File “<blender_console>”, line 1, in <module>
ImportError: No module named ‘mysql’

I’ve tried looking online, but everything I’ve found is either using an older version of blender, python 2.x, or tying in other programming languages.

So my questions are.

  1. Is there a way to connect blender to a MySQL database?
  2. Can I import the MySQL Connector/Python module into blender so i can use it there?
    Any and all help is greatly appreciated.

I had a similar problem yesterday, and solved the import issue:
Try to ‘import sys’, just type it in the Blender console to see if it works. Now, to list all module locations you can import, run ‘sys.path’.

If you know where ‘mysql.connector’ is located you can run: sys.path.append(‘yourdirectory’)
Now blender knows where it is and you can try to import it.

Progress! But I’ve got a new error now

>>> sys.path.append(‘C:\python33\LIB\site-packages’)
>>> import mysql.connector
Traceback (most recent call last):
File “<blender_console>”, line 1, in <module>
File “C:\python33\LIB\site-packages\mysql\connector_init_.py”, line 30, in <module>
from .connection import MySQLConnection
File “C:\python33\LIB\site-packages\mysql\connector\connection.py”, line 32, in <module>
from mysql.connector.network import MySQLUnixSocket, MySQLTCPSocket
File “C:\python33\LIB\site-packages\mysql\connector
etwork.py”, line 27, in <module>
import socket
File “C:\Python33\Lib\socket.py”, line 47, in <module>
import _socket
ImportError: DLL load failed: The specified procedure could not be found.

I’m not sure, but ou might want to add more directories to the sys.path. Try to print out the sys.path list in a python console outside of Blender

I’m still getting the same error. Here’s my step by step.

First, I looked at what Python had in it’s sys.path

C:&gt;python
Python 3.3.4 (v3.3.4:7ff62415e426, Feb 10 2014, 18:13:51) [MSC v.1600 64 bit (AM
D64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import sys
>>> sys.path
[‘’, ‘C:\Python33\Lib’, ‘C:\Python33\DLLs’, ‘C:\Python33\Lib\lib-tk’, ‘C:
\pyssh-ctypes-0.3’, ‘C:\’, ‘C:\Windows\system32\python33.zip’, ‘C:\Python3
3’, ‘C:\Python33\lib\site-packages’]

Second. I opened blender, went to scripting, and using its built in command prompt entered the following.

import sys
sys.path.append(‘C:\Python33\Lib’)
sys.path.append(‘C:\Python33\DLLs’)
sys.path.append(‘C:\Python33\Lib\lib-tk’)
sys.path.append(‘C:\pyssh-ctypes-0.3’)
sys.path.append(‘C:\Windows\system32\python33.zip’)
sys.path.append(‘C:\Python33’)
sys.path.append(‘C:\Python33\lib\site-packages’)

Third, I check to make sure everything had added correctly
>>> sys.path
[‘C:\Program Files\Blender Foundation\Blender\2.69\scripts\addons’, ‘C:\Program Files\Blender Foundation\Blender\2.69\scripts\startup’, ‘C:\Program Files\Blender Foundation\Blender\2.69\scripts\modules’, ‘C:\Python33\Lib’, ‘C:\Python33\DLLs’, ‘C:\Python33\Lib\lib-tk’, ‘C:\pyssh-ctypes-0.3’, ‘C:\Program Files\Blender Foundation\Blender’, ‘C:\Program Files\Blender Foundation\Blender\python33.zip’, ‘C:\Program Files\Blender Foundation\Blender\2.69\python\DLLs’, ‘C:\Program Files\Blender Foundation\Blender\2.69\python\lib’, ‘C:\Program Files\Blender Foundation\Blender\2.69\python’, ‘C:\Program Files\Blender Foundation\Blender\2.69\python\lib\site-packages’, ‘C:\Program Files\Blender Foundation\Blender\2.69\scripts\addons\modules’, ‘C:\Users\Justin\AppData\Roaming\Blender Foundation\Blender\2.69\scripts\addons\modules’,

‘C:\Python33\Lib’, ‘C:\Python33\DLLs’, ‘C:\Python33\Lib\lib-tk’, ‘C:\pyssh-ctypes-0.3’, ‘C:\Windows\system32\python33.zip’, ‘C:\Python33’, ‘C:\Python33\lib\site-packages’
]

I added the quotes here afterwards.

Then I tried to import mysql.connector.
>>> import mysql.connector
Traceback (most recent call last):
File “<blender_console>”, line 1, in <module>
File “C:\Python33\lib\site-packages\mysql\connector_init_.py”, line 30, in <module>
from .connection import MySQLConnection
File “C:\Python33\lib\site-packages\mysql\connector\connection.py”, line 32, in <module>
from mysql.connector.network import MySQLUnixSocket, MySQLTCPSocket
File “C:\Python33\lib\site-packages\mysql\connector
etwork.py”, line 27, in <module>
import socket
File “C:\Python33\Lib\socket.py”, line 47, in <module>
import _socket
ImportError: DLL load failed: The specified procedure could not be found.

So still running into the same issue. I tried looking at the socket.py script to see what it’s talking about. But that’s so far above my level I don’t even know where to start.

Some generic runtime library might be missing, see

or google for the error message
(ImportError: DLL load failed: The specified procedure could not be found.)

Can’t seem to get a list of the generic runtime libraries that Blender uses or how it imports them. Trying to google that error message alone is to broad a term to get any useful information. Searching for it in conjunction with Python 3.3 and MySQL Connector/Python returns gibberish.

Perhaps I’m going about this the wrong way. Has anyone managed to achieve a MySQL DB connection with anything in Blender 2.6?

You have to be aware of the version of MSVC that is used tom compile the binary objects for both blender and the mysql bindings. They need to be either the same or they need to have manifests packed into the pyd objects. Usually when just downloading random binaries for python 3.3.3 from the web it is my experience that you either have to fix this (no easy) or compile your own. If you link the version of the mysql bindings your are using and the version of blender (exact download url) I will take a look for you if you want

Sqlite3 - yes. MySQL - No.

any reason it has to be MySQL?

For me the following works:
I have a separate folder containing an addons and a modules folder. From blender user settings I refer to this folder. (this way I dont need to re-install my scripts for every new blender version)
In the modules folder I put the mysql python package I got from the mysql site
so you get:


addons/
  addon_using_mysql.py
modules/
  mysql/
    __init__.py
    connector/
      locales/
         ......
      conversion.py
      ......

and in my script:


import mysql.connector
.....
conn = mysql.connector.connect(**self.connection_details)

Juicyfruit - not quite certain how to find what version of the mysql bindings I use. I got blender from blender.org/download. It’s blender 2.69 x64 for Windows. I used the ‘Installer’ Option and downloaded from the USA link.

dustractor. I don’t think sqlite will be adequate for what I’m attempting to do. My end goal is to attempt to make an MMORPG. And while I’m not particularly well versed in sqlite. What I’ve read on the website suggests to me it would be insufficient for my project.