Relative imports require the 'package' argument

前端 未结 5 1602
太阳男子
太阳男子 2021-02-07 01:44

I want to use Sphinx so it can automatically generate a pydoc for my python code but I\'m getting an error. What an I doing wrong?

conf.py sphinx config

相关标签:
5条回答
  • 2021-02-07 01:49

    DJANGO_SETTINGS_MODULE is expected to be a Python module identifier, not a filesystem path. Looking at the django/conf/__init__py file, it seems that a relative path to your settings module won't work there. You will need to move it below a directory listed in your sys.path, or you should add a parent directory to your sys.path and reference your settings module from there.

    0 讨论(0)
  • 2021-02-07 01:53

    you need to add your project path to sys path just like

    sys.path.append("C:\\Users\\ogward\\STUDPROJ") 
    os.environ['DJANGO_SETTINGS_MODULE'] = '../cloud_server.settings'
     
    
    0 讨论(0)
  • 2021-02-07 01:56
    1. may be the settings you set in uwsgi.py is not correct
    2. the settings path in uwsgi.py(XXXX is in the same dir as uwsgi.py):

      os.environ.setdefault("DJANGO_SETTINGS_MODULE", "XXXX.settings")

    0 讨论(0)
  • 2021-02-07 02:03

    You can also get this error simply if you have a typo in where you're specifying your settings file name.

    0 讨论(0)
  • 2021-02-07 02:08

    I came to this question via Google, so I'll answer what helped me (not directly related to the question).

    I use importlib to dynamically import sub-packages given by a string.

    import importlib
    module_name = 'subpackage.i.import'
    special_module = importlib.import_module(module_name, package=None)
    

    This simply has to be adjusted to

    import importlib
    module_name = 'subpackage.i.import'
    special_module = importlib.import_module(module_name, package='my_current_pkg')
    
    0 讨论(0)
提交回复
热议问题