LoginSignup
0
1

More than 1 year has passed since last update.

psycopg2.extensionsが見つからない時の対処法

Posted at

概説

djangoでPostgreSQLを使ったWebアプリを作るとき、macOS(intel)の仮想環境上でshowmigrationmakemigrationを実行しようとしたらModuleNotFoundError: No module named 'psycopg2.extensions'が出てしまったとき、wheelとsetuptoolsをアップデートした上でpsycopg2-binaryを強制的に再インストールすることで解決した。

環境

環境は以下の通りです。

名称 バージョン
macOS Monterey(12.1)
django 4.0.1
Python 3.8.9
brew 3.3.10
pip 21.3.1
psycopg2-binary 2.9.3
PostgreSQL 14.1

対処法

仮想環境上で以下のコマンドを実行してください。

shell
pip install --upgrade wheel
pip install --upgrade setuptools
pip3.9 install psycopg2-binary --force-reinstall --no-cache-dir

補足

psycopg2のキャッシュが残っていたりするとマズイらしい。
pg_configを使えるか確認したり、psycopg2を再インストールしたつもりだけど上手くいかないという人は試してみてください。

shell
python3 manage.py makemigrations [yourAppName]

[yourAppName]は自身のアプリに置き換えてください。
単に

shell
python3 manage.py makemigrations

としてしまうとNo changes detectedとなってしまう場合があります。

また、仮想環境上で実行しないとConnectionRefusedError: [Errno 61] Connection refusedで弾かれるので注意が必要です。(python2系で実行した場合もSyntax Errorとなるので注意。)

0
1
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
0
1