我如何解决“OSError: mysql_config not found"?Elastic Beanstalk 部署期间出错?

问题

我正在尝试使用小型数据库后端在 Elastic Beanstalk 上部署一个非常简单的应用程序.我尝试安装 mysqlclient 作为 AWS 此处.但是,当我部署我的应用程序时,我在尝试下载包时从我的 Elastic Beanstalk 日志中收到以下错误:

I am trying to deploy a very simple app on Elastic Beanstalk with a small database backend. I try to install mysqlclient as part of the process outlined by AWS here. However, when I deploy my app, I get the following error from my Elastic Beanstalk logs as it tries to download the package:

Collecting mysqlclient
  Using cached mysqlclient-2.0.1.tar.gz (87 kB)

2020/08/21 20:30:16.419082 [ERROR] An error occurred during execution of command [app-deploy] - [InstallDependency]. Stop running the command. Error: fail to install dependencies with requirements.txt file with error Command /bin/sh -c /var/app/venv/staging-LQM1lest/bin/pip install -r requirements.txt failed with error exit status 1. Stderr:    ERROR: Command errored out with exit status 1:
     command: /var/app/venv/staging-LQM1lest/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bz45889a/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bz45889a/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-1tyle8mv
         cwd: /tmp/pip-install-bz45889a/mysqlclient/
    Complete output (12 lines):
    /bin/sh: mysql_config: command not found
    /bin/sh: mariadb_config: command not found
    /bin/sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-bz45889a/mysqlclient/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "/tmp/pip-install-bz45889a/mysqlclient/setup_posix.py", line 65, in get_config
        libs = mysql_config("libs")
      File "/tmp/pip-install-bz45889a/mysqlclient/setup_posix.py", line 31, in mysql_config
        raise OSError("{} not found".format(_mysql_config_path))
    OSError: mysql_config not found

问题

mysqlclient 是 AWS 推荐的驱动程序,用于使用 Flask 或 Django 连接到 RDS 中的 MySQL 数据库.如何使用 Elastic Beanstalk 安装它?

The mysqlclient is the AWS recommended driver to connect to a MySQL database in RDS using Flask or Django. How do I get it installed with Elastic Beanstalk?

背景

我尝试使用 (1) Elastic Beanstalk 环境内的数据库或 (2) Elastic Beanstalk 环境外定期部署的 RDS 实例来实现我的架构环境.在这种情况下,我们将使用选项 (1).

I've tried to implement my architecture with either (1) a database within the Elastic Beanstalk environment or (2) a regularly deployed RDS instance outside the Elastic Beanstalk environment. In this case, we're going with option (1).

我无法使用 apt-get 安装 mysql-server 或其他软件包作为 在这里建议 很容易,这就是为什么我希望这不会被标记为重复.我无权访问底层服务器.我尝试使用平台挂钩和 .ebextensions,但我 无法让它工作.在这篇文章中,我试图退后一步,看看是否还有其他途径.

I can't install mysql-server or other packages using apt-get as suggested here very easily, which is why I hope this isn't labeled as a duplicate. I don't have access to the underlying servers. I attempted to using platform hooks and .ebextensions, but I wasn't able to get that to work. In this post, I'm trying to step back and see if there is another avenue.

推荐答案

对于 Amazon linux 2,您应该能够使用 yum 安装它.因此,您可以在 .ebextensions 中有一个名为的文件,例如01_packages.config 内容:

For Amazon linux 2 you should be able to install it with yum. Thus, you can have in your .ebextensions a file called, e.g. 01_packages.config with the content:

packages: 
    yum:
        MySQL-python: []

如果您需要更多 yum 依赖项,您可以添加更多.

You can add further yum dependencies if you require more.

相关文章