如何安装MySQLdb包?(ImportError:没有名为setuptools的模块)

时间:2021-05-04 23:16:11

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

我正在安装MySQLdb包。我在这里找到了源代码。

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?

我没有系统管理员的权利。我还有机会安装MySQLdb吗?

Thank you.

谢谢你!

11 个解决方案

#1


16  

If MySQLdb's now distributed in a way that requires setuptools, your choices are either to download the latter (e.g. from here) or refactor MySQLdb's setup.py to bypass setuptools (maybe just importing setup and Extension from plain distutils instead might work, but you may also need to edit some of the setup_*.py files in the same directory).

如果MySQLdb现在以一种需要setuptools的方式发布,那么您的选择要么是下载后者(例如这里),要么是重构MySQLdb的设置。py可以绕过setuptools(也许只需要从普通的distutils导入安装和扩展就可以了,但是您可能还需要编辑一些setup_*。在同一目录中的py文件)。

Depending on how your site's Python installation is configured, installing extensions for your own individual use without requiring sysadm rights may be hard, but it's never truly impossible if you have shell access. You'll need to tweak your Python's sys.path to start with a directory of your own that's your personal equivalent of the system-wide site pacages directory, e.g. by setting PYTHONPATH persistently in your own environment, and then manually place in said personal directory what normal installs would normally place in site-packages (and/or subdirectories thereof).

根据站点的Python安装是如何配置的,在不需要sysadm权限的情况下为您自己安装扩展可能很难,但是如果您有shell访问的话,这从来都不是不可能的。您需要调整Python的系统。从您自己的目录开始,这是您的个人等效的全系统站点pacages目录,例如,通过在您自己的环境中持续地设置PYTHONPATH,然后手动放置在说的个人目录中,正常的安装通常放置在站点包(和/或子目录)中。

#2


28  

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

在尝试了许多建议之后,简单地使用sudo apt-get install python-mysqldb对我来说很有用。

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

更多信息:获取“错误加载MySQLdb模块:没有命名为MySQLdb的模块”——已经尝试过以前发布的解决方案

#3


11  

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

我通过运行以下命令来安装setuptools,在centos5.4上解决了这个问题

yum install python-setuptools

yum安装python-setuptools

I hope that helps.

我希望有帮助。

#4


5  

This was sort of tricky for me too, I did the following which worked pretty well.

这对我来说也有点棘手,我做了以下的工作,效果很好。

  • Download the appropriate Python .egg for setuptools (ie, for Python 2.6, you can get it here. Grab the correct one from the PyPI site here.)
  • 下载适合setuptools的Python .egg(例如,对于Python 2.6,可以在这里获得。从这里的PyPI站点获取正确的数据。
  • chmod the egg to be executable: chmod a+x [egg] (ie, for Python 2.6, chmod a+x setuptools-0.6c9-py2.6.egg)
  • chmod蛋可执行:chmod a+x [egg](即,对于Python 2.6, chmod a+x setuptools-0.6c9-py2.6.egg)
  • Run ./[egg] (ie, for Python 2.6, ./setuptools-0.6c9-py2.6.egg)
  • 运行。/[egg](即Python 2.6. /setuptools- 0.69 c9-py2.6.egg)

Not sure if you'll need to use sudo if you're just installing it for you current user. You'd definitely need it to install it for all users.

不确定是否需要使用sudo,如果您只是为当前用户安装它。您肯定需要它来为所有用户安装它。

#5


5  

@main:

@main:

$ su
$ yum install MySQL-python

and it will be installed (MySQLdb).

它将被安装(MySQLdb)。

#6


2  

#!/usr/bin/env python

import os
import sys
from **distutils.core** import setup, Extension

if sys.version_info < (2, 3):
    raise Error("Python-2.3 or newer is required")

if os.name == "posix":
    from setup_posix import get_config
else: # assume windows
    from setup_windows import get_config

metadata, options = get_config()
metadata['ext_modules'] = [Extension(sources=['_mysql.c'], **options)]
metadata['long_description'] = metadata['long_description'].replace(r'\n', '')
setup(**metadata)

#7


2  

For Python 2.7, one can easily install using this

对于Python 2.7,可以使用它轻松地进行安装

apt-get install python2.7-mysqldb

apt-get安装python2.7-mysqldb

#8


1  

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

此外,您还可以在setup.cfg文件中看到构建依赖项

#9


1  

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) :)

我正在经历同样的问题。根据这篇文章,您需要一个C编译器或GCC。我将通过安装C编译器来解决这个问题。如果可以的话我会通知你(我想你不再需要它了,但我还是会把结果贴出来):

#10


1  

well installing C compiler or GCC didn't work but I found a way to successfully install mysqldb package

安装C编译器或GCC没有成功,但我找到了一种成功安装mysqldb包的方法。

kindly follow Mike schrieb's (Thanks to him) instructions here . In my case, I used setuptools-0.6c11-py2.7.egg and setuptools-0.6c11 . Then download the executable file here then install that file. hope it helps :)

请听迈克·施里布(感谢他)的指示。在我的例子中,我使用setuptools-0.6c11-py2.7。鸡蛋和setuptools - 0.6 - c11。然后在这里下载可执行文件,然后安装该文件。希望它能帮助:)

#11


0  

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

当您需要在Linux/Unix中安装模块而又缺乏sudo / admin权限时,一种简单的解决方法是使用用户方案安装,基本运行

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

