Django 设置 DigitalOcean Postgres "DATABASES = {" 错误

Django Setting up DigitalOchean Postgre "DATABASES = {" ERORR

我正在按照 https://www.udemy.com/course/the-ultimate-beginners-guide-to-django-django-2-python-web-dev-website/learn/lecture/9517168#overview 指南在带有 Postgres 数据库的 Digital Ocean Server 上构建 Django 网站。

老师遵循的指南是官方的Digital Ocean设置指南https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04#creating-and-configuring-a-new-django-project

一切都很好,直到我尝试在服务器端迁移项目:

try:
    from .local_settings import *
except ImportError:
    pass
from settings import *

SECRET_KEY = 'MY_SECRET_KEY'

DEBUG = False

ALLOWED_HOSTS = ['164.143.264.187']

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'my_name',
        'USER': 'the_user_nameing_i_have',
        'PASSWORD': 'my_key',
        'HOST':'localhost',
        'POSRT': '6432',
    }
}

我仍然得到原来的错误。

我的 manage.py 文件我已经尝试过这两个选项



"""
# this commented out what the teacher has in his code
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "portfolio.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)
"""




# This is what I had
import os
import sys


def main():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'portfolio.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

根据 Pranita Gandhi 的评论更新 1

pip3 install -r requirements.txt


Collecting Django==2.0.7
  Using cached https://files.pythonhosted.org/packages/ab/15/cfde97943f0db45e4f999c60b696fbb4df59e82bbccc686770f4e44c9094/Django-2.0.7-py3-none-any.whl
Collecting Pillow==5.0.0
  Using cached https://files.pythonhosted.org/packages/9a/2f/86941111d108fd060190c994f15881283b98693c1c370e74885cfc470eb3/Pillow-5.0.0-cp36-cp36m-manylinux1_x86_64.whl
Collecting psycopg2==2.7.4
  Using cached https://files.pythonhosted.org/packages/92/15/92b5c363243376ce9cb879bbec561bba196694eb663a6937b4cb967e230e/psycopg2-2.7.4-cp36-cp36m-manylinux1_x86_64.whl
Collecting psycopg2-binary==2.7.4
  Using cached https://files.pythonhosted.org/packages/5f/0b/aa7078d3f6d27d951c38b6a1f4b99b71b2caecebb2921b2d808b5bf0e2e0/psycopg2_binary-2.7.4-cp36-cp36m-manylinux1_x86_64.whl
Collecting pytz==2018.3
  Using cached https://files.pythonhosted.org/packages/3c/80/32e98784a8647880dedf1f6bf8e2c91b195fe18fdecc6767dcf5104598d6/pytz-2018.3-py2.py3-none-any.whl
Installing collected packages: pytz, Django, Pillow, psycopg2, psycopg2-binary
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/lib/python3.6/site-packages'
Consider using the `--user` option or check the permissions.

更新 2

我试图强制安装基于 https://github.com/googlesamples/assistant-sdk-python/issues/236 / moham96 于 2018 年 4 月 20 日发表评论

您正在尝试将程序包安装到您没有写入权限的系统文件夹中。 您有三个选项(只使用其中一个):

python3 -m venv env
source ./env/bin/activate 
python -m pip install requirements.txt
python -m pip install --user requirements.txt
sudo python -m pip install requirements.txt

不幸的是,这些都没有解决我的问题。

您好,您是否在课程中出现提示时安装并激活了虚拟环境。我认为它可能是虚拟环境。

你能在服务器端找到你的 venv 或 env 文件夹吗?