LoginSignup
5
2

More than 3 years have passed since last update.

poetry add psycopg2がEnvCommandErrorでコケた時にすること

Last updated at Posted at 2021-02-15

Flask + postgresqlで趣味グラムしていた時にこれで3時間ハマったので、その解決法です。

環境

M1 Mac
Mac OS 11.2.1 Big Sur
Python: 3.9.1
poetry: 1.1.4

事象

やったこと

poetry add psycopg2

エラー

Using version ^2.8.6 for psycopg2

Updating dependencies
Resolving dependencies... (0.1s)

Package operations: 1 install, 0 updates, 0 removals

  • Installing psycopg2 (2.8.6): Failed

  EnvCommandError

# 以下略

なるほどわからん
エラー内容をよく読んでみると

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

とある。
どうやらsslが見えなくてビルドに失敗しているようだ。

対処

  1. コマンドラインツールを入れる。
  2. homebrewでopensslをインストールする。
  3. openssl配下のlibとincludeを環境変数に指定してpoetry addを実行する。

コマンドラインツールを入れる。

※すでに入れている場合はスキップ可

$ xcode-select --install

homebrewでopensslをインストールする。

# インストール
$ brew install openssl

# 確認
$ brew info openssl

# この2つの変数が大事!次で使うよ
For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"

openssl配下のlibとincludeを環境変数に指定してpoetry addを実行する。

$ env LDFLAGS="-I/opt/homebrew/opt/openssl@1.1/include -L/opt/homebrew/opt/openssl@1.1/lib" poetry add psycopg2
Using version ^2.8.6 for psycopg2

Updating dependencies
Resolving dependencies... (0.1s)

Package operations: 1 install, 0 updates, 0 removals

  • Installing psycopg2 (2.8.6)

入りました!

参考

error installing psycopg2, library not found for -lssl

ld: library not found for -lssl

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2