質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

1973閲覧

psycopg2に関するエラー

hjpehrbh

総合スコア2

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2023/01/12 08:02

前提

「動かして学ぶ!Python Django開発入門 第2版」という本に沿ってプログラムを作っています.

EC2インスタンスにSSH接続した後,
Python3.8 -m venv venv_private_diary
にてPython仮装環境を作りました.

Python仮想環境に入った後,
pip install -r requirements.txt
を実行したところエラーが出ました.

requirements.txtは,ローカルマシンのPython仮想環境で以下のように書き出しました.
pip freeze > requirements.txt

実現したいこと

pip install -r requirements.txt
を実行した際のエラーを解消したいです.

発生している問題・エラーメッセージ

エラーが発生しているのですが,最初にRequirement already satisfiedと出ているので問題ないのでしょうか.

Requirement already satisfied: asgiref==3.5.2 in ./venv_private_diary/lib/python3.8/site-packages (from -r requirements.txt (line 1)) (3.5.2) Collecting async-generator==1.10 Using cached async_generator-1.10-py3-none-any.whl (18 kB) Collecting attrs==22.1.0 Using cached attrs-22.1.0-py2.py3-none-any.whl (58 kB) Collecting beautifulsoup4==4.9.3 Using cached beautifulsoup4-4.9.3-py3-none-any.whl (115 kB) Requirement already satisfied: boto3==1.18.58 in ./venv_private_diary/lib/python3.8/site-packages (from -r requirements.txt (line 5)) (1.18.58) Requirement already satisfied: botocore==1.21.65 in ./venv_private_diary/lib/python3.8/site-packages (from -r requirements.txt (line 6)) (1.21.65) Collecting certifi==2022.9.24 Using cached certifi-2022.9.24-py3-none-any.whl (161 kB) Requirement already satisfied: cffi==1.15.1 in ./venv_private_diary/lib/python3.8/site-packages (from -r requirements.txt (line 8)) (1.15.1) Requirement already satisfied: charset-normalizer==2.1.1 in ./venv_private_diary/lib/python3.8/site-packages (from -r requirements.txt (line 9)) (2.1.1) 中略 Collecting psycopg2==2.9.5 Using cached psycopg2-2.9.5.tar.gz (384 kB) Preparing metadata (setup.py) ... done Requirement already satisfied: psycopg2-binary==2.9.1 in ./venv_private_diary/lib/python3.8/site-packages (from -r requirements.txt (line 39)) (2.9.1) Requirement already satisfied: pycparser==2.21 in ./venv_private_diary/lib/python3.8/site-packages (from -r requirements.txt (line 40)) (2.21) Requirement already satisfied: PyJWT==2.6.0 in ./venv_private_diary/lib/python3.8/site-packages (from -r requirements.txt (line 41)) (2.6.0) Collecting pyOpenSSL==22.1.0 Using cached pyOpenSSL-22.1.0-py3-none-any.whl (57 kB) Requirement already satisfied: pyparsing==2.4.7 in ./venv_private_diary/lib/python3.8/site-packages (from -r requirements.txt (line 43)) (2.4.7) 中略 Collecting wsproto==1.2.0 Using cached wsproto-1.2.0-py3-none-any.whl (24 kB) Requirement already satisfied: zipp==3.8.0 in ./venv_private_diary/lib/python3.8/site-packages (from -r requirements.txt (line 66)) (3.8.0) Requirement already satisfied: backports.zoneinfo in ./venv_private_diary/lib/python3.8/site-packages (from Django==4.1.3->-r requirements.txt (line 14)) (0.2.1) Requirement already satisfied: setuptools>=3.0 in ./venv_private_diary/lib/python3.8/site-packages (from gunicorn==20.1.0->-r requirements.txt (line 21)) (65.6.3) Installing collected packages: psycopg2, Pillow, numpy, MarkupSafe, kiwisolver, joblib, itsdangerous, importlib-metadata, h11, exceptiongroup, Django, cycler, click, certifi, beautifulsoup4, attrs, async-generator, wsproto, scipy, pandas, outcome, opencv-python, matplotlib, Jinja2, trio, scikit-learn, pyOpenSSL, Flask, trio-websocket, selenium DEPRECATION: psycopg2 is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559 Running setup.py install for psycopg2 ... error error: subprocess-exited-with-error × Running setup.py install for psycopg2 did not run successfully. │ exit code: 1 ╰─> [42 lines of output] /home/app_admin/venv_private_diary/lib64/python3.8/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead. warnings.warn(msg, warning_class) running install /home/app_admin/venv_private_diary/lib64/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. warnings.warn( running build running build_py creating build creating build/lib.linux-x86_64-cpython-38 creating build/lib.linux-x86_64-cpython-38/psycopg2 copying lib/__init__.py -> build/lib.linux-x86_64-cpython-38/psycopg2 copying lib/_ipaddress.py -> build/lib.linux-x86_64-cpython-38/psycopg2 copying lib/_json.py -> build/lib.linux-x86_64-cpython-38/psycopg2 copying lib/_range.py -> build/lib.linux-x86_64-cpython-38/psycopg2 copying lib/errorcodes.py -> build/lib.linux-x86_64-cpython-38/psycopg2 copying lib/errors.py -> build/lib.linux-x86_64-cpython-38/psycopg2 copying lib/extensions.py -> build/lib.linux-x86_64-cpython-38/psycopg2 copying lib/extras.py -> build/lib.linux-x86_64-cpython-38/psycopg2 copying lib/pool.py -> build/lib.linux-x86_64-cpython-38/psycopg2 copying lib/sql.py -> build/lib.linux-x86_64-cpython-38/psycopg2 copying lib/tz.py -> build/lib.linux-x86_64-cpython-38/psycopg2 running build_ext building 'psycopg2._psycopg' extension creating build/temp.linux-x86_64-cpython-38 creating build/temp.linux-x86_64-cpython-38/psycopg gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC "-DPSYCOPG_VERSION=2.9.5 (dt dec pq3 ext lo64)" -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -I/home/app_admin/venv_private_diary/include -I/usr/include/python3.8 -I. -I/usr/include -I/usr/include/pgsql/server -c psycopg/adapter_asis.c -o build/temp.linux-x86_64-cpython-38/psycopg/adapter_asis.o -Wdeclaration-after-statement In file included from psycopg/adapter_asis.c:28:0: ./psycopg/psycopg.h:35:10: 致命的エラー: Python.h: No such file or directory #include <Python.h> ^~~~~~~~~~ コンパイルを停止しました。 It appears you are missing some prerequisite to build the package from source. You may install a binary package by installing 'psycopg2-binary' from PyPI. If you want to install psycopg2 from source, please install the packages required for the build and try again. For further information please check the 'doc/src/install.rst' file (also at <https://www.psycopg.org/docs/install.html>). error: command '/usr/bin/gcc' failed with exit code 1 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure × Encountered error while trying to install package. ╰─> psycopg2 note: This is an issue with the package mentioned above, not pip. hint: See above for output from the failure.

該当のソースコード

pip install -r requirements.txt

試したこと

1.
xcode-select --install
を実行しようとしましたが,
-bash: xcode-select: コマンドが見つかりません
となります.

2.
pip install psycopg2-binary
の実行結果です.

Requirement already satisfied: psycopg2-binary in ./venv_private_diary/lib/python3.8/site-packages (2.9.1)

3.
sudo yum install openssl
の実行結果です.

読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd amzn2-core | 3.7 kB 00:00 224 packages excluded due to repository priority protections パッケージ 1:openssl-1.0.2k-24.amzn2.0.4.x86_64 はインストール済みか最新バージョンです 何もしません

補足情報(FW/ツールのバージョンなど)

macOS: Venura 13.1

Pythonのバージョン

ローカルマシンのPython仮想環境で
python -V
を実行すると
Python 3.9.1
と出ました.

EC2インスタンスにSSH接続した後にPython仮想環境で実行すると
Python 3.8.15
と出ました.

参考

試したこと1, 2
https://stackoverflow.com/questions/26288042/error-installing-psycopg2-library-not-found-for-lssl

試したこと3
https://dev.classmethod.jp/articles/mac-psycopg2-install/

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

quickquip

2023/01/12 08:42

psycopg2-binary が入ったならそれでいい気がしますが、実際なにかに困っていますか?
hjpehrbh

2023/01/12 08:44

いえ,この先の作業を進めるにあたってこのエラーの影響が出てこないか不安です.
quickquip

2023/01/12 08:57

psycopg2-binary と psycopg2 の両方を入れて大丈夫なのか どうして psycopg2-binary が Requirement already satisfied なのか の方に不安を感じました (psycopg2-binaryが入っていることは想定どおりなのでしょうか?)
guest

回答1

0

自己解決

psycopg2-binaryがあればいいことが判明しました.

投稿2023/01/19 03:05

hjpehrbh

総合スコア2

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問