[GH-ISSUE #433] Attempted relative import in non-package on local_settings setup #311

Closed
opened 2026-02-26 10:30:45 +03:00 by kerem · 5 comments
Owner

Originally created by @webmst on GitHub (Jun 3, 2019).
Original GitHub issue: https://github.com/nsupdate-info/nsupdate.info/issues/433

Hi everybody,
after having 'git cloned' nsupdate.info in /usr/local/nsupdate (FreeBSD 12/python2.7), attempting setup of a local_settings.py file (as per instructions) with:

export DJANGO_SETTINGS_MODULE=local_settings
export PYTHONPATH=/usr/local/nsupdate/src/nsupdate/settings

trying to execute the 'dev' environment for the first time, I get:

[root@localhost /usr/local/nsupdate]# python2.7 manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 9, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 308, in execute
    settings.INSTALLED_APPS
  File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/nsupdate/src/nsupdate/settings/local_settings.py", line 5, in <module>
    from .base import *
ValueError: Attempted relative import in non-package

Does anybody see what's wrong?

Originally created by @webmst on GitHub (Jun 3, 2019). Original GitHub issue: https://github.com/nsupdate-info/nsupdate.info/issues/433 Hi everybody, after having 'git cloned' nsupdate.info in /usr/local/nsupdate (FreeBSD 12/python2.7), attempting setup of a local_settings.py file (as per instructions) with: ``` export DJANGO_SETTINGS_MODULE=local_settings export PYTHONPATH=/usr/local/nsupdate/src/nsupdate/settings ``` trying to execute the 'dev' environment for the first time, I get: ``` [root@localhost /usr/local/nsupdate]# python2.7 manage.py runserver Traceback (most recent call last): File "manage.py", line 9, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 308, in execute settings.INSTALLED_APPS File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__ self._setup(name) File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup self._wrapped = Settings(settings_module) File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/usr/local/nsupdate/src/nsupdate/settings/local_settings.py", line 5, in <module> from .base import * ValueError: Attempted relative import in non-package ``` Does anybody see what's wrong?
kerem closed this issue 2026-02-26 10:30:45 +03:00
Author
Owner

@ThomasWaldmann commented on GitHub (Jun 3, 2019):

can you try:

export DJANGO_SETTINGS_MODULE=local_settings
export PYTHONPATH=/usr/local/nsupdate/src

when starting, guess you need to be in the same dir as local_settings.py.

<!-- gh-comment-id:498180929 --> @ThomasWaldmann commented on GitHub (Jun 3, 2019): can you try: ``` export DJANGO_SETTINGS_MODULE=local_settings export PYTHONPATH=/usr/local/nsupdate/src ``` when starting, guess you need to be in the same dir as local_settings.py.
Author
Owner

@ThomasWaldmann commented on GitHub (Jun 3, 2019):

also, try to use python3.x if possible.

<!-- gh-comment-id:498181151 --> @ThomasWaldmann commented on GitHub (Jun 3, 2019): also, try to use python3.x if possible.
Author
Owner

@webmst commented on GitHub (Jun 3, 2019):

ThomasWaldmann, thanks for the kind reply.

the solution you suggested didn't work, same error.

After many retries, I discovered that to solve, I had to use:

export DJANGO_SETTINGS_MODULE=nsupdate.settings.local_settings

without setting PYTHONPATH

<!-- gh-comment-id:498184972 --> @webmst commented on GitHub (Jun 3, 2019): ThomasWaldmann, thanks for the kind reply. the solution you suggested didn't work, same error. After many retries, I discovered that to solve, I had to use: ` export DJANGO_SETTINGS_MODULE=nsupdate.settings.local_settings ` without setting PYTHONPATH
Author
Owner

@ThomasWaldmann commented on GitHub (Jun 3, 2019):

Quoting from the docs:

But do not change anything in there, but rather create your own local_settings.py file,
import from our settings and override anything you want to change afterwards.:

from nsupdate.settings.dev import *
SECRET_KEY='S3CR3T'

That looks different than the import in your local_settings.py file:

  File "/usr/local/nsupdate/src/nsupdate/settings/local_settings.py", line 5, in <module>
    from .base import *
<!-- gh-comment-id:498187601 --> @ThomasWaldmann commented on GitHub (Jun 3, 2019): Quoting from the docs: ``` But do not change anything in there, but rather create your own local_settings.py file, import from our settings and override anything you want to change afterwards.: from nsupdate.settings.dev import * SECRET_KEY='S3CR3T' ``` That looks different than the import in your local_settings.py file: ``` File "/usr/local/nsupdate/src/nsupdate/settings/local_settings.py", line 5, in <module> from .base import * ```
Author
Owner

@webmst commented on GitHub (Jun 3, 2019):

I agree with you, this is what made me not to undestand!

Infact, as per instructions, I had already created a local_settings.py file not to modify the original dev/prod .py files, but I was unable to make it processed setting the DJANGO_SETTINGS_MODULE variable.

I think that the issue is due to the 'home' python directory already set to '/usr/local/nsupdate/src' in my python FreeBSD system.

<!-- gh-comment-id:498206546 --> @webmst commented on GitHub (Jun 3, 2019): I agree with you, this is what made me not to undestand! Infact, as per instructions, I had already created a local_settings.py file not to modify the original dev/prod .py files, but I was unable to make it processed setting the DJANGO_SETTINGS_MODULE variable. I think that the issue is due to the 'home' python directory already set to '/usr/local/nsupdate/src' in my python FreeBSD system.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nsupdate.info-nsupdate-info#311
No description provided.