Streamlit cloud face issue in mysqlclient installing

Streamlit cloud is showing following issues

Collecting mysqlclient==2.1.0
  Downloading mysqlclient-2.1.0.tar.gz (87 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 87.6/87.6 KB 169.7 MB/s eta 0:00:00[2022-03-16 10:57:29.366586] 
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      /bin/sh: 1: mysql_config: not found
      /bin/sh: 1: mariadb_config: not found
      /bin/sh: 1: mysql_config: not found
      Traceback (most recent call last):
        File "<string>", line 36, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/var/tmp/pip-install-g8pp10fw/mysqlclient_a2d902fcbe474524b9682de4f54d6ffb/setup.py", line 15, in <module>
          metadata, options = get_config()
        File "/var/tmp/pip-install-g8pp10fw/mysqlclient_a2d902fcbe474524b9682de4f54d6ffb/setup_posix.py", line 70, in get_config
          libs = mysql_config("libs")
        File "/var/tmp/pip-install-g8pp10fw/mysqlclient_a2d902fcbe474524b9682de4f54d6ffb/setup_posix.py", line 31, in mysql_config
          raise OSError("{} not found".format(_mysql_config_path))
      OSError: mysql_config not found
      mysql_config --version
      mariadb_config --version
      mysql_config --libs
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Hi @Kalim_Amzad, welcome to the community! :wave: :partying_face:

To connect to a remote MySQL database from Streamlit Cloud, we recommend using the mysql-connector-python library instead, as demonstrated in this tutorial:

You will be unable to host a MySQL server on Streamlit Cloud and connect to it using mysqlclient.

However, if you insist on installing mysqlclient, there are additional steps required for a successful installation. The official Linux installation instructions state that the following Linux packages need to be installed first:

python3-dev, default-libmysqlclient-dev, and build-essential.

As these are apt-get depedencies, you will need to create a packages.txt file containing the following:

python3-dev
default-libmysqlclient-dev
build-essential

Next, add the following Python dependency to your requirements.txt:

mysqlclient

You will then be able to import MySQLdb in your app.

Best, :balloon:
Snehan

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.