Hi:
CSS BOY scripts are executed in jython, not python.
Most of the default python modules are also available in jython, but when you install python modules with binary dependencies like numpy, MySQL_python, .. those are not available in jython.
In jython you can instead call all the Java modules included in CS-Studio, for example the RDBUtil which allows access to Oracle, Postgres, MySQL.
But you shouldn’t really do that in a BOY script, because it’ll execute on the UI thread. Database operations are too slow, they will cause your complete UI to freeze.
The display tool was meant to display PVs, not to perform database operations.
If you do enjoy writing python code that interacts with MySQL, just do that outside of the display tool, then add a pcaspy CA server to provide the results as PVs, and display those PVs in CSS BOY.
-Kay
Hi all,
I want to import MySQLdb module in CSS to operate the mysql database.
In order to do this, I have looked up the CSS manual and add the MySQLdb module path ("/usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/") in the
PYTHONPATH that obtained from sys.path;
The content of python script that I wrote only contain two lines:
from org.csstudio.opibuilder.scriptUtil import PVUtil
import MySQLdb
however, when running the python script in CSS, an error occured and print out the following message:
Traceback (most recent call last):
File "<script>", line 2, in <module>
File "/usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/MySQLdb/__init__.py", line 19, in <module>
File "/usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.py", line 7, in <module>
File "/usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.py", line 6, in __bootstrap__
ImportError: No module named _mysql
If I import MySQLdb module directly in python terminal window and everything is OK and no
error occurred !
Any help will be appreciated and thanks in advance !
Zhefu
|