How to install MySQLdb package? (ImportError: No m

2020-02-19 02:57发布

I am trying to install MySQLdb package. I found the source code here.

I did the following:

gunzip MySQL-python-1.2.3c1.tar.gz
tar xvf MySQL-python-1.2.3c1.tar
cd MySQL-python-1.2.3c1
python setup.py build

As the result I got the following:

Traceback (most recent call last):
  File "setup.py", line 5, in ?
    from setuptools import setup, Extension
ImportError: No module named setuptools

Does anybody knows how to solve this problem? By the way, if I am able to do the described step, I will need to do the following:

sudo python setup.py install

And I have no system-administrator-rights. Do I still have a chance to install MySQLdb?

Thank you.

11条回答
别忘想泡老子
2楼-- · 2020-02-19 03:26

I am experiencing the same problem right now. According to this post you need to have a C Compiler or GCC. I'll try to fix the problem by installing C compiler. I'll inform you if it works (we'll I guess you don't need it anymore, but I'll post the result anyway) :)

查看更多
我想做一个坏孩纸
3楼-- · 2020-02-19 03:31

Also, you can see the build dependencies in the file setup.cfg

查看更多
再贱就再见
4楼-- · 2020-02-19 03:32

After trying many suggestions, simply using sudo apt-get install python-mysqldb worked for me.

More info: Getting "Error loading MySQLdb module: No module named MySQLdb" - have tried previously posted solutions

查看更多
三岁会撩人
5楼-- · 2020-02-19 03:33

When you need to install modules in Linux/Unix and you lack sudo / admin rights, one simple way around it is to use the user scheme installation, basically run

"python setup.py install --user" from the command line in the folder of the module / library to be installed

(see http://docs.python.org/install/index.html for further details)

查看更多
家丑人穷心不美
6楼-- · 2020-02-19 03:35

For Python 2.7, one can easily install using this

apt-get install python2.7-mysqldb

查看更多
我只想做你的唯一
7楼-- · 2020-02-19 03:36

I resolved this issue on centos5.4 by running the following command to install setuptools

yum install python-setuptools

I hope that helps.

查看更多
登录 后发表回答