Python 加载 MySQLdb 模块时出错:libmysqlclient.so.20:无法打开共享对象文件:没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34348752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:51:57  来源:igfitidea点击:

Error loading MySQLdb module: libmysqlclient.so.20: cannot open shared object file: No such file or directory

pythonmysqldjango

提问by Dawn T Cherian

I had a running django project and for some reasons I had to remove the current mysql version and install a different MySQL version in my machine.

我有一个正在运行的 django 项目,由于某些原因,我不得不删除当前的 mysql 版本并在我的机器上安装不同的 MySQL 版本。

But now when I am trying to run this program am getting an error as follows:

但是现在当我尝试运行这个程序时出现如下错误:

raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: libmysqlclient.so.20: cannot open shared object file: No such file or directory

采纳答案by Dawn T Cherian

reinstall the c shared library:

重新安装c共享库:

pip uninstall mysql-python
pip install mysql-python

回答by user3767321

Use the following commands:

使用以下命令:

pip uninstall mysql-python
pip install mysql-python

In my case it work because it searches from the complied files.

在我的情况下,它起作用是因为它从编译的文件中搜索。

回答by Darnell Lynch

My issue with the same error message was mysql environment not all the way set up. I needed to uninstall MySQL-python; install libmysqlclient-dev; reinstall MySQL-python to rectify the issue.

我遇到相同错误消息的问题是 mysql 环境没有完全设置好。我需要卸载 MySQL-python;安装 libmysqlclient-dev;重新安装 MySQL-python 以解决问题。

So the fix was too:

所以修复也是:

  • sudo pip uninstall MySQL-python (uninstall from your package manager of choice)
  • sudo apt-get install libmysqlclient-dev

  • sudo pip install MySQL-python

  • sudo pip uninstall MySQL-python(从您选择的包管理器中卸载)
  • 须藤 apt-get 安装 libmysqlclient-dev

  • 须藤 pip 安装 MySQL-python

**I should also mention that I used the --no-cache-dir option with pip install to hit PYPI directly which helped discover the following:

**我还应该提到,我在 pip install 中使用了 --no-cache-dir 选项来直接命中 PYPI,这有助于发现以下内容:

sh: 1: mysql_config: not found
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-Y7RFpJ/mysql-python/setup.py", line 17, in <module>
    metadata, options = get_config()
  File "/tmp/pip-build-Y7RFpJ/mysql-python/setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File "/tmp/pip-build-Y7RFpJ/mysql-python/setup_posix.py", line 25, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

and lead me to here

带我到这里

Using: mysql 5.7, mysql-python 1.2.5, django 1.8.9, ubuntu 16.04

使用:mysql 5.7、mysql-python 1.2.5、django 1.8.9、ubuntu 16.04

回答by Pondor

I did fix the same issue via setting below environment variable:

我确实通过设置以下环境变量解决了同样的问题:

export LD_LIBRARY_PATH=/usr/local/mysql/lib

回答by Artiko

just in case pip uninstall& pip installnot working, and you dont want to set specific path to ld_library_path, what I did on my vps:

以防万一pip uninstallpip install不能正常工作,而且你不想设定具体的路径ld_library_path,我在我的VPS做的:

cd /usr/local/lib
sudo ln -s /path/to/your/libmysqlclient.so.20

in my case my mysql is installed from linuxbrew (there is some reason to install inside home), so I had to navigate there $HOME/.linuxbrew/Cellar/mysql/5.7.18/lib/libmysqlclient.so.20

在我的情况下,我的 mysql 是从 linuxbrew 安装的(有一些原因要安装在家里),所以我不得不在那里导航 $HOME/.linuxbrew/Cellar/mysql/5.7.18/lib/libmysqlclient.so.20

回答by Lukasz Koziara

In my case the problem was caused by Ubuntu upgrades, so I can't find libmysqlclient.so.20in /usr/lib/x86_64-linux-gnu.

在我的情况下,问题是由 Ubuntu 升级引起的,所以我libmysqlclient.so.20/usr/lib/x86_64-linux-gnu.

Solution:

解决方案:

  1. Check existance libmysqlclient.so.XXin /usr/lib/x86_64-linux-gnu(or similar)
  2. Download libmysqlclient.so.XXfrom Ubuntu website (eg. link for v20)
  3. Install lib using dpkg command sudo dpkg -i libmysqlclient(...).deband sudo apt-get install -f
  4. Link lib: ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.XX.so libmysqlclient.XX.so
  1. 检查所有脑干libmysqlclient.so.XX/usr/lib/x86_64-linux-gnu(或类似)
  2. libmysqlclient.so.XX从 Ubuntu 网站下载(例如v20 的链接
  3. 使用 dpkg 命令安装 libsudo dpkg -i libmysqlclient(...).debsudo apt-get install -f
  4. 链接库: ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.XX.so libmysqlclient.XX.so