Unable to install mysqlclient package on EC2 instance.

huangapple go评论96阅读模式
英文:

Unable to install mysqlclient package on EC2 instance

问题

以下是您提供的代码部分的翻译:

  1. I am trying to install mysqlclient Python package on an Amazon EC2 instance running Amazon Linux 2023 AMI.
  2. When I run ```pip install mysqlclient```, I get the following error message:
  3. Collecting mysqlclient==2.1.0
  4. Downloading mysqlclient-2.1.0.tar.gz (87 kB)
  5. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 87.6/87.6 kB 17.2 MB/s eta 0:00:00
  6. Preparing metadata (setup.py) ... error
  7. error: subprocess-exited-with-error
  8. × python setup.py egg_info did not run successfully.
  9. exit code: 1
  10. ╰─> [16 lines of output]
  11. /bin/sh: line 1: mysql_config: command not found
  12. /bin/sh: line 1: mariadb_config: command not found
  13. /bin/sh: line 1: mysql_config: command not found
  14. Traceback (most recent call last):
  15. File "<string>", line 2, in <module>
  16. File "<pip-setuptools-caller>", line 34, in <module>
  17. File "/tmp/pip-install-ywdhtbse/mysqlclient_802cda8d3393451492ff091d28d6482f/setup.py", line 15, in <module>
  18. metadata, options = get_config()
  19. File "/tmp/pip-install-ywdhtbse/mysqlclient_802cda8d3393451492ff091d28d6482f/setup_posix.py", line 70, in get_config
  20. libs = mysql_config("libs")
  21. File "/tmp/pip-install-ywdhtbse/mysqlclient_802cda8d3393451492ff091d28d6482f/setup_posix.py", line 31, in mysql_config
  22. raise OSError("{} not found".format(_mysql_config_path))
  23. OSError: mysql_config not found
  24. mysql_config --version
  25. mariadb_config --version
  26. mysql_config --libs
  27. [end of output]
  28. note: This error originates from a subprocess, and is likely not a problem with pip.
  29. error: metadata-generation-failed
  30. × Encountered error while generating package metadata.
  31. ╰─> See above for output.
  32. note: This is an issue with the package mentioned above, not pip.
  33. hint: See above for details.

希望这能帮助您解决问题。如果您需要更多帮助,请告诉我。

英文:

I am trying to install mysqlclient Python package on an Amazon EC2 instance running Amazon Linux 2023 AMI.

When I run pip install mysqlclient, I get the following error message:

  1. Collecting mysqlclient==2.1.0
  2. Downloading mysqlclient-2.1.0.tar.gz (87 kB)
  3. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 87.6/87.6 kB 17.2 MB/s eta 0:00:00
  4. Preparing metadata (setup.py) ... error
  5. error: subprocess-exited-with-error
  6. × python setup.py egg_info did not run successfully.
  7. exit code: 1
  8. ╰─> [16 lines of output]
  9. /bin/sh: line 1: mysql_config: command not found
  10. /bin/sh: line 1: mariadb_config: command not found
  11. /bin/sh: line 1: mysql_config: command not found
  12. Traceback (most recent call last):
  13. File "<string>", line 2, in <module>
  14. File "<pip-setuptools-caller>", line 34, in <module>
  15. File "/tmp/pip-install-ywdhtbse/mysqlclient_802cda8d3393451492ff091d28d6482f/setup.py", line 15, in <module>
  16. metadata, options = get_config()
  17. File "/tmp/pip-install-ywdhtbse/mysqlclient_802cda8d3393451492ff091d28d6482f/setup_posix.py", line 70, in get_config
  18. libs = mysql_config("libs")
  19. File "/tmp/pip-install-ywdhtbse/mysqlclient_802cda8d3393451492ff091d28d6482f/setup_posix.py", line 31, in mysql_config
  20. raise OSError("{} not found".format(_mysql_config_path))
  21. OSError: mysql_config not found
  22. mysql_config --version
  23. mariadb_config --version
  24. mysql_config --libs
  25. [end of output]
  26. note: This error originates from a subprocess, and is likely not a problem with pip.
  27. error: metadata-generation-failed
  28. × Encountered error while generating package metadata.
  29. ╰─> See above for output.
  30. note: This is an issue with the package mentioned above, not pip.
  31. hint: See above for details.

I have tried the following :

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

Can anyone suggest a solution to this problem?

Thanks in advance!

EDIT

Here are all the commands I did :

  • sudo yum update -y
  • sudo yum install python3 -y
  • sudo yum install python3-pip -y
  • sudo dnf install -y mariadb105-devel gcc
  • pip install mysqlclient==2.1.0 (in a virtual environment)