“python设置。py安装——用户“来自要安装的模块/库文件夹中的命令行

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

(详情请参阅http://docs.python.org/install/index.html)

#1


16  

If MySQLdb's now distributed in a way that requires setuptools, your choices are either to download the latter (e.g. from here) or refactor MySQLdb's setup.py to bypass setuptools (maybe just importing setup and Extension from plain distutils instead might work, but you may also need to edit some of the setup_*.py files in the same directory).

如果MySQLdb现在以一种需要setuptools的方式发布,那么您的选择要么是下载后者(例如这里),要么是重构MySQLdb的设置。py可以绕过setuptools(也许只需要从普通的distutils导入安装和扩展就可以了,但是您可能还需要编辑一些setup_*。在同一目录中的py文件)。

Depending on how your site's Python installation is configured, installing extensions for your own individual use without requiring sysadm rights may be hard, but it's never truly impossible if you have shell access. You'll need to tweak your Python's sys.path to start with a directory of your own that's your personal equivalent of the system-wide site pacages directory, e.g. by setting PYTHONPATH persistently in your own environment, and then manually place in said personal directory what normal installs would normally place in site-packages (and/or subdirectories thereof).

根据站点的Python安装是如何配置的,在不需要sysadm权限的情况下为您自己安装扩展可能很难,但是如果您有shell访问的话,这从来都不是不可能的。您需要调整Python的系统。从您自己的目录开始,这是您的个人等效的全系统站点pacages目录,例如,通过在您自己的环境中持续地设置PYTHONPATH,然后手动放置在说的个人目录中,正常的安装通常放置在站点包(和/或子目录)中。

#2


28  

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

在尝试了许多建议之后,简单地使用sudo apt-get install python-mysqldb对我来说很有用。

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

更多信息:获取“错误加载MySQLdb模块:没有命名为MySQLdb的模块”——已经尝试过以前发布的解决方案

#3


11  

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

我通过运行以下命令来安装setuptools,在centos5.4上解决了这个问题

yum install python-setuptools

yum安装python-setuptools

I hope that helps.

我希望有帮助。

#4


5  

This was sort of tricky for me too, I did the following which worked pretty well.

这对我来说也有点棘手,我做了以下的工作,效果很好。

  • Download the appropriate Python .egg for setuptools (ie, for Python 2.6, you can get it here. Grab the correct one from the PyPI site here.)
  • 下载适合setuptools的Python .egg(例如,对于Python 2.6,可以在这里获得。从这里的PyPI站点获取正确的数据。
  • chmod the egg to be executable: chmod a+x [egg] (ie, for Python 2.6, chmod a+x setuptools-0.6c9-py2.6.egg)
  • chmod蛋可执行:chmod a+x [egg](即,对于Python 2.6, chmod a+x setuptools-0.6c9-py2.6.egg)
  • Run ./[egg] (ie, for Python 2.6, ./setuptools-0.6c9-py2.6.egg)
  • 运行。/[egg](即Python 2.6. /setuptools- 0.69 c9-py2.6.egg)

Not sure if you'll need to use sudo if you're just installing it for you current user. You'd definitely need it to install it for all users.

不确定是否需要使用sudo,如果您只是为当前用户安装它。您肯定需要它来为所有用户安装它。

#5


5  

@main:

@main:

$ su
$ yum install MySQL-python

and it will be installed (MySQLdb).

它将被安装(MySQLdb)。

#6


2  

#!/usr/bin/env python

import os
import sys
from **distutils.core** import setup, Extension

if sys.version_info < (2, 3):
    raise Error("Python-2.3 or newer is required")

if os.name == "posix":
    from setup_posix import get_config
else: # assume windows
    from setup_windows import get_config

metadata, options = get_config()
metadata['ext_modules'] = [Extension(sources=['_mysql.c'], **options)]
metadata['long_description'] = metadata['long_description'].replace(r'\n', '')
setup(**metadata)

#7


2  

For Python 2.7, one can easily install using this

对于Python 2.7,可以使用它轻松地进行安装

apt-get install python2.7-mysqldb

apt-get安装python2.7-mysqldb

#8


1  

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

此外,您还可以在setup.cfg文件中看到构建依赖项

#9


1  

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) :)

我正在经历同样的问题。根据这篇文章,您需要一个C编译器或GCC。我将通过安装C编译器来解决这个问题。如果可以的话我会通知你(我想你不再需要它了,但我还是会把结果贴出来):

#10


1  

well installing C compiler or GCC didn't work but I found a way to successfully install mysqldb package

安装C编译器或GCC没有成功,但我找到了一种成功安装mysqldb包的方法。

kindly follow Mike schrieb's (Thanks to him) instructions here . In my case, I used setuptools-0.6c11-py2.7.egg and setuptools-0.6c11 . Then download the executable file here then install that file. hope it helps :)

请听迈克·施里布(感谢他)的指示。在我的例子中,我使用setuptools-0.6c11-py2.7。鸡蛋和setuptools - 0.6 - c11。然后在这里下载可执行文件,然后安装该文件。希望它能帮助:)

#11


0  

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

当您需要在Linux/Unix中安装模块而又缺乏sudo / admin权限时,一种简单的解决方法是使用用户方案安装,基本运行

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

“python设置。py安装——用户“来自要安装的模块/库文件夹中的命令行

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

(详情请参阅http://docs.python.org/install/index.html)