PyCharm Django test runner can't see django.sites (Runtime Error) - python

When I run manage.py test everything is working normally, but if run test with PyCharm Django Tests it gives me following error:
Error
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib/python3.4/unittest/case.py", line 577, in run
testMethod()
File "/usr/lib/python3.4/unittest/loader.py", line 32, in testFailure
raise exception
ImportError: Failed to import test module: order_form.tests
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
module = self._get_module_from_name(name)
File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
__import__(name)
File "/home/vagrant/project/order_form/tests.py", line 2, in <module>
from .models import Order
File "/home/vagrant/project/order_form/models.py", line 3, in <module>
from cms.models.pluginmodel import CMSPlugin
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/cms/models/__init__.py", line 3, in <module>
from .pagemodel import * # nopyflakes
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/cms/models/pagemodel.py", line 6, in <module>
from django.contrib.sites.models import Site
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/django/contrib/sites/models.py", line 83, in <module>
class Site(models.Model):
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Yes, I've enabled 'django.contrib.sites' in INSTALLED_APPS and SITE_ID is set.
Any ideas?

I created local virtualenv and install same requirements — tests work fine with it.
Thanks, everybody for comments.

Related

How can I fix this error from importing module pyautogui?

I run the python code from the root. Shows an error when I just imported the module:
ERROR : Traceback (most recent call last):
File "/home/amir/photo.py", line 4, in <module>
import pyautogui as gui
File "/usr/local/lib/python3.9/dist-packages/pyautogui/__init__.py", line 249, in <module>
import mouseinfo
File "/usr/local/lib/python3.9/dist-packages/mouseinfo/__init__.py", line 223, in <module>
_display = Display(os.environ['DISPLAY'])
File "/usr/local/lib/python3.9/dist-packages/Xlib/display.py", line 80, in __init__
self.display = _BaseDisplay(display)
File "/usr/local/lib/python3.9/dist-packages/Xlib/display.py", line 62, in __init__
display.Display.__init__(*(self, ) + args, **keys)
File "/usr/local/lib/python3.9/dist-packages/Xlib/protocol/display.py", line 129, in __init__
raise error.DisplayConnectionError(self.display_name, r.reason)
Xlib.error.DisplayConnectionError: Can't connect to display ":1": b'No protocol specified\n'

Django raising AppRegistryNotReady after update from to 1.9

I have read many similar posts with the same situation and tried a few things suggested if they were at all related. I just updated to Django 1.9 and I received this traceback:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/django/www/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/opt/django/www/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/opt/django/www/local/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/opt/django/www/local/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/opt/django/www/local/lib/python2.7/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/opt/django/www/src/site_aggrigator/__init__.py", line 2, in <module>
import management
File "/opt/django/www/src/site_aggrigator/management/__init__.py", line 4, in <module>
from django.contrib.auth.models import Permission
File "/opt/django/www/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/opt/django/www/local/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/opt/django/www/local/lib/python2.7/site-packages/django/db/models/base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "/opt/django/www/local/lib/python2.7/site-packages/django/apps/registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "/opt/django/www/local/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
All my apps are installed on my virtual env for sure because the app was running fine before I made the update. I also received this right before my update:
/opt/django/www/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/contrib/auth/models.py:41: RemovedInDjango19Warning: Model class django.contrib.auth.models.Permission doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Permission(models.Model):
And one post provided a solution of :
INSTALLED_APPS = (
"django.contrib.auth.models.Permission",
Which I also did as they said would be a viable solution. Anyone else had this issue?
Try to add this (after the declaration of SECRET_KEY):
import django
django.setup()

Django + Djangae + Nose / Fail wsgi

I'm currently trying to setting up django-nose in my project.
I also used Djangae (https://djangae.readthedocs.org/en/latest/) for app engine compatibility.
I add 'django_nose' in my INSTALLED_APPS
I set TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
Launching "python manage.py test" is not raising any exceptions.
But when I want to launch the server with "python manage.py runserver", the server is running but when I try to call "localhost:8000" I get :
ERROR 2016-03-23 15:59:49,299 wsgi.py:263]
Traceback (most recent call last):
File "/Users/briva/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/briva/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Users/briva/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject
__import__(cumulative_path)
File "/Users/briva/Desktop/dangoptest/dangoptest/wsgi.py", line 18, in <module>
application = DjangaeApplication(get_wsgi_application())
File "/Users/briva/Desktop/dangoptest/lib/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup()
File "/Users/briva/Desktop/dangoptest/lib/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/briva/Desktop/dangoptest/lib/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/briva/Desktop/dangoptest/lib/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "lib/django_nose/__init__.py", line 5, in <module>
from django_nose.runner import BasicNoseRunner, NoseTestSuiteRunner
File "lib/django_nose/runner.py", line 61, in <module>
from django.test.simple import DjangoTestSuiteRunner as DiscoverRunner
ImportError: No module named simple
Thanks for answers.

Error with google appengine using pyramid

Using pyramid_appengine my project works fine but, when i deploy to GAE i have this error:
Traceback (most recent call last):
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 187, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 225, in _LoadHandler
handler = __import__(path[0])
File "/base/data/home/apps/s~muncompy/v3.359898035587494190/muncompy/__init__.py", line 36, in <module>
application = make_app()
File "/base/data/home/apps/s~muncompy/v3.359898035587494190/muncompy/__init__.py", line 32, in make_app
config.scan()
File "/base/data/home/apps/s~muncompy/v3.359898035587494190/pyramid/config/__init__.py", line 912, in scan
ignore=ignore)
File "/base/data/home/apps/s~muncompy/v3.359898035587494190/venusian/__init__.py", line 189, in scan
__import__(modname)
File "/base/data/home/apps/s~muncompy/v3.359898035587494190/muncompy/conftest.py", line 6, in <module>
from google.appengine.tools import dev_appserver_index
ImportError: No module named tools
Any ideas for why module tools from google.appengine is missing?

Sphinx Autodoc not importing properly

As the title says I am using Sphinx to generate documentation for a python library and using the auto doc functions.
The problem I am having is that the autodoc importer does not properly import the libraries.
Traceback (most recent call last):rs/user
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/decorators.py", line 4, in <module>
import response
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
from lib.helpers import gtJSONEncoder
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 3, in <module>
from gt import Model, EMAIL_FROM, EMAIL_HOST
File "/Users/prggmr/Work/chevy/gt/software/gt/gt.py", line 114, in <module>
from modules.user import views
File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/views.py", line 5, in <module>
from lib import response
ImportError: cannot import name response
Traceback (most recent call last):json
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 2, in <module>
import response
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
from lib.helpers import gtJSONEncoder
ImportError: cannot import name gtJSONEncoder
Traceback (most recent call last):messages
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
ImportError: No module named helper
Traceback (most recent call last):request
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 2, in <module>
import response
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
from lib.helpers import gtJSONEncoder
ImportError: cannot import name gtJSONEncoder
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 2, in <module>
import response
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
from lib.helpers import gtJSONEncoder
ImportError: cannot import name gtJSONEncoder
Traceback (most recent call last):ser
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/models.py", line 6, in <module>
import gt
File "/Users/prggmr/Work/chevy/gt/software/gt/gt.py", line 114, in <module>
from modules.user import views
File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/views.py", line 7, in <module>
from lib.decorators import valid_user
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/decorators.py", line 7, in <module>
from gt.modules.user.models import get_user_account, is_login_valid
ImportError: No module named modules.user.models
Traceback (most recent call last):ser
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/views.py", line 2, in <module>
from gt import app, TEMPLATES_PATH
File "/Users/prggmr/Work/chevy/gt/software/gt/gt.py", line 114, in <module>
from modules.user import views
ImportError: cannot import name views
I have tripled checked that the paths are correct and I am including them on the system path.
The thing that really gets me about this is that I can run the application just perfectly and all unit tests are passing with over 95% code coverage ... yet sphinx cannot import it.
That looks like an import loop. Try to organize your imports so that they don't depend on each other in a circle.
Alternatively, you can try to reorder them. Perhaps in helpers.py move line 3 to the bottom of the file, or something similar.

Categories