4

I have a CentOS box.

(venv)[root@localhost]# yum install MySQL-python
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.maine.edu
 * epel: ftp.osuosl.org
 * extras: mirror.us.leaseweb.net
 * remi: rpms.famillecollet.com
 * updates: mirrors.centarra.com
Setting up Install Process
Package MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 already installed and latest version
Nothing to do

...

(venv)[root@localhost]# python
Python 2.7.6 (default, May 20 2014, 20:23:08)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
>>>

What do I do?

and when I try pip install mysql-python I get this:

Traceback (most recent call last):
  File "/home/user1/project/venv/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/home/user1/project/venv/lib/python2.7/site-packages/pip/__init__.py", line 185, in main
    return command.main(cmd_args)
  File "/home/user1/project/venv/lib/python2.7/site-packages/pip/basecommand.py", line 161, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 65: ordinal not in range(128)
ComputerFellow
  • 11,710
  • 12
  • 50
  • 61
  • maybe check that link http://stackoverflow.com/questions/4380931/installing-mysql-python-on-centos – Freelancer May 20 '14 at 15:31
  • @Freelancer but that's not the problem that I'm facing. – ComputerFellow May 20 '14 at 15:34
  • Could be related to your venv. Did you create venv on the system and load a requirements file? When you freeze the virtual environment, what does the requirments list say( pip freeze > requirements.txt) – bcollins May 20 '14 at 15:49
  • Possible duplicate http://stackoverflow.com/a/10970547/285594 –  Apr 05 '17 at 12:36

3 Answers3

10

You need to force pip to use the default localization settings. Instead of:

pip install mysql-python

do:

LC_ALL=C pip install mysql-python

If you run into an error: Python.h: No such file or directory, then you'll need to install an additional library:

yum install python-devel
huu
  • 7,032
  • 2
  • 34
  • 49
0

Some times we need to externally add/install git repo, This is not released yet but you can add from below command

pip install git+https://github.com/PyMySQL/mysqlclient-python.git

And

pip install mysql-python

and

yum install python-devel
Rajat jain
  • 1,715
  • 3
  • 12
  • 21
0

You can use MySQL-python

For centos

yum install MySQL-python

Python 2.7.13 (default, Sep 26 2018, 18:42:22) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.

    >> import MySQLdb
    >> 
Jadhav Gaurav
  • 510
  • 5
  • 10