rancavil / django-py3-openshift-quickstart

Django 1.6 git repository for OpenShift with Python 3.3
33 stars 20 forks source link

virtualenv? #2

Open kastork opened 10 years ago

kastork commented 10 years ago

Thanks for these starter projects, they're very helpful.

In https://github.com/rancavil/django-openshift-quickstart, you had a nice little tutorial on how to set up a virtualenv to run the app locally. You didn't include this in the py3 version of the project, so I performed all the same steps as in the other tutorial.

But it doesn't work. I get

(venv) % python manage.py runserver                                  wsgi/openshift (master ⚡) lanchester
Validating models...

0 errors found
May 14, 2014 - 06:23:03
Django version 1.6, using settings 'settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x106142a70>
Traceback (most recent call last):
  File "/Volumes/WorkHD/web/lobby2/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/utils/module_loading.py", line 21, in import_by_path
    module = import_module(module_path)
  File "/Volumes/WorkHD/web/lobby2/venv/lib/python3.3/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1529, in _find_and_load_unlocked
ImportError: No module named 'wsgi'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Volumes/WorkHD/web/lobby2/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/utils/autoreload.py", line 93, in wrapper
    fn(*args, **kwargs)
  File "/Volumes/WorkHD/web/lobby2/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/core/management/commands/runserver.py", line 118, in inner_run
    handler = self.get_handler(*args, **options)
  File "/Volumes/WorkHD/web/lobby2/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/contrib/staticfiles/management/commands/runserver.py", line 24, in get_handler
    handler = super(Command, self).get_handler(*args, **options)
  File "/Volumes/WorkHD/web/lobby2/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/core/management/commands/runserver.py", line 41, in get_handler
    return get_internal_wsgi_application()
  File "/Volumes/WorkHD/web/lobby2/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/core/servers/basehttp.py", line 57, in get_internal_wsgi_application
    error_prefix="WSGI application '%s' could not be loaded; " % app_path
  File "/Volumes/WorkHD/web/lobby2/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/utils/module_loading.py", line 26, in import_by_path
    sys.exc_info()[2])
  File "/Volumes/WorkHD/web/lobby2/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/utils/six.py", line 490, in reraise
    raise value.with_traceback(tb)
  File "/Volumes/WorkHD/web/lobby2/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/utils/module_loading.py", line 21, in import_by_path
    module = import_module(module_path)
  File "/Volumes/WorkHD/web/lobby2/venv/lib/python3.3/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1529, in _find_and_load_unlocked
django.core.exceptions.ImproperlyConfigured: WSGI application 'wsgi.application' could not be loaded; Error importing module wsgi: "No module named 'wsgi'"

But the little main program 'wsgi.py' at the root of the directory does start a local Django.

Is there no way to use manage.py on a local dev setup?

I'm using python 3.3.5 from homebrew on OSX.

plourenco75 commented 10 years ago

Same issue for me on Ubuntu 14.04 - with python3.3.5 in virtualenv. Can't run locally.

Qblack commented 10 years ago

I had this today as well. Managed to solve it in the following fashion. I am on windows though not sure if it will work for everyone.

I added

sys.path.append(os.path.join(os.path.dirname(__file__), '..', ".."))

inside openshift/manage.py

and

an else in mysite/wsgi.py

else:
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
ghost commented 10 years ago

Thanks Qblack. I'm on Linux Mint 17 and worked fine for me! :)

Enrices commented 9 years ago

I suggest a slightly different fix by operating change in settings.py, and wrap it by os.path.normpath() to avoid annoying OS issues !