db client (M1)

数据库MySQL约 448 字大约 1 分钟

mysql

pip install mysqlclient==1.4.4

安装 mysqlclient 会出现下面的问题:

mysql_config not found

若不需要安装mysql服务,直接安装客户端即可

brew install mysql-client pkg-config

安装完成后,检查命令是否可执行

which mysql_config

箬笠报错如下

Exception: Can not find valid pkg-config name.
      Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually

修改环境变量

export MYSQLCLIENT_CFLAGS=$(mysql_config --cflags)
export MYSQLCLIENT_LDFLAGS=$(mysql_config --libs)

此时继续安装 mysqlclient

pip install mysqlclient==1.4.4

若报错如下

    ld: library not found for -lzstd
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command '/usr/bin/gcc' failed with exit code 1

安装zstd

brew install zstd

修改环境变量

export CFLAGS="-I$(brew --prefix)/include"
export LDFLAGS="-L$(brew --prefix)/lib"

# 若不生效,则使用

export LDFLAGS="-L/opt/homebrew/Cellar/zstd/1.5.6/lib"
#具体版本以安装的版本为准 

再次安装即可

postgre

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      running egg_info
      creating /private/var/folders/bp/jkzx65zj6sq1xj6bb5bkt03w0000gn/T/pip-pip-egg-info-37d85hev/psycopg2.egg-info
      writing /private/var/folders/bp/jkzx65zj6sq1xj6bb5bkt03w0000gn/T/pip-pip-egg-info-37d85hev/psycopg2.egg-info/PKG-INFO
      writing dependency_links to /private/var/folders/bp/jkzx65zj6sq1xj6bb5bkt03w0000gn/T/pip-pip-egg-info-37d85hev/psycopg2.egg-info/dependency_links.txt
      writing top-level names to /private/var/folders/bp/jkzx65zj6sq1xj6bb5bkt03w0000gn/T/pip-pip-egg-info-37d85hev/psycopg2.egg-info/top_level.txt
      writing manifest file '/private/var/folders/bp/jkzx65zj6sq1xj6bb5bkt03w0000gn/T/pip-pip-egg-info-37d85hev/psycopg2.egg-info/SOURCES.txt'
      
      Error: pg_config executable not found.
      
      pg_config is required to build psycopg2 from source.  Please add the directory
      containing pg_config to the $PATH or specify the full executable path with the
      option:
      
          python setup.py build_ext --pg-config /path/to/pg_config build ...
      
      or with the pg_config option in 'setup.cfg'.
      
      If you prefer to avoid building psycopg2 from source, please install the PyPI
      'psycopg2-binary' package instead.
      
      For further information please check the 'doc/src/install.rst' file (also at
      <https://www.psycopg.org/docs/install.html>).
      
      [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.

https://stackoverflow.com/questions/66888087/cannot-install-psycopg2-with-pip3-on-m1-macopen in new window

安装pgsql

 brew install postgresql@16

导入环境变量

export PATH="/opt/homebrew/opt/postgresql@16/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/postgresql@16/lib"
export CPPFLAGS="-I/opt/homebrew/opt/postgresql@16/include"