无法在 EC2 实例上安装 mysqlclient 包

hit*_*ton 3 python mysql amazon-ec2 amazon-web-services

我正在尝试在运行 Amazon Linux 2023 AMI 的 Amazon EC2 实例上安装 mysqlclient Python 包。

\n

当我运行时pip install mysqlclient,我收到以下错误消息:

\n
Collecting mysqlclient==2.1.0\n  Downloading mysqlclient-2.1.0.tar.gz (87 kB)\n     \xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81 87.6/87.6 kB 17.2 MB/s eta 0:00:00\n  Preparing metadata (setup.py) ... error\n  error: subprocess-exited-with-error\n\n  \xc3\x97 python setup.py egg_info did not run successfully.\n  \xe2\x94\x82 exit code: 1\n  \xe2\x95\xb0\xe2\x94\x80> [16 lines of output]\n      /bin/sh: line 1: mysql_config: command not found\n      /bin/sh: line 1: mariadb_config: command not found\n      /bin/sh: line 1: mysql_config: command not found\n      Traceback (most recent call last):\n        File "<string>", line 2, in <module>\n        File "<pip-setuptools-caller>", line 34, in <module>\n        File "/tmp/pip-install-ywdhtbse/mysqlclient_802cda8d3393451492ff091d28d6482f/setup.py", line 15, in <module>\n          metadata, options = get_config()\n        File "/tmp/pip-install-ywdhtbse/mysqlclient_802cda8d3393451492ff091d28d6482f/setup_posix.py", line 70, in get_config\n          libs = mysql_config("libs")\n        File "/tmp/pip-install-ywdhtbse/mysqlclient_802cda8d3393451492ff091d28d6482f/setup_posix.py", line 31, in mysql_config\n          raise OSError("{} not found".format(_mysql_config_path))\n      OSError: mysql_config not found\n      mysql_config --version\n      mariadb_config --version\n      mysql_config --libs\n      [end of output]\n\n  note: This error originates from a subprocess, and is likely not a problem with pip.\nerror: metadata-generation-failed\n\n\xc3\x97 Encountered error while generating package metadata.\n\xe2\x95\xb0\xe2\x94\x80> See above for output.\n\nnote: This is an issue with the package mentioned above, not pip.\nhint: See above for details.\n
Run Code Online (Sandbox Code Playgroud)\n

我已经尝试过以下操作:

\n

sudo yum -y install mysql这导致Last metadata expiration check: 0:41:31 ago on Thu Apr 6 13:36:18 2023. No match for argument: mysql

\n

谁能建议解决这个问题?

\n

提前致谢!

\n

编辑

\n

这是我执行的所有命令:

\n
    \n
  • 须藤百胜更新-y
  • \n
  • 须藤 yum 安装 python3 -y
  • \n
  • sudo yum install python3-pip -y
  • \n
  • sudo dnf install -y mariadb105-devel gcc
  • \n
  • pip install mysqlclient==2.1.0(虚拟环境中)
  • \n
\n

但对于最后一个我收到以下错误:

