Django and python 2.7 from ports on Mac OS X - python

I have Django 1.4.1 and Python 2.7 installed from ports on Mac OS X 10.7. When I try to run manage.py runserver 8000, I'm getting an error:
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10bb840d0>>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 158, in get_app_errors
self._populate()
File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name, True)
File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/rankor777/PycharmProjects/PyCart/PyCartApp/models.py", line 40, in <module>
class Photo(models.Model):
File "/Users/rankor777/PycharmProjects/PyCart/PyCartApp/models.py", line 41, in Photo
title = models.Model(max_length=128)
File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 289, in __init__
if args_len > len(self._meta.fields):
AttributeError: 'Model' object has no attribute '_meta'
What's this, and how to fix it?

I don't know why you think this has something to do with MacPorts. The traceback shows the error, which is in line 41 of PyCartApp/models.py: you've put models.Model(max_length=128) where I presume you meant to put models.CharField(max_length=128).

Related

Channel tests with selenium in Django raise error message

I'm following this tutorial to experiment Channels with Django. I'm working on Windows 10 HOME, Django 2.1.4 and Python 3.7.1
The goal of this tutorial is to build a chat app.
After downloading chromeDriver and adding it in the PATH, I run this command in my prompt :
py manage.py test chat.tests
Which returns this error message :
EETraceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
EOFError: Ran out of input
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
EOFError: Ran out of input
======================================================================
ERROR: test_when_chat_message_posted_then_not_seen_by_anyone_in_different_room (chat.tests.ChatTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\test\testcases.py", line 202, in __call__
self._pre_setup()
File "C:\Users\kevin\Envs\myproject\lib\site-packages\channels\testing\live.py", line 52, in _pre_setup
self._server_process.start()
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
reduction.dump(process_obj, to_child)
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\reduction.py", line 61, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'DaphneProcess.__init__.<locals>.<lambda>'
======================================================================
ERROR: test_when_chat_message_posted_then_seen_by_everyone_in_same_room (chat.tests.ChatTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\test\testcases.py", line 202, in __call__
self._pre_setup()
File "C:\Users\kevin\Envs\myproject\lib\site-packages\channels\testing\live.py", line 52, in _pre_setup
self._server_process.start()
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
reduction.dump(process_obj, to_child)
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\reduction.py", line 61, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'DaphneProcess.__init__.<locals>.<lambda>'
----------------------------------------------------------------------
Ran 0 tests in 4.689s
FAILED (errors=2)
Destroying test database for alias 'default'...
The same question (https://stackoverflow.com/questions/50016048....) provide a solution, but it doesn't work for me.
When I modify the file reduction.py to replace import pickle by import dill as pickle, I'm getting this new message error :
DevTools listening on ws://127.0.0.1:25037/devtools/browser/b4c722e4-c7f2-49fb-939b-7372e9688eea
C:\Users\kevin\Envs\myproject\lib\site-packages\daphne\server.py:13: UserWarning: Something has already installed a non-asyncio Twisted reactor. Attempting to uninstall it; you can fix this warning by importing daphne.server early in your codebase or finding the package that imports Twisted and importing it later on.
UserWarning,
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "c:\users\kevin\appdata\local\programs\python\python37-32\Lib\multiprocessing\spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
File "C:\Users\kevin\Envs\myproject\lib\site-packages\dill\_dill.py", line 304, in load
obj = pik.load()
File "C:\Users\kevin\Envs\myproject\lib\site-packages\dill\_dill.py", line 465, in find_class
return StockUnpickler.find_class(self, module, name)
File "C:\Users\kevin\Envs\myproject\lib\site-packages\channels\auth.py", line 12, in <module>
from django.contrib.auth.models import AnonymousUser
File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\contrib\auth\models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\db\models\base.py", line 87, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\apps\registry.py", line 249, in get_containing_app_config
self.check_apps_ready()
File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\apps\registry.py", line 132, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Please, someone could bring me help ?

I can not run a server on Django

I have a problem: after the python manage.py runserver command I receive the following error which I can not solve:
Unhandled exception in thread started by <function wrapper at 0xb6712e64>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 107, in inner_run
autoreload.raise_last_exception()
File "/usr/lib/python2.7/dist-packages/django/utils/autoreload.py", line 252, in raise_last_exception
six.reraise(*_exception)
File "/usr/lib/python2.7/dist-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python2.7/dist-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/usr/lib/python2.7/dist-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/redactor/admin.py", line 3, in <module>
from redactor.widgets import JQueryEditor
ImportError: cannot import name JQueryEditor
How can I solve this problem? Many where we recommend that you sudo easy_install pip the team, but it did not help.
Are you sure that the name of the widget class is correct?
I was checking django-redactor and django-redactoreditor and they don't have a class named "JQueryEditor".

ImportError: cannot import name Connection while adding session?

I have a django project working fine . now i need to add login with session on that project I use mango .
As added in setting.py file
SESSION_ENGINE = 'mango.session'
then it started to give following error:
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 170, in __call__
self.load_middleware()
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 52, in load_middleware
mw_instance = mw_class()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/middleware.py", line 11, in __init__
engine = import_module(settings.SESSION_ENGINE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/shubham/Music/ekomerz/mango/__init__.py", line 2, in <module>
from pymongo import Connection
ImportError: cannot import name Connection
how I can solve this ?
and is there is any other method should i try for login with session ?

ImportError under admin.autodiscover() when trying to run single django-nose test

I'm trying to run single test using django-nose:
./manage.py test lead.tests:LeadStatTests.basic_stat_test
And following ImportError occurs:
======================================================================
ERROR: Failure: ImportError (cannot import name LeadSource)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/nose/loader.py", line 420, in loadTestsFromName
addr.filename, addr.module)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/kolen/items/someproject/lead/tests.py", line 16, in <module>
from lead.models import Lead, Action, LeadSource, LeadType, events_by_month, EventSummary
File "/Users/kolen/items/someproject/lead/models.py", line 38, in <module>
User = get_user_model()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 127, in get_user_model
user_model = get_model(app_label, model_name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/db/models/loading.py", line 271, in get_model
self._populate()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in _populate
self.load_app(app_name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/debug_toolbar/models.py", line 63, in <module>
patch_root_urlconf()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/debug_toolbar/models.py", line 51, in patch_root_urlconf
reverse('djdt:render_panel')
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 507, in reverse
app_list = resolver.app_dict[ns]
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 329, in app_dict
self._populate()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 267, in _populate
for pattern in reversed(self.url_patterns):
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 365, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 360, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/kolen/items/someproject/system/urls.py", line 8, in <module>
admin.autodiscover()
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 29, in autodiscover
import_module('%s.admin' % app)
File "/Users/kolen/.virtualenvs/someenv/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/kolen/items/someproject/lead/admin.py", line 5, in <module>
from lead.models import LeadSource, LeadType, Lead, ........, \
ImportError: cannot import name LeadSource
Running all tests with ./manage.py test works. This exception occurs only when trying to run single test or test class. However running all tests takes too much time so I want a way to run single test.
Application and django admin works too. There's no __init__.py in root directory of the project.
Suddenly discovered that problem is caused by django-debug-toolbar. Removing it from the project solved this issue.
There is possibly duplicate of this question with similar problem also caused by django-debug-toolbar.

Problem syncdb-ing new BeautifulSoup package in django

This was the traceback, please help.
Traceback (most recent call last):
File "C:\Documents and Settings\EC.32-SAMUEL\workspace\ec\ec\manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
utility.execute()
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 219, in execute
self.validate()
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python26\lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors
self._populate()
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 61, in _populate
self.load_app(app_name, True)
File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 83, in load_app
if not module_has_submodule(app_module, 'models'):
File "C:\Python26\lib\site-packages\django\utils\module_loading.py", line 17, in module_has_submodule
for entry in package.__path__: # No __path__, then not a package.
AttributeError: 'module' object has no attribute '
path'
BeautifulSoup is not a Django-app. Its a python package/module. You don't have to add to INSTALLED_APPS. It just need to be available in your PYTHONPATH to use it.
Your traceback doesn't give clue what is actually wrong with your Django project.
The only time you ever need to do a syncdb is when you have to do something to the db. BeautifulSoup does not need to use the db at any point and does not need to be an installed app

Categories