But with the last one I get the following error :

  1. Collecting importlib-metadata
  2. Downloading importlib_metadata-6.1.0-py3-none-any.whl (21 kB)
  3. Collecting zipp>=0.5
  4. Downloading zipp-3.15.0-py3-none-any.whl (6.8 kB)
  5. Building wheels for collected packages: Flask-MySQLdb, mysqlclient
  6. Building wheel for Flask-MySQLdb (setup.py) ... done
  7. Created wheel for Flask-MySQLdb: filename=Flask_MySQLdb-1.0.1-py3-none-any.whl size=4675 sha256=e0bb7388b33b749ec52908abdb0e34d15c10544c2c2c96932e9ee90b117e0cfa
  8. Stored in directory: /home/ec2-user/.cache/pip/wheels/48/ba/f7/32a9b364c18e9e479d5dd05305109e7a72d85d8e29c02a10ea
  9. Building wheel for mysqlclient (setup.py) ... error
  10. error: subprocess-exited-with-error
  11. × python setup.py bdist_wheel did not run successfully.
  12. exit code: 1
  13. ╰─> [44 lines of output]
  14. mysql_config --version
  15. ['10.5.5']
  16. mysql_config --libs
  17. ['-L/usr/lib64/', '-lmariadb']
  18. mysql_config --cflags
  19. ['-I/usr/include/mysql', '-I/usr/include/mysql/mysql']
  20. ext_options:
  21. library_dirs: ['/usr/lib64/']
  22. libraries: ['mariadb']
  23. extra_compile_args: ['-std=c99']
  24. extra_link_args: []
  25. include_dirs: ['/usr/include/mysql', '/usr/include/mysql/mysql']
  26. extra_objects: []
  27. define_macros: [('version_info', "(2,1,0,'final',0)"), ('__version__', '2.1.0')]
  28. running bdist_wheel
  29. running build
  30. running build_py
  31. creating build
  32. creating build/lib.linux-x86_64-cpython-39
  33. creating build/lib.linux-x86_64-cpython-39/MySQLdb
  34. copying MySQLdb/__init__.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  35. copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  36. copying MySQLdb/connections.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  37. copying MySQLdb/converters.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  38. copying MySQLdb/cursors.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  39. copying MySQLdb/release.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  40. copying MySQLdb/times.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  41. creating build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  42. copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  43. copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  44. copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  45. copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  46. copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  47. copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  48. running build_ext
  49. building 'MySQLdb._mysql' extension
  50. creating build/temp.linux-x86_64-cpython-39
  51. creating build/temp.linux-x86_64-cpython-39/MySQLdb
  52. 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
  53. MySQLdb/_mysql.c:46:10: fatal error: Python.h: No such file or directory
  54. 46 | #include "Python.h"
  55. | ^~~~~~~~~~
  56. compilation terminated.
  57. error: command '/usr/bin/gcc' failed with exit code 1
  58. [end of output]
  59. note: This error originates from a subprocess, and is likely not a problem with pip.
  60. ERROR: Failed building wheel for mysqlclient
  61. Running setup.py clean for mysqlclient
  62. Successfully built Flask-MySQLdb
  63. Failed to build mysqlclient
  64. Installing collected packages: certifi, zipp, Werkzeug, urllib3, six, mysqlclient, MarkupSafe, itsdangerous, idna, colorama, click, charset-normalizer, requests, Jinja2, importlib-metadata, Flask, Flask-MySQLdb, Flask-Cors
  65. Running setup.py install for mysqlclient ... error
  66. error: subprocess-exited-with-error
  67. × Running setup.py install for mysqlclient did not run successfully.
  68. exit code: 1
  69. ╰─> [46 lines of output]
  70. mysql_config --version
  71. ['10.5.5']
  72. mysql_config --libs
  73. ['-L/usr/lib64/', '-lmariadb']
  74. mysql_config --cflags
  75. ['-I/usr/include/mysql', '-I/usr/include/mysql/mysql']
  76. ext_options:
  77. library_dirs: ['/usr/lib64/']
  78. libraries: ['mariadb']
  79. extra_compile_args: ['-std=c99']
  80. extra_link_args: []
  81. include_dirs: ['/usr/include/mysql', '/usr/include/mysql/mysql']
  82. extra_objects: []
  83. define_macros: [('version_info', "(2,1,0,'final',0)"), ('__version__', '2.1.0')]
  84. running install
  85. /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.
  86. warnings.warn(
  87. running build
  88. running build_py
  89. creating build
  90. creating build/lib.linux-x86_64-cpython-39
  91. creating build/lib.linux-x86_64-cpython-39/MySQLdb
  92. copying MySQLdb/__init__.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  93. copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  94. copying MySQLdb/connections.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  95. copying MySQLdb/converters.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  96. copying MySQLdb/cursors.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  97. copying MySQLdb/release.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  98. copying MySQLdb/times.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
  99. creating build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  100. copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  101. copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  102. copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  103. copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  104. copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  105. copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
  106. running build_ext
  107. building 'MySQLdb._mysql' extension
  108. creating build/temp.linux-x86_64-cpython-39
  109. creating build/temp.linux-x86_64-cpython-39/MySQLdb
  110. 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
  111. MySQLdb/_mysql.c:46:10: fatal error: Python.h: No such file or directory
  112. 46 | #include "Python.h"
  113. | ^~~~~~~~~~
  114. compilation terminated.
  115. error: command '/usr/bin/gcc' failed with exit code 1
  116. [end of output]
  117. note: This error originates from a subprocess, and is likely not a problem with pip.
  118. error: legacy-install-failure
  119. × Encountered error while trying to install package.
  120. ╰─> mysqlclient
  121. note: This is an issue with the package mentioned above, not pip.
  122. hint: See above for output from the failure.

答案1

得分: 9

  1. 在新的Amazon Linux 2023上,你需要执行以下操作:
  2. ```bash
  3. # 安装pip(AL 2023默认没有安装)
  4. sudo dnf install -y pip
  5. # 安装依赖
  6. sudo dnf install -y mariadb105-devel gcc python3-devel
  7. # 安装mysqlclient
  8. pip install mysqlclient
  1. <details>
  2. <summary>英文:</summary>
  3. On fresh Amazon Linux 2023 you have to do:

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

  1. </details>

huangapple
  • 本文由 发表于 2023年4月6日 23:04:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951019.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定