\n
Collecting importlib-metadata\n  Downloading importlib_metadata-6.1.0-py3-none-any.whl (21 kB)\nCollecting zipp>=0.5\n  Downloading zipp-3.15.0-py3-none-any.whl (6.8 kB)\nBuilding wheels for collected packages: Flask-MySQLdb, mysqlclient\n  Building wheel for Flask-MySQLdb (setup.py) ... done\n  Created wheel for Flask-MySQLdb: filename=Flask_MySQLdb-1.0.1-py3-none-any.whl size=4675 sha256=e0bb7388b33b749ec52908abdb0e34d15c10544c2c2c96932e9ee90b117e0cfa\n  Stored in directory: /home/ec2-user/.cache/pip/wheels/48/ba/f7/32a9b364c18e9e479d5dd05305109e7a72d85d8e29c02a10ea\n  Building wheel for mysqlclient (setup.py) ... error\n  error: subprocess-exited-with-error\n\n  \xc3\x97 python setup.py bdist_wheel did not run successfully.\n  \xe2\x94\x82 exit code: 1\n  \xe2\x95\xb0\xe2\x94\x80> [44 lines of output]\n      mysql_config --version\n      ['10.5.5']\n      mysql_config --libs\n      ['-L/usr/lib64/', '-lmariadb']\n      mysql_config --cflags\n      ['-I/usr/include/mysql', '-I/usr/include/mysql/mysql']\n      ext_options:\n        library_dirs: ['/usr/lib64/']\n        libraries: ['mariadb']\n        extra_compile_args: ['-std=c99']\n        extra_link_args: []\n        include_dirs: ['/usr/include/mysql', '/usr/include/mysql/mysql']\n        extra_objects: []\n        define_macros: [('version_info', "(2,1,0,'final',0)"), ('__version__', '2.1.0')]\n      running bdist_wheel\n      running build\n      running build_py\n      creating build\n      creating build/lib.linux-x86_64-cpython-39\n      creating build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/__init__.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/connections.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/converters.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/cursors.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/release.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/times.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      creating build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      running build_ext\n      building 'MySQLdb._mysql' extension\n      creating build/temp.linux-x86_64-cpython-39\n      creating build/temp.linux-x86_64-cpython-39/MySQLdb\n      gcc -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -ftree-vectorize -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -ftree-vectorize -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -ftree-vectorize -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(2,1,0,'final',0) -D__version__=2.1.0 -I/usr/include/mysql -I/usr/include/mysql/mysql -I/home/ec2-user/myapp/env/include -I/usr/include/python3.9 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-cpython-39/MySQLdb/_mysql.o -std=c99\n      MySQLdb/_mysql.c:46:10: fatal error: Python.h: No such file or directory\n         46 | #include "Python.h"\n            |          ^~~~~~~~~~\n      compilation terminated.\n      error: command '/usr/bin/gcc' failed with exit code 1\n      [end of output]\n\n  note: This error originates from a subprocess, and is likely not a problem with pip.\n  ERROR: Failed building wheel for mysqlclient\n  Running setup.py clean for mysqlclient\nSuccessfully built Flask-MySQLdb\nFailed to build mysqlclient\nInstalling collected packages: certifi, zipp, Werkzeug, urllib3, six, mysqlclient, MarkupSafe, itsdangerous, idna, colorama, click, charset-normalizer, requests, Jinja2, importlib-metadata, Flask, Flask-MySQLdb, Flask-Cors\n  Running setup.py install for mysqlclient ... error\n  error: subprocess-exited-with-error\n\n  \xc3\x97 Running setup.py install for mysqlclient did not run successfully.\n  \xe2\x94\x82 exit code: 1\n  \xe2\x95\xb0\xe2\x94\x80> [46 lines of output]\n      mysql_config --version\n      ['10.5.5']\n      mysql_config --libs\n      ['-L/usr/lib64/', '-lmariadb']\n      mysql_config --cflags\n      ['-I/usr/include/mysql', '-I/usr/include/mysql/mysql']\n      ext_options:\n        library_dirs: ['/usr/lib64/']\n        libraries: ['mariadb']\n        extra_compile_args: ['-std=c99']\n        extra_link_args: []\n        include_dirs: ['/usr/include/mysql', '/usr/include/mysql/mysql']\n        extra_objects: []\n        define_macros: [('version_info', "(2,1,0,'final',0)"), ('__version__', '2.1.0')]\n      running install\n      /home/ec2-user/myapp/env/lib/python3.9/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.\n        warnings.warn(\n      running build\n      running build_py\n      creating build\n      creating build/lib.linux-x86_64-cpython-39\n      creating build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/__init__.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/connections.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/converters.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/cursors.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/release.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      copying MySQLdb/times.py -> build/lib.linux-x86_64-cpython-39/MySQLdb\n      creating build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants\n      running build_ext\n      building 'MySQLdb._mysql' extension\n      creating build/temp.linux-x86_64-cpython-39\n      creating build/temp.linux-x86_64-cpython-39/MySQLdb\n      gcc -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -ftree-vectorize -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -ftree-vectorize -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -ftree-vectorize -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(2,1,0,'final',0) -D__version__=2.1.0 -I/usr/include/mysql -I/usr/include/mysql/mysql -I/home/ec2-user/myapp/env/include -I/usr/include/python3.9 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-cpython-39/MySQLdb/_mysql.o -std=c99\n      MySQLdb/_mysql.c:46:10: fatal error: Python.h: No such file or directory\n         46 | #include "Python.h"\n            |          ^~~~~~~~~~\n      compilation terminated.\n      error: command '/usr/bin/gcc' failed with exit code 1\n      [end of output]\n\n  note: This error originates from a subprocess, and is likely not a problem with pip.\nerror: legacy-install-failure\n\n\xc3\x97 Encountered error while trying to install package.\n\xe2\x95\xb0\xe2\x94\x80> mysqlclient\n\nnote: This is an issue with the package mentioned above, not pip.\nhint: See above for output from the failure.\n
Run Code Online (Sandbox Code Playgroud)\n

Mar*_*cin 13

在新的 Amazon Linux 2023 上,您必须执行以下操作:

# install pip (AL 2023 does not have one by default)
sudo dnf install -y pip

# install dependencies
sudo dnf install -y mariadb105-devel gcc python3-devel

# install mysqlclient
pip install mysqlclient
Run Code Online (Sandbox Code Playgroud)