Installing MySQLDB on Python 2.7.3 under CentOS - python

I need to install Python 2.7 on a machine, from source, alongside the existing version on the machine (2.4). I have compiled and installed Python successfully, but when I try to run a script calling the MySQLDB module, it throws the following error:
[root#the-node1 bin]# interactive_recording_archive.py
Traceback (most recent call last):
File "/usr/local/bin/interactive_recording_archive.py", line 8, in <module>
import MySQLdb as mdb
ImportError: No module named MySQLdb
I have tried installing MySQLDB using the easy-install script but this fails to find any module by that name. I have MySQL installed and working on the machine.
What am I doing wrong?

The package is called MySQL-python:
easy_install MySQL-python
Do check the installation requirements; you have python and setuptools, but you need the mysql-devel package too.

Related

Mysql Connector issue in Python

I have installed MySQL connector for python 3.6 in centos 7
If I search for installed modules with below command
it's showing as below
pip3.6 freeze
mysql-connector==2.1.6
mysql-connector-python==2.1.7
pymongo==3.6.1
pip3.6 search mysql-connector
mysql-connector-python (8.0.6) -MYSQL driver written in Python
INSTALLED: 2.1.7
LATEST: 8.0.6
mysql-connector (2.1.6) - MySQL driver written in Python
INSTALLED: 2.1.6 (latest)
MySQL connector installed.But when trying to run the program using MySQL connector then its showing error no module installed MySQL connector.I am using MariaDB 10.0
python3.6 mysql1.py
Traceback (most recent call last):
File "mysql1.py", line 2, in
import mysql.connector as mariadb
File "/root/Python_environment/my_Scripts/mysql.py", line 2, in
import mysql.connector
ModuleNotFoundError: No module named 'mysql.connector'; 'mysql' is not a package
can any one know how to resolve
You must not name your script mysql.py — in that case Python tries to import mysql from the script — and fails.
Rename your script /root/Python_environment/my_Scripts/mysql.py to something else.
This is the problem I faced in Environment created by python.Outside the python environment i am able to run the script.Its running succefully.In python environment i am not able run script i am working on it.if any body know can give suggestion on this

ModuleNotFoundError: No module named 'redis'

I tried to install redis-py lib via pip. It was installed successfully, but when I tried to import redis in python3 shell, I got the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'redis'
In python2 it gets imported with no errors.
I have tried all three pip, pip2, pip3 on my machine (ubuntu 17.10). Also I have python3.6 installed. I also tried easy_install
You are installing it in Python 2.7 (you have probably already know this). If python3.6 brings up the correct Python version on your system then this should work for you:
python3.6 -m pip install redis
If you are unsure what each pip version brings up you can use the which command to list the file path. This will give you a good indication as to where to look.
Also pip3.6 install redis might work but is not as secure as the above

MySQLdb is hard to locate

I use this tutorial text as an example, there are others:
#!/usr/bin/python
import MySQLdb
If it produces the following result, then it means MySQLdb module is not installed −
Traceback (most recent call last):
File "test.py", line 3, in <module>
import MySQLdb
ImportError: No module named MySQLdb
To install MySQLdb module, use the following command −
For Ubuntu, use the following command -
$ sudo apt-get install python-pip python-dev libmysqlclient-dev
I have gone trough these steps, more or less as described above.
Problem is that the subdirectory "python" does not exist under /usr/bin/
in my file system. I run Linux Mint 18.3. Python 2.7 seems to be the native version installed in Mint (used for several purposes), but I have also installed Python 3.6.4 and wish to use this for development purposes.
Does anyone know in which directory I could expect to find MySQLdb?
Since #!/usr/bin/python is non existent I wonder - has MySQLdb been properly installed? If it has, I have not after several efforts succeded in locating it.

Installing MySQLdb specifically in python 2.7 on centos

I'm using CentOS release 6.5 (Final).
I 'm currently using python 2.4, in which I can use MySQL without problems.
root#dedicado [/home/digicelc/public_html/gestion/python/cater]# python
>>> import MySQLdb
>>>
But, when I try it from python2.7
root#dedicado [/home/digicelc/public_html/gestion/python/cater]# python2.7
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
>>>
I don't want to change the python version in the server, just want to make the module avaiable for 2.7
Finally this:
# yum install python27-MySQL-python
Is giving me this:
Error: Package: python27-MySQL-python-1.2.3-9.el6.centos.alt.x86_64 (scl)
Requires: libmysqlclient_r.so.16()(64bit)
Error: Package: python27-MySQL-python-1.2.3-9.el6.centos.alt.x86_64 (scl)
Requires: libmysqlclient_r.so.16(libmysqlclient_16)(64bit)
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
I had a similar problem. Had to install python2.7 to get a particular library, then couldn't run mysql via python2.7 because it was installed on 2.6.
Try this:
pip2.7 install MySQL-python

MySQLdb for Python - incompatible library version error?

I am, like many others, trying to get MySQLdb for Python to run on Mac Snow Leopard (10.6.x) and I've been able to install the 64-bit MySQL DMG as recommended by various blogs/forum posts, and I've been able to install the setuptools and MySQLDB itself by using the
ARCHFLAGS='-arch 86_64' python2.7 setup.py clean
ARCHFLAGS='-arch 86_64' python2.7 setup.py build
sudo ARCHFLAGS='-arch 86_64' python2.7 setup.py install
As you can see from the above I have upgraded to Python 2.7 and everything seems fine; except when I try to import MySQLdb into python shell.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>
File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/ad/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: /usr/local/mysql/lib/libmysqlclient.16.dylib
Referenced from: /Users/ad/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
Reason: Incompatible library version: _mysql.so requires version 17.0.0 or later, but libmysqlclient.16.dylib provides version 16.0.0
I did a search and found libmysqlclient.16.dylib but not libmysqlclient.17.dylib
What is causing this problem, how do I resolve it, and even though I did a search for libmysqlclient.17.dylib there seems to be nothing about it; does it exist?
Thanks
You built the module against MySQL 5.5.x, but only the client libraries for 5.1.x are available on the system. Either install updated libraries, or build against an older version.
Definitely make sure that Python and MySQL are for the same architecture. You have to consistently use either 32bit or 64bit versions for both.
Also make sure that MySQLdb can find the MySQL libraries and includes, but from your error message it seems like this is the case.

Categories