0

I am following https://www.udemy.com/course/the-ultimate-beginners-guide-to-django-django-2-python-web-dev-website/learn/lecture/9517168#overview guide to build aDjango website on a Digital Ocean Server with Postgres database.

The guide that the teacher follows is the official Digital Ocean setup guide 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

Everything was fine until I am trying to Migrate the project on the server side:

  • 1st syntax that I have run in the terminal

    python manage.py makemigrations
    
  • 1st ERROR

     File "manage.py", line 16
     ) from exc
          ^
     SyntaxError: invalid syntax
    
  • 2nd syntax that I have run in the terminal

    python3 manage.py makemigrations
    
  • 2nd ERROR

      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
    
  • I have modified the original settings.py file and put the following to the bottom as in django local_settings import error

try:
    from .local_settings import *
except ImportError:
    pass
  • I have also tried the import settings correction (changed values for database data for posting) Django Local Settings
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',
    }
}

I still get the original ERRORs.

my manage.py file I have tried with both options



"""
# 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()

Update 1 based on comment of Pranita Gandhi

  • I have UnInstalled all 4 libraries that I had in the server VENV

  • On the local machine I have created a requirements.txt of the original venv as Pranita Gandhi have recommend it. Than putted it to the server and tried to install it to the now empty server venv.

pip3 install -r requirements.txt

  • I got the following ERORR:

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.

Update 2

I have tried to force the install based on https://github.com/googlesamples/assistant-sdk-python/issues/236 / moham96 commented on Apr 20, 2018

You are trying to install the package to a system folder which you don't have permissions to write to. You have three options(use only one of them):

  • 1-setup a virtual env to install the package (recommended):
python3 -m venv env
source ./env/bin/activate 
python -m pip install requirements.txt
  • 2-Install the package to the user folder:
python -m pip install --user requirements.txt
  • 3-use sudo to install to the system folder (not recommended)
sudo python -m pip install requirements.txt

Unfortunately non of these have solved my problem.

sogu
  • 2,738
  • 5
  • 31
  • 90

1 Answers1

1

Hi did you install and activate your virtual environment when prompted in the course. I think its likely the virtual environment.

Can you locate your venv or env folder in the server terminal?

  • 3
    Yes I did Install venv and it runs well. I have also installed the requirements file from the local project succesfully "Django==2.0.7 Pillow==5.0.0 psycopg2==2.7.4 psycopg2-binary==2.7.4 pytz==2018.3" but I am not sure they are the only one that are needed because I have accidentally installed some staff to my computers original venv. – sogu Dec 08 '19 at 12:34
  • 1
    you can update your requirements.txt by doing another pip freeze > requirements.txt and re-pushing and pulling. =Then try to migrate again. – Pranita Gandhi Dec 08 '19 at 12:42