When deploying my app, I get this error while trying to install
Exception: Can not find valid pkg-config name.
Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
I don’t want to have to set these vars manually but would prefer to install
pkg-config on my Windows computer. I downloaded the
w64devkit from Releases · skeeto/w64devkit · GitHub and placed the files off the root like this:
C:\w64devkit\bin\pkg-config.exe and then added this location to the PATH variable but this did not work.
When I check to see the version number it shows
Why can’t the build process locate the
pkg-config file? I must be doing something wrong. Any suggestions?
Not getting much love here. Is there anyone who can help me resolve this?
In setting the path, there are ways to do this graphically (How to Set the Path and Environment Variables in Windows) or in the command line (set | Microsoft Learn) via
As for the environment variable name, not sure if
PATH is the only environment variable that it may refer to. Could you verify that the
PATH variable contains the path:
Alternatively, there seems to be a Python package called
pykg-config that serves as a Python drop-in replacement for pkg-config.
Hope this helps.
When I check the
PATH variable, by entering
I can see that the location of my
pkg-config.exe file which is located in
C:\msys64\mingw64\bin as seen here:
But I still keep getting the same error saying
pkg-config: not found as seen here:
I see a reference to
/bin/sh but I don’t know what that is referring to. Although I was able to install the
pykg--config package without error, that did not resolve the problem I am still having with the
mysqlclient installation process during deployment.
Perhaps it is not necessary for me to list
mysqlclient in the requirements.txt file. When I do
pip install mysqlclient it tells me ‘Requirement already satisfied…’:
If you have any more suggestions, please let me know, Thanks.
Looking at the README page of
mysqlclient (https://github.com/PyMySQL/mysqlclient/blob/main/README.md) indicated that you’ll need to have the DB connector installed in addition to
mysqlclient. Please see if you can either download a binary version for use as building one seems to be a bit buggy (in reference to the above README page.
As for the pkg-config not being found at
/bin/sh which seems odd as you’re using a Windows and the mentioned path seems to be Linux based. Getting the environment path right on Windows also seem to be a rabbit hole in itself as the pre-defined default path is not clearly stated. Thus, the next steps would be to try the above installation of the DB connector.
If the above does not work, I think it may be easier to start fresh by using a package manager like conda (I’d prefer mini-conda as it has a light footprint on the computer) where you can install a fresh Python installation for a new conda environment, that way all dependencies will be handled by conda.
Not quite sure if this helps, but it is the thought process of how I would approach the problem.
Let me know how it goes.
Thanks for your ideas Chanin. I was able to download the MariaDB C Connector and install it, but that didn’t seem to make any difference as I still get the same errors with the
mysqlclient install failing because
pkg-config not found.
I then decided to try your suggestion of using
Miniconda3. I was able to get both the DB connector and the DB client packages installed as seen here:
I also used
miniconda3 to install
Both of these package installs completed successfully but when I rebooted my Streamlit app I still keep getting the same error about
pkg-config: not found
I noticed that the error message is still mentioning the
/bin/sh: path which is not where the DB Connector and DB Client were installed using
miniconda3. They appear to have been installed in:
How can I update the Streamlit app to look in the right place for the required packages (DB Connector, DB Client, pkg-config) that have now been successfully installed using
p.s. I am wondering whether doing the command
conda install mysqlclient needs to be done from the project directory? I don’t think so, and didn’t do that in my test discussed above.
I hope this makes at least some sense. I’m tired and need to sleep now. Looking forward to hearing your thoughts… again.
Thanks for the update and sounds like we’re making some progress. It seems from the screenshot that you’re using Python 3.7 and starting from Streamlit 1.24.0 it requires at least 3.8 as 3.7 is no longer supported. Also have you tried following the tutorial on setting up a MySQL connecting with Streamlit:
The above tutorial seems to require
and you can now use st.experimental_connection for connecting to the database.
Hi again. Unfortunately I am still stuck. I created a new virtual environment and it still gives me the same error when trying to install mysqlclient.
This is all very frustrating because everything works fine under localhost, but fails when prtocessing the dependencies during deployment.
Here is what I have noticed:
- When I run under localhost I am using
poetry install the dependencies contained in pyproject.toml
- During the deployment process, the dependencies are contained in requirements.txt
I don’t know what to try next.
Sorry to hear that it is still not working. Would you like to share the code repo to your app. This is the best way to allow the reproduction of the error.
One final update for anyone following along. I managed to resolve this issue by switching from
pymysql in the requirements.txt file. I also added this line to my connections credential information:
driver = "pymysql" as shown here:
dialect = "mysql"
driver = "pymysql"
host = "123.456.789.123"
port = "3306"
database = "my_database"
username = "my_user"
password = "mypassword"
This avoids using
mysqlclient which was causing all the problems.
Thanks! It works to me too.
Thank you, It works for me. Been trying to find a fix for hours.
For linux OS base on debian like Ubuntu, install package libmysqlclient-dev fix the issue.
You can do
sudo apt install libmysqlclient-dev