无法安装 MySQL-python

2024-04-04

好的,我最近从 Ubuntu 10.04 升级到 12.04

只会面临很多问题。我是这方面的新手,所以你可能需要更详细地或一步一步地告诉我

我有一个 django 项目运行完美,但现在它给了我这个错误:

  File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory

或者在Python中:

>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory

无论如何,我认为我的 MySQL-python 有问题,所以我尝试重新安装它。

sudo pip install mysql-python

gives :

Downloading/unpacking mysql-python
  Running setup.py egg_info for package mysql-python
    The required version of distribute (>=0.6.28) is not available,
    and can't be installed while this script is running. Please
    install a more recent version first, using
    'easy_install -U distribute'.

    (Currently using distribute 0.6.24dev-r0 (/usr/lib/python2.7/dist-packages))
    Complete output from command python setup.py egg_info:
    The required version of distribute (>=0.6.28) is not available,

and can't be installed while this script is running. Please

install a more recent version first, using

'easy_install -U distribute'.



(Currently using distribute 0.6.24dev-r0 (/usr/lib/python2.7/dist-packages))

----------------------------------------
Command python setup.py egg_info failed with error code 2 in /tmp/pip-build/mysql-python
Storing complete log in /home/nabeel/.pip/pip.log

如果我做 :

sudo easy_install -U distribute

它给出了这个错误:

Searching for distribute
Reading http://pypi.python.org/simple/distribute/
Reading http://packages.python.org/distribute
Best match: distribute 0.6.29
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.29.tar.gz#md5=1aad767bfca8bebaccafee25f85696cf
Processing distribute-0.6.29.tar.gz
Running distribute-0.6.29/setup.py -q bdist_egg --dist-dir /tmp/easy_install-K8ZuMX/distribute-0.6.29/egg-dist-tmp-Fj0gj_
Before install bootstrap.
Scanning installed packages
Setuptools installation detected at /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Egg installation
Patching...
Renaming /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg to /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg.OLD.1350776909.4
Patching complete.
Relaunching...
Traceback (most recent call last):
  File "/usr/local/bin/easy_install", line 9, in <module>
    load_entry_point('distribute==0.6.8', 'console_scripts', 'easy_install')()
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 1708, in main
    with_ei_usage(lambda:
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 1696, in with_ei_usage
    return f()
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 1712, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "/usr/local/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/local/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 236, in run
    self.easy_install(spec, not self.no_deps)
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 471, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 501, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 680, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 957, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/command/easy_install.py", line 946, in run_setup
    run_setup(setup_script, args)
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/sandbox.py", line 29, in run_setup
    lambda: execfile(
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/sandbox.py", line 70, in run
    return func()
  File "/usr/local/lib/python2.7/site-packages/distribute-0.6.8-py2.7.egg/setuptools/sandbox.py", line 31, in <lambda>
    {'__file__':setup_script, '__name__':'__main__'}
  File "setup.py", line 131, in <module>
  File "/tmp/easy_install-K8ZuMX/distribute-0.6.29/distribute_setup.py", line 368, in _before_install
  File "/tmp/easy_install-K8ZuMX/distribute-0.6.29/distribute_setup.py", line 441, in _fake_setuptools
  File "/tmp/easy_install-K8ZuMX/distribute-0.6.29/distribute_setup.py", line 450, in _relaunch
NameError: global name '_cmd1' is not defined

现在我再次访问了此链接:http://pypi.python.org/pypi/setuptools/0.6c11 http://pypi.python.org/pypi/setuptools/0.6c11下载并安装安装工具.. 我还从这里安装了最新的发行版 0.6.8 :http://pypi.python.org/pypi/distribute/0.6.8 http://pypi.python.org/pypi/distribute/0.6.8

我也尝试过卸载以前的版本并重新安装,但似乎不起作用。 我已经安装了Python 2.7.3

有人可以向我解释一下发生了什么事吗...我如何安装 Mysqldb...

我还在 shell 上运行了这些命令:

sudo apt-get install mysql-server mysql-client python-mysqldb libmysqlclient-dev python-dev

但这没有帮助......

更新我刚刚做了这个并得到了这个错误:

nabeel@nabeel-pc:~$ pip uninstall setuptools
Uninstalling distribute:
  /usr/bin/easy_install
  /usr/bin/easy_install-2.7
  /usr/lib/python2.7/dist-packages/distribute-0.6.24dev_r0.egg-info
  /usr/lib/python2.7/dist-packages/easy_install.pyc
  /usr/lib/python2.7/dist-packages/pkg_resources.pyc
  /usr/lib/python2.7/dist-packages/setuptools
  /usr/lib/python2.7/dist-packages/site.pyc
  /usr/share/pyshared/easy_install.py
  /usr/share/pyshared/pkg_resources.py
  /usr/share/pyshared/site.py
Proceed (y/n)? y
  Successfully uninstalled distribute
nabeel@nabeel-pc:~$ sudo easy_install -U distribute
Searching for distribute
Reading http://pypi.python.org/simple/distribute/
Reading http://packages.python.org/distribute
Best match: distribute 0.6.29
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.29.tar.gz#md5=1aad767bfca8bebaccafee25f85696cf
Processing distribute-0.6.29.tar.gz
Running distribute-0.6.29/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Xcer8d/distribute-0.6.29/egg-dist-tmp-K0E7gP
Before install bootstrap.
Scanning installed packages
Setuptools installation detected at /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Egg installation
Already patched.
After install bootstrap.
Creating /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info
Creating /usr/local/lib/python2.7/site-packages/setuptools.pth
Removing distribute 0.6.8 from easy-install.pth file
Adding distribute 0.6.29 to easy-install.pth file
Installing easy_install script to /usr/local/bin
Installing easy_install-2.7 script to /usr/local/bin

Installed /usr/local/lib/python2.7/site-packages/distribute-0.6.29-py2.7.egg
Processing dependencies for distribute
Finished processing dependencies for distribute
nabeel@nabeel-pc:~$ sudo pip install mysql-python
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
ImportError: No module named pkg_resources

更新2:我已经成功安装 virtualenv 现在在环境中我也成功安装了MySQLdb。 这是我在运行服务器时遇到的错误:

sudo python manage.py syncdb

我收到此错误:

  File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory


(myenv)nabeel@nabeel-pc:~/workspace/gteam/metrics$ python
    Python 2.7.3 (default, Oct  6 2012, 21:57:36) 
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import MySQLdb
    >>> exit()

使用虚拟环境

首先要事。确保你有 Mysql、Setuptools 和一些必需品:

sudo apt-get install mysql-server
sudo apt-get install python-setuptools python-dev build-essential

现在安装 VirtualEnv:

sudo easy_install -U virtualenv 

创建虚拟环境。作为文档 http://www.virtualenv.org/en/latest/#what-it-does says: virtualenv is a tool to create isolated Python environments.这意味着发生冲突的可能性非常小。这里的“myenv”是一个文件夹的名称,您可以在其中访问您的环境,因此请在您想要的位置创建它。

virtualenv --distribute myenv

然后转到“myenv”目录并运行以下命令来激活它:

source myenv/bin/activate

您需要安装 libmysqlclient-dev 才能使 MySQL-python 工作:

sudo apt-get install libmysqlclient-dev

现在您已准备好安装 MySQL-python:

pip install MySQL-python

一切都应该正常。

当您不想再在该环境中工作时,请在终端中写入:

deactivate

UPDATE:

由于这个答案不断获得好评,让我向您展示如何使用 conda 执行相同的操作,它现在已成为我最喜欢的环境。首先你必须安装anaconda(我相信你也可以安装miniconda,这是一个更轻的版本,包括conda和一些软件包。)Here https://www.continuum.io/downloads您将找到适用于 Linux、OS X 和 Windows 的安装程序。它是一个很大的文件,但包含许多可供安装的预编译包。假设你已经安装了 anaconda,你可以简单地运行:

conda create -n mysql-env python

mysql-env是环境的名称(你可以随意称呼它)并且python是要安装的默认 python 版本(当前为 2.7.10)。或者,安装其他版本的 pythonconda create -n my-new-env python=3.4.

然后激活您的环境:

source activate mysql-env

最后安装mysql-python:

conda install MySQL-python

(我认为conda install mysql-python也有效)

就这样。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法安装 MySQL-python 的相关文章

随机推荐

  • Freetts 无法使用外部扬声器

    我在我的 java 应用程序中使用了 Freetts jar 文件来公布令牌编号 我的应用程序在我的笔记本电脑中运行良好 但在具有外部扬声器的台式机中无法运行 我得到一个空指针异常 注意 我的两台计算机都使用 Windows 7 下面的代码
  • PHP DOMDocument saveHTML 未正确编码西里尔字母

    I use DOMDocument操作 html 和 php 7 问题是文本在页面上显示良好 西里尔文 但是当我转到 查看 HTML 页面源代码 时 情况不太好 它显示如下 1047 1076 1077 1089 1100 1086 108
  • jQuery 提交 ajax 表单,带有 2 个提交按钮

    我试图实现以下目标 在 php 中我有一个这样的表单
  • 我可以将自定义对象发送到 Android Wear 吗?

    我刚刚学习如何为 Android Wear 进行开发 我已经为智能手表创建了一个全屏活动 在应用程序的移动部分中 我获取了一些 JSON 数据并从中创建了自定义对象列表 在我的移动应用程序上 我在 ListView 中显示这些对象的信息 在
  • 在 Rust 中将原始指针转换为 16 位 Unicode 字符到文件路径

    我正在用 Rust 编写的 DLL 替换用 C 编写的 DLL 目前DLL中的函数调用如下 BOOL calledFunction wchar t pFileName 我相信在这样的背景下wchar t是一个 16 位 Unicode 字符
  • 是否可以在Azure中运行npx工具来执行包

    是否可以运行npx工具来执行Azure App服务 Web应用程序 中的包 我在用 节点 v10 19 0 npm v6 13 4 如果我在本地计算机上浏览到 nodejs 我可以看到 npx cmd 工具 但如果我在 azure 中执行相
  • Textmate for Ruby 自动完成?

    我真的很习惯 Netbeans 的自动完成功能 在 Netbeans 中 当我键入 字符串 然后点击 点 时 它将打印出 String 类的方法列表 TextMate好像没有这个功能 您可以添加什么吗 会节省很多时间 而不是一直使用 ri
  • 在列表视图上方添加图像

    我想在列表视图上方添加图像视图 我知道在列表视图中添加部分听者 但我只是想节省时间 所以我使用图像视图作为列表视图标题 而不是使用 addSectionHeader 不幸的是我只是坚持使用一些 xml 属性 图像叠加在我的列表视图中 实际上
  • 我正在尝试获取 Apple Music API 的用户令牌,我已经从 python 终端命令生成了有效的开发人员令牌

    我正在我的 IOS 应用程序中第一次使用 Apple Music api 我已经在 python 命令的帮助下生成了开发者令牌 每次请求用户令牌时 我都会收到错误 请求用户令牌时发生错误 操作无法完成 SKErrorDomain 错误 7
  • 检查 arraytype 列是否包含 null

    我有一个数据框 其中有一列可以包含整数值的数组类型 如果没有值 它将只包含一个 并且它将是空值 重要的 注意该列不会为空 而是一个具有单个值的数组 无效的 gt val df DataFrame Seq foo Seq Some 2 Som
  • 在 TFS API 中将测试用例添加到 ITestSuiteBase

    我正在使用 TFS API 并遇到了 ITestSuiteBase 和 IRequirementTestSuite 的问题 我设法在 IStaticTestSuite 中轻松创建一个新的测试用例 IStaticTestSuite worki
  • 自动同步 Visual Studio 的类视图

    是否可以让 Visual Studio 的 类视图 窗格 在 视图 gt 类视图 下可用 自动同步到当前符号 基本上只要当前符号发生变化就会执行 View SynchronizeClassView See here https stacko
  • 其元数据的二进制版本是1.7.1,预期版本是1.5.1

    C Users khare gradle caches modules 2 files 2 1 org jetbrains kotlin kotlin stdlib common 1 7 0 51736992f422993a1e741051
  • KTable 应该发出的事件

    我正在尝试测试一个拓扑 该拓扑作为最后一个节点 具有 KTable 我的测试是使用成熟的 Kafka 集群 通过 confluence 的 Docker 镜像 所以我not使用TopologyTestDriver 我的拓扑有键值类型的输入S
  • 自定义设计signed_up_but_unconfirmed消息

    实际上我想自定义signed up but unconfirmed消息该消息是 A message with a confirmation link has been sent to your email address Please fo
  • 如何检查SuperTab和jedi-vim是否激活?

    正如标题所述 如何检查插件是否已加载 当我击中时tab 对于 SuperTab 我得到的只是插入到我的文件中的普通字符 tab 当我点击ctrl 空格键我只是被抛出插入模式 与点击相同的行为ESC The scriptnames命令列出所有
  • 办公文档设置

    我目前正在存储一个键值对Office context documents settings使用以下函数 Office context document settings set name value 存储键值对后 我将重新启动加载项并尝试使
  • 无法将 SQL 查询的结果传递给 JAVA 中的方法

    这是我第一次使用 Java 我很困惑 我创建了这个方法 List
  • 即使使用文档中的示例,也无法模拟打开

    我直接从 Python 复制并粘贴了以下代码模拟文档 https docs python org 3 library unittest mock html mock open from unittest mock import patch
  • 无法安装 MySQL-python

    好的 我最近从 Ubuntu 10 04 升级到 12 04 只会面临很多问题 我是这方面的新手 所以你可能需要更详细地或一步一步地告诉我 我有一个 django 项目运行完美 但现在它给了我这个错误 File usr local lib