前提・実現したいこと
前提:
Djangogirls tutorialの「PostgreSQLのインストール」で躓きました。
その中の「PythonのPostgreSQL用パッケージのインストール」までは問題なく進められていました。
参考:https://tutorial-extensions.djangogirls.org/ja/optional_postgresql_installation/
同様の問題を取り扱ったstack over flowの記事に書いてある対処法は一通り行いました。
参考:https://stackoverflow.com/questions/12906351/importerror-no-module-named-psycopg2
実現したいこと:
(myvenv) alcohole:~/environment/djangogirls (master) $ python -c "import psycopg2" Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'psycopg2'
のMuduleNotFoundErrorを解消したいです。
該当のソースコード
以下は、python, pip, herokuのバージョンの表示、postgreSQLの状態、
そして調べて出てきた対処法を一通り試してみたログとsettings.pyです。
### bash(AWS Cloud9のAmazon Linux)
(myvenv) alcohole:~/environment/djangogirls (master) $ python --version Python 3.6.8 (myvenv) alcohole:~/environment/djangogirls (master) $ pip --version pip 19.3.1 from /home/ec2-user/environment/djangogirls/myvenv/lib64/python3.6/dist-packages/pip (python 3.6) (myvenv) alcohole:~/environment/djangogirls (master) $ heroku -v heroku-cli/7.0.9 linux-x64 node-v10.16.3 (myvenv) alcohole:~/environment/djangogirls (master) $ psql psql: FATAL: role "ec2-user" does not exist (myvenv) alcohole:~/environment/djangogirls (master) $ sudo -u postgres psql could not change directory to "/home/ec2-user/environment/djangogirls" psql (9.2.24) Type "help" for help. postgres=# CREATE USER KentoHomma; ERROR: role "kentohomma" already exists postgres=# CREATE DATABASE djangogirls OWNER KentoHomma postgres-# ; ERROR: database "djangogirls" already exists postgres=# pip install psycopg2 postgres-# ^\ (myvenv) alcohole:~/environment/djangogirls (master) $ pip install psycopg2 Requirement already satisfied: psycopg2 in ./myvenv/lib/python3.6/dist-packages (2.8.4) (myvenv) alcohole:~/environment/djangogirls (master) $ python -c "import psycopg2" Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'psycopg2' (myvenv) alcohole:~/environment/djangogirls (master) $ pip install psycopg2-binary Requirement already satisfied: psycopg2-binary in ./myvenv/lib/python3.6/dist-packages (2.8.4) (myvenv) alcohole:~/environment/djangogirls (master) $ python -c "import psycopg2" Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'psycopg2' (myvenv) alcohole:~/environment/djangogirls (master) $ yum install postgresql-devel-8.4.20-4.el6_7.x86_64 Loaded plugins: priorities, update-motd, upgrade-helper You need to be root to perform this command. (myvenv) alcohole:~/environment/djangogirls (master) $ sudo yum install postgresql-devel-8.4.20-4.el6_7.x86_64 Loaded plugins: priorities, update-motd, upgrade-helper amzn-main | 2.1 kB 00:00:00 amzn-updates | 2.5 kB 00:00:00 1065 packages excluded due to repository priority protections No package postgresql-devel-8.4.20-4.el6_7.x86_64 available. Error: Nothing to do (myvenv) alcohole:~/environment/djangogirls (master) $ yum install python-psycopg2 Loaded plugins: priorities, update-motd, upgrade-helper You need to be root to perform this command. (myvenv) alcohole:~/environment/djangogirls (master) $ pip yum install python-psycopg2 ERROR: unknown command "yum" (myvenv) alcohole:~/environment/djangogirls (master) $ sudo yum install python-psycopg2 Loaded plugins: priorities, update-motd, upgrade-helper 1065 packages excluded due to repository priority protections Package python26-psycopg2-2.5.1-3.8.amzn1.x86_64 already installed and latest version Nothing to do (myvenv) alcohole:~/environment/djangogirls (master) $ python -c "import psycopg2" Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'psycopg2' (myvenv) alcohole:~/environment/djangogirls (master) $ sudo yum install build-dep python-psycopg2 Loaded plugins: priorities, update-motd, upgrade-helper 1065 packages excluded due to repository priority protections No package build-dep available. Package python26-psycopg2-2.5.1-3.8.amzn1.x86_64 already installed and latest version Nothing to do (myvenv) alcohole:~/environment/djangogirls (master) $ pip install psycopg2 Requirement already satisfied: psycopg2 in ./myvenv/lib/python3.6/dist-packages (2.8.4) (myvenv) alcohole:~/environment/djangogirls (master) $ sudo yum install libpq-dev Loaded plugins: priorities, update-motd, upgrade-helper 1065 packages excluded due to repository priority protections No package libpq-dev available. Error: Nothing to do (myvenv) alcohole:~/environment/djangogirls (master) $ pip install psycopg2 Requirement already satisfied: psycopg2 in ./myvenv/lib/python3.6/dist-packages (2.8.4) (myvenv) alcohole:~/environment/djangogirls (master) $ sudo python -m pip install psycopg2 Collecting psycopg2 Downloading https://files.pythonhosted.org/packages/84/d7/6a93c99b5ba4d4d22daa3928b983cec66df4536ca50b22ce5dcac65e4e71/psycopg2-2.8.4.tar.gz (377kB) 100% |████████████████████████████████| 378kB 2.7MB/s Building wheels for collected packages: psycopg2 Running setup.py bdist_wheel for psycopg2 ... done Stored in directory: /root/.cache/pip/wheels/7e/5b/53/30085c62689dcfce50c8f40759945a49eb856af082e9ebf751 Successfully built psycopg2 Installing collected packages: psycopg2 Successfully installed psycopg2-2.8.4 You are using pip version 9.0.3, however version 19.3.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. (myvenv) alcohole:~/environment/djangogirls (master) $ python -c "import psycopg2" Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'psycopg2' (myvenv) alcohole:~/environment/djangogirls (master) $ sudo yum install python3 python-dev python3-dev Loaded plugins: priorities, update-motd, upgrade-helper amzn-main | 2.1 kB 00:00:00 amzn-updates | 2.5 kB 00:00:00 1065 packages excluded due to repository priority protections No package python3 available. No package python-dev available. No package python3-dev available. Error: Nothing to do (myvenv) alcohole:~/environment/djangogirls (master) $ pip install psycopg2 Requirement already satisfied: psycopg2 in ./myvenv/lib/python3.6/dist-packages (2.8.4) (myvenv) alcohole:~/environment/djangogirls (master) $ python -c "import psycopg2" Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'psycopg2' (myvenv) alcohole:~/environment/djangogirls (master) $ easy_install psycopg2 Searching for psycopg2 Best match: psycopg2 2.8.4 Adding psycopg2 2.8.4 to easy-install.pth file Using /home/ec2-user/environment/djangogirls/myvenv/lib/python3.6/dist-packages Processing dependencies for psycopg2 Finished processing dependencies for psycopg2 (myvenv) alcohole:~/environment/djangogirls (master) $ python -c "import psycopg2" Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'psycopg2'
### settings.py(database部分)
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'djangogirls', 'USER': 'KentoHomma', 'PASSWORD': '', 'HOST': 'localhost', 'PORT': '', } }
補足情報(FW/ツールのバージョンなど)
server EC2
platform AmazonLinux
Django 2.0.2
git 2.14.5
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。