I want to use MySQLDB to connect MySQL
but I got a problem.

the problem is:
---------------------------------------------------------------------------------
cs6201:/home/lamwaiman/python/data # python dm.py
Traceback (most recent call last):
File "dm.py", line 11, in <module>
import MySQLdb
File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", line 19, in <module>
File "build/bdist.linux-i686/egg/_mysql.py", line 7, in <module>
File "build/bdist.linux-i686/egg/_mysql.py", line 6, in __bootstrap__
ImportError: /root/.python-eggs/MySQL_python-1.2.3c1-py2.6-linux-i686.egg-tmp/_mysql.so: undefined symbol: __pure_virtual
----------------------------------------------------------------------------------

I've searched google, some people said this may because compiler mismatch between MySQL and Python, I checked:
--------------------------------------------------------------------------------
lamwaiman@cs6201:/usr/bin> strings -a mysql | grep -i gcc | uniq -d
GCC: (GNU) 4.2.1 (SUSE Linux)
lamwaiman@cs6201:/usr/bin> strings -a python | grep -i gcc | uniq -d
GCC: (GNU) 4.2.1 (SUSE Linux)
lamwaiman@cs6201:/usr/bin>
---------------------------------------------------------------------------------
They got the same compiler. What is the problem?

My computer configuration:
OS: Linux 2.6.22.19-0.4-default i686
Current user: lamwaiman@cs6201
System: openSUSE 10.3 (i586)
KDE: 3.5.7 "release 72.11"
CPU: Intel(R) Pentium(R) D CPU 3.00GHz ( 2 core )

mysql Ver 14.12 Distrib 5.0.45, for suse-linux-gnu (i686) using readline 5.2
Python 2.6.4

the mysql, was installed by my computer-mate, I think he probably just installed it through YAST software management.
The python is installed by me, there is an python 2.4 installed in this OS already. I want to upgrade it to 2.6.4 , I downloaded the python 2.6.4 tar file, untar it, then >>python setup.py
----------------------------------------------------------------------------------
Let me tell you my installation step:

1)I try to use MySQLDB statement, it point out that I didn't install MySQLDB
2) I downloaded MySQLDB from sourceforge
3) I tried >> python setup.py build, it said I missing "setuptools"
4) I tried >> python ez_setup.py, everything is ok and this setuptools was installed.
5) I tried again, >> python setup.py build, this time it said I missing mysql_config
4) I searched on the Internet, people said it is because I missing a module called mysql_devel
5) I searched on the internet again, downloaded a "MySQL-devel-5.0.22-0.i386.rpm", clicked it and it was installed.
6) I installed it again >>python setup.py build, everything is ok.
7) following the README instruction, I >>sudo python setup.py install, everything is fine.
8) then I run my python program again, get the above problem now.
9) I removed the mysql-devel though YAST
10) In the YAST software management, I found out there is a "libmysqlclient-devel" with the same version of my MySQL(5.0.45.22) , I think this is also one of the"mysql-devel", installed it. Same result.

Anyone get any idea?? I don't know what do "compile from source" means, I am quite new to linux, usually I just follow the instruction.
Please tell me if you got any idea, thank you very much!!

there is Suse repository which I guess should have that package.
try:

apt-get install python-mysql

l

Edited 6 Years Ago by Stefano Mtangoo: n/a

there is Suse repository which I guess should have that package.
try:
l

type this in the shell?

cs6201:/home/lamwaiman/python/data # apt-get install python-mysql
bash: apt-get: command not found

???

what do you use in shell? yast or yum?
Are you logged in as root? Check your shell if it start with # then you are root otherwise it will show $

if not root type su then enter and type password

>>what do you use in shell? yast or yum?
I don't understand this

>>Are you logged in as root? Check your shell if it start with # then you are root otherwise it will show $
I am root already

Results:
---------------------------------------------
cs6201:~ # zypper install python-mysql
* Reading repository 'openSUSE-10.3-Updates' cache
* Reading repository 'openSUSE-10.3-DVD 10.3' cache
* Reading repository 'mozilla' cache
* Reading installed packages [100%]

package 'python-mysql' not found
Nothing to do.
-------------------------------------------------------
cs6201:~ # smart install python-mysql
-bash: smart: command not found
-------------------------------------------------------

What does all these command means? I think the "python-mysql" module are not in my computer, it needs to be downloaded. Anyway,
what is the objective?

in Linux there are package managers like Apt-get, Yast, yum and zypper. These helps you to install whatever package you want from official repositories of your os. I don't use and have never used Suse but I know Ubuntu and Mandriva. In Ubuntu, to install any pakage I will use

apt-get install package_name

In Mandriva however I use

urpmi package_name

So from Suse I discovered the package manager zypper. Since from your last post shows that zypper does the job then next issue is to find package name for MySQLdb.

Anyway from this it seems that you have few repositories in your list. You should add some more. here is the tutorial on how to do it on Suse with zypper

Edited 6 Years Ago by Stefano Mtangoo: n/a

I got Yast by default
what is the advantage of zypper over yast?
Why does it related to my problem?

it seems yast fails in some instances. zypper, smart and other are just alternatives. anyway did you manage to add more repositories? It seems python-mysql isn't in few repo you have.

1)I don't understand the concept of "repositories", can you explain it to me please? English is not my native language

2) before adding "python-mysql", I need to uninstall it, but I don't know how to uninstall it. I cannot find it via Yast.

3) To add "python-mysql" into the "repositories", should download a special format of "python-mysql"(MySqlDB)? The website provide tar format file.

I think the mysql-python do not exist in the package-management thing.
I tried many time, different name( including "mysql-python", "python-mysql", "MySQLDB", "MySQLdb", "python-mysqldb" ...)

the result always return that the package do not exist.
The README file of this thing did not mention how to uninstall also.

OK, I looked up the internet and found out I need to remove it manually
and removed it.
Figuring the next step...

The problem solved!! I don't know why!!
After uninstaling this thing, I try to install it again by:

tar xfz MySQL-python-1.2.3c1.tar.gz
cd MySQL-python-1.2.3c1
python setup.py build
python setup.py install

then the program works!
I think the problem may be caused by unproper installation( I need to install mysql-devel before trying to install mysqldb )
To conclude:
1) install Mysql
2) install mysql-devel ( alias : mysql-devel, libmysqlclient-devel )
3) install setuptool, the Mysqldb package included this
4) untar the mysqldb file
5) cd to the folder
6) python ez_setup.py (this will install the "setuptool" )
7) python setup.py build
8) python setup.py install


Thanks anyway!! Thank you evstevemd!!
I created a table in mysql via python!(the first step)

The problem solved!! I don't know why!!
After uninstaling this thing, I try to install it again by:

tar xfz MySQL-python-1.2.3c1.tar.gz
cd MySQL-python-1.2.3c1
python setup.py build
python setup.py install

then the program works!
I think the problem may be caused by unproper installation( I need to install mysql-devel before trying to install mysqldb )
To conclude:
1) install Mysql
2) install mysql-devel ( alias : mysql-devel, libmysqlclient-devel )
3) install setuptool, the Mysqldb package included this
4) untar the mysqldb file
5) cd to the folder
6) python ez_setup.py (this will install the "setuptool" )
7) python setup.py build
8) python setup.py install

From that you missed mySQL headers and it should have spit that out but strage enough it didn't

Thanks anyway!! Thank you evstevemd!!
I created a table in mysql via python!(the first step)

Eureka to you? I'm glad I helped. It is good thing to mark thread solved and....you are welcome :)

Edited 6 Years Ago by Stefano Mtangoo: n/a

This question has already been answered. Start a new discussion instead.