Python Forum

Full Version: Problem with flask on Mac
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi everyone I’m running Mac OS Ventura 13.2 and I’m trying to install flask-mysqldb library using pip on the terminal by running the code :
pip install flask-mysqldb
but I keep getting the following error :

% pip install flask-mysqldb
Collecting flask-mysqldb
Obtaining dependency information for flask-mysqldb from https://files.pythonhosted.org/packages/...l.metadata
Using cached Flask_MySQLdb-2.0.0-py3-none-any.whl.metadata (3.0 kB)
Requirement already satisfied: Flask>=1.0.4 in ./anaconda3/lib/python3.11/site-packages (from flask-mysqldb) (2.2.2)
Collecting mysqlclient>=2.2.0 (from flask-mysqldb)
Using cached mysqlclient-2.2.1.tar.gz (89 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [30 lines of output]
/bin/sh: pkg-config: command not found
/bin/sh: pkg-config: command not found
/bin/sh: pkg-config: command not found
Trying pkg-config --exists mysqlclient
Command 'pkg-config --exists mysqlclient' returned non-zero exit status 127.
Trying pkg-config --exists mariadb
Command 'pkg-config --exists mariadb' returned non-zero exit status 127.
Trying pkg-config --exists libmariadb
Command 'pkg-config --exists libmariadb' returned non-zero exit status 127.
Traceback (most recent call last):
File "/Users/amirhosein/anaconda3/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "/Users/amirhosein/anaconda3/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/amirhosein/anaconda3/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
^^^^^^^^^^^^^^^^^^^^^
File "/private/var/folders/rv/n6zb4_qs6ql1r8cc2gs7w8_w0000gn/T/pip-build-env-nqoa4iyp/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/private/var/folders/rv/n6zb4_qs6ql1r8cc2gs7w8_w0000gn/T/pip-build-env-nqoa4iyp/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
self.run_setup()
File "/private/var/folders/rv/n6zb4_qs6ql1r8cc2gs7w8_w0000gn/T/pip-build-env-nqoa4iyp/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 311, in run_setup
exec(code, locals())
File "<string>", line 155, in <module>
File "<string>", line 49, in get_config_posix
File "<string>", line 28, in find_package_name
Exception: Can not find valid pkg-config name.
Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
The first few lines of your output say

Output:
/bin/sh: pkg-config: command not found
Does pkg-config installed on MacOS, or do you have to install it from Homebrew or something?
(Dec-18-2023, 08:13 AM)ndc85430 Wrote: [ -> ]The first few lines of your output say

Output:
/bin/sh: pkg-config: command not found
Does pkg-config installed on MacOS, or do you have to install it from Homebrew or something?

How do I install it ?
Are you using Homebrew? brew install pkg-config should do it (see https://formulae.brew.sh/formula/pkg-config). If you're not using Homebrew, I'm not sure.
(Dec-18-2023, 11:05 AM)ndc85430 Wrote: [ -> ]Are you using Homebrew? brew install pkg-config should do it (see https://formulae.brew.sh/formula/pkg-config). If you're not using Homebrew, I'm not sure.

It says command not found,I even tried it with the $ sign as explained in the link you posted
You need to install Homebrew if you haven't already - see https://brew.sh/. No, you don't type the $. That's just an example of the shell prompt.
(Dec-18-2023, 05:33 PM)ndc85430 Wrote: [ -> ]You need to install Homebrew if you haven't already - see https://brew.sh/. No, you don't type the $. That's just an example of the shell prompt.

Didn’t fix it
You may be better off installing pymysql and using that. I'm on ubuntu linux and get the same install problem.
This link allowed me to install without errors
https://github.com/PyMySQL/mysqlclient#install
Now you are using Anaconda3 then most a environment be activated,(base) is the default one.
Are a environment activated?
It's best is to make new environment and not use (base) for this.
As you see here it goes over to a other version of Python that's not Anaconda.
/private/var/folders/rv/n6zb4_qs6ql1r8cc2gs7w8_w0000gn/T/pip-build-env-nqoa4iyp/overlay/lib/python3.11/s
This should of course not happen as you install to Anaconda,see the Path to Python 3.11 is different.
/Users/amirhosein/anaconda3/lib/python3.11/site-packages/pip
Example is i use Miniconda(work the same as Anaconda) and then first active a environment then it works.
G:\div_code
λ G:\miniconda3\Scripts\activate.bat tom_env

# When a environment it has (name_of_env) 
G:\div_code
(tom_env) λ pip install flask-mysqldb
Collecting flask-mysqldb
  Downloading Flask_MySQLdb-2.0.0-py3-none-any.whl (4.9 kB)
Collecting Flask>=1.0.4
  Using cached flask-3.0.0-py3-none-any.whl (99 kB)
Collecting mysqlclient>=2.2.0
  Downloading mysqlclient-2.2.1-cp310-cp310-win_amd64.whl (202 kB)
     |████████████████████████████████| 202 kB 731 kB/s
Collecting Jinja2>=3.1.2
  Using cached Jinja2-3.1.2-py3-none-any.whl (133 kB)
Collecting itsdangerous>=2.1.2
  Using cached itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Collecting click>=8.1.3
  Downloading click-8.1.7-py3-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 3.3 MB/s
Collecting blinker>=1.6.2
  Downloading blinker-1.7.0-py3-none-any.whl (13 kB)
Collecting Werkzeug>=3.0.0
  Downloading werkzeug-3.0.1-py3-none-any.whl (226 kB)
     |████████████████████████████████| 226 kB 6.4 MB/s
Requirement already satisfied: colorama in g:\miniconda3\envs\tom_env\lib\site-packages (from click>=8.1.3->Flask>=1.0.4->flask-mysqldb) (0.4.4)
Requirement already satisfied: MarkupSafe>=2.0 in g:\miniconda3\envs\tom_env\lib\site-packages (from Jinja2>=3.1.2->Flask>=1.0.4->flask-mysqldb) (2.0.1)
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.1.3-cp310-cp310-win_amd64.whl (17 kB)
Installing collected packages: MarkupSafe, Werkzeug, Jinja2, itsdangerous, click, blinker, mysqlclient, Flask, flask-mysqldb
  Attempting uninstall: MarkupSafe
    Found existing installation: MarkupSafe 2.0.1
    Uninstalling MarkupSafe-2.0.1:
      Successfully uninstalled MarkupSafe-2.0.1
  Attempting uninstall: Jinja2
    Found existing installation: Jinja2 3.0.3
    Uninstalling Jinja2-3.0.3:
      Successfully uninstalled Jinja2-3.0.3
Successfully installed Flask-3.0.0 Jinja2-3.1.2 MarkupSafe-2.1.3 Werkzeug-3.0.1 blinker-1.7.0 click-8.1.7 flask-mysqldb-2.0.0 itsdangerous-2.1.2 mysqlclient-2.2.1

# Test
G:\div_code
(tom_env) λ python
Python 3.10.1 | packaged by conda-forge | (main, Dec 22 2021, 01:34:40) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from flask_mysqldb import MySQL
>>> # No error
>>> exit()
Pages: 1 2