0

django 1.11

python 3.6.3

I've been working on an initial django app and just changed the views, models and forms from individual files to directories. My development machine is a windows box running the latest PyCharm. I then "deployed" the updated files to a linux test machine.

On the linux machine I did makemigrations and migrate and that seemed to work. I then visited the site...

Traceback (most recent call last):
  File "/dh/passenger/helper-scripts/wsgi-loader.py", line 320, in <module>
    app_module = load_app()
  File "/dh/passenger/helper-scripts/wsgi-loader.py", line 61, in load_app
    return imp.load_source('passenger_wsgi', startup_file)
  File "/home/me/.pyenv/versions/3.5.2/lib/python3.5/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "passenger_wsgi.py", line 23, in <module>
    application = get_wsgi_application()
  File "/home/me/.pyenv/versions/3.5.2/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/home/me/.pyenv/versions/3.5.2/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/home/me/.pyenv/versions/3.5.2/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/home/me/.pyenv/versions/3.5.2/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/me/.pyenv/versions/3.5.2/lib/python3.5/site-packages/django/conf/__init__.py", line 110, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/home/me/.pyenv/versions/3.5.2/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'MyProject.settings'

I've done a fair amount of googling and see lots of issues of this kind but I have not found a solution.

I have tested the wsgi startup script and all the paths it builds/uses are correct and valid. The project looks like (pruned for brevity):

devSiteBase
|-- MyProject
|   |-- MyProject
|   |   |-- __init__.py
|   |   |-- settings.py
|   |   |-- urls.py
|   |   `-- wsgi.py
|   |-- Members
|   |   |-- __init__.py
|   |   |-- admin.py
|   |   |-- apps.py
|   |   |-- forms
|   |   |   |-- ...
|   |   |   |-- __init__.py
|   |   |-- models
|   |   |   |-- ...
|   |   |   |-- __init__.py
|   |   |-- tests.py
|   |   |-- urls.py
|   |   `-- views
|   |       |-- ...
|   |       |-- __init__.py
|   |-- __init__.py
|   |-- manage.py
|   `-- templates
|       |-- ...
|-- passenger_wsgi.py
|-- public
|   |-- ...

the wsgi startup script:

import os
import sys

from django.core.wsgi import get_wsgi_application

cwd = os.getcwd()
sys.path.append(cwd)
sys.path.append(os.path.join(cwd, 'MyProject'))
sys.path.append(os.path.join(cwd, 'MyProject/MyProject'))

HOME_DIR = os.path.expanduser('~')

INTERP = os.path.join(HOME_DIR, ".pyenv/versions/3.5.2/bin/python")

if sys.executable != INTERP:
    os.execl(INTERP, INTERP, *sys.argv)

sys.path.insert(0, os.path.join(HOME_DIR, '.pyenv/versions/3.5.2/bin'))
sys.path.insert(0, os.path.join(HOME_DIR, '.pyenv/versions/3.5.2/lib/python3.5/site-packages'))

os.environ['DJANGO_SETTINGS_MODULE'] = 'MyProject.settings'

application = get_wsgi_application()

I can run python manage.py diffsettings and that can obviously read the settings file.

Edit This issue is showing up on the linux platform not the PC.

7 Reeds
  • 2,419
  • 3
  • 32
  • 64

1 Answers1

0

When you are using Pycharm you need enable django environment for your project top right corner you need select edit configurations there you can add your settings file and enable django see this image it should be like thisenter image description here

Balaraju M
  • 473
  • 1
  • 3
  • 14
  • Thank you but the issue is not on the PC development machine but on the linux test platform. – 7 Reeds Dec 01 '17 at 13:01
  • I have no answer to the problem. What I reported has gone away as mysteriously as it appeared. There is another issue now... but that is for a different question. – 7 Reeds Dec 03 '17 at 19:17
  • SO admins: there need to be other categories of closing/flagging. I would delete/close this question but deleting "answered" questions is frowned on and none of the cancel/flag option fit. I'll leave it in your hands. – 7 Reeds Dec 03 '17 at 19:23
  • I am voting to close my own question as it is a dup of https://stackoverflow.com/questions/21069880/running-django-tutorial-tests-fail-no-module-named-polls-tests . The answer there is the answer to this as well. I had an init.py file in the wrong place. – 7 Reeds Dec 05 '17 at 04:03