Reputation: 129
I'm trying to get to the bottom of my problem regarding running any "migrate" command on my django project. I have a django app deployed in a virtual env and with mod_wsgi and apache2 the app is served properly at www.mysite.com/test/simulatore. The problem came when I edited the models, so I had to run
python manage.py makemigrations
After some initial troubleshooting I think I have isolated the problem on wsgi.py
If I try (from my virtualenv) to try to run the command
python -i /home/carma/mycarma_test/mycarma/mycarma/wsgi.py
this is the result
['/home/carma/mycarma_test/mycarma/mycarma', '/home/carma/mycarma/testenv/lib/python35.zip', '/home/carma/mycarma/testenv/lib/python3.5', '/home/carma/mycarma/testenv/lib/python3.5/plat-x86_64-linux-gnu', '/home/carma/mycarma/testenv/lib/python3.5/lib-dynload', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/home/carma/mycarma/testenv/lib/python3.5/site-packages', '/home/carma/mycarma_test/mycarma/mycarma/..', '/home/carma/mycarma_test', '/home/carma/mycarma_test/mycarma']
Traceback (most recent call last):
File "/home/carma/mycarma_test/mycarma/mycarma/wsgi.py", line 22, in <module>
application = get_wsgi_application()
File "/home/carma/mycarma/testenv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/home/carma/mycarma/testenv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/home/carma/mycarma/testenv/lib/python3.5/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/home/carma/mycarma/testenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/home/carma/mycarma/testenv/lib/python3.5/site-packages/django/conf/__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/carma/mycarma/testenv/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 944, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
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 '”mycarma'
As you can see the module mycarma (which is the project name) is reported with single quotes and the just the initial double quote
ImportError: No module named '”mycarma'
This tells me (I think) there is a configuration issue somewhere that is passing a wrong parameter, but I can't find where. Here are my settings:
Directory structure
mycarma_test
└── mycarma
├── manage.py
├── mycarma
│ ├── development_settings.py
│ ├── __init__.py
│ ├── settings.py
│ ├── test_settings.py
│ ├── urls.py
│ └── wsgi.py
├── requirements
│ ├── common.txt
│ ├── dev.txt
│ ├── prod.txt
│ └── test.txt
├── simulatore
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
└── templates
├── base.html
├── registration
│ └── login.html
└── simulatore
└── index.html
File wsgi in mycarma/mycarma
import os
import sys
from django.core.wsgi import get_wsgi_application
DJANGO_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
sys.path.append(DJANGO_PATH)
sys.path.append('/home/carma/mycarma_test')
sys.path.append('/home/carma/mycarma_test/mycarma')
print(sys.path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mycarma.settings")
application = get_wsgi_application()
Please note I added the two append and the print in order to test/troubleshoot. But also without them no luck. settings.py
ROOT_URLCONF = 'mycarma.urls'
STATIC_URL = '/static/'
STATIC_ROOT = '/home/carma/mycarma/static'
Apache2 conf file
<Directory /home/carma/mycarma/static>
Require all granted
</Directory>
WSGIDaemonProcess pydaemon-1 processes=1 threads=5 python-path=/home/carma/mycarma/ python-home=/home/carma/mycarma/mycarmaenv
WSGIDaemonProcess pydaemon-2 processes=1 threads=5 python-path=/home/carma/mycarma_test/mycarma/ python-home=/home/carma/mycarma/testenv
WSGIScriptAlias /simulatore /home/carma/mycarma/mycarma/wsgi.py
<Location /simulatore>
WSGIProcessGroup pydaemon-1
WSGIApplicationGroup %{GLOBAL}
</Location>
<Directory /home/carma/mycarma/mycarma>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias /test /home/carma/mycarma_test/mycarma/mycarma/wsgi.py
<Location /test>
WSGIProcessGroup pydaemon-2
WSGIApplicationGroup %{GLOBAL}
</Location>
<Directory /home/carma/mycarma_test/mycarma/mycarma>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Thanks.
EDIT: problem found In the dev bin/activate script the
DJANGO_SETTINGS_MODULE=”carma.test_settings”
used some weird double quotes. Modified and everything si working.
Upvotes: 1
Views: 930
Reputation: 1401
I am pretty sure that is because you have that extra double quote in your INSTALLED_APPS
django config. This is happening when django bootstraps and tries to load all your apps and it can't locate it.
Upvotes: 2