我正在按照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网站。
老师遵循的指南是《数字海洋》官方设置指南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
在我尝试在服务器端迁移项目之前,一切都很好:
我在终端中运行的第一语法
python manage.py makemigrations
第一个错误
File "manage.py", line 16
) from exc
^
SyntaxError: invalid syntax
我在终端中运行的第二种语法
python3 manage.py makemigrations
第二次错误
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/djangodeploy/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/djangodeploy/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 317, in execute
settings.INSTALLED_APPS
File "/home/djangodeploy/.local/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/home/djangodeploy/.local/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/home/djangodeploy/.local/lib/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/djangodeploy/portfolio-project/portfolio/settings.py", line 137, in <module>
from .local_settings import *
File "/home/djangodeploy/portfolio-project/portfolio/local_settings.py", line 5
DATABASES = {
^
IndentationError: unexpected indent
我已经修改了原始settings.py文件,并将以下内容放到底部,如django local_settings import error
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
我已经卸载了服务器VENV中所有的4个库
在本地计算机上,我创建了原始venv的requirements.txt作为 普拉尼塔·甘地(Pranita Gandhi)推荐了它。然后,将其放入服务器并尝试将其安装到现在空的服务器venv中。
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
不幸的是,这些都不能解决我的问题。
答案 0 :(得分:1)
您好,系统提示您安装并激活您的虚拟环境。我认为它可能是虚拟环境。
可以在服务器终端中找到venv或env文件夹吗?