Django can't find package even though in virtualenv - django

I'm coming into an inherited Django project, so I can't say how it was originally set up. However, pip freeze tells me that django-cms is installed in the virtualenv:
(demo)$ pip freeze
...
django-cms==3.3.0
...
So why when I do anything with, manage.py, do I get an error saying it's not available?
(demo)$
./manage.py shell
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/iscape/sites/demo/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/iscape/sites/demo/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 328, in execute
django.setup()
File "/iscape/sites/demo/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/iscape/sites/demo/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/iscape/sites/demo/local/lib/python2.7/site-packages/django/apps/config.py", line 112, in create
mod = import_module(mod_path)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named cms
I can also confirm that VIRTUAL_ENV has the correct value in the "activate" script. It's like pip knows what's installed, but Django doesn't.
This is Django1.8, btw, though I don't know how much of a factor that is.
Any ideas? I'm getting nothing out of the stack trace and don't know where else to look.

Related

Python Django manage.py shell Attribute error module 'ast' has no attribute 'AnnAssign'

So I'm working on this test app in Django and i wanted to add some data to my sql tables through the python shell. I ran the following command from the CMD
λ python manage.py shell
Which gave me the following output:
Traceback (most recent call last): File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv) File "C:\Python\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute() File "C:\Python\lib\site-packages\django\core\management\__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options) File "C:\Python\lib\site-packages\django\core\management\base.py", line 335, in execute
output = self.handle(*args, **options) File "C:\Python\lib\site-packages\django\core\management\commands\shell.py", line 99, in handle
return getattr(self, shell)(options) File "C:\Python\lib\site-packages\django\core\management\commands\shell.py", line 35, in ipython
from IPython import start_ipython File "C:\Python\lib\site-packages\IPython\__init__.py", line 55, in <module>
from .terminal.embed import embed File "C:\Python\lib\site-packages\IPython\terminal\embed.py", line 15, in <module>
from IPython.core.interactiveshell import DummyMod, InteractiveShell File "C:\Python\lib\site-packages\IPython\core\interactiveshell.py", line 109, in <module>
_assign_nodes = (ast.AugAssign, ast.AnnAssign, ast.Assign) AttributeError: module 'ast' has no attribute 'AnnAssign'
I'm using Python 3 and Django 2.0.3.
Some things I tried on my own:
I checked that ipython was up to date using pip, my database runs on SQL community server runs and works fine and the Django server itself also runs without issues.
EDIT: I did some more digging AST is part of the standard python library. However i dont find any issues with my python install, any ideas?
EDIT2: Tried reinstalling Ipython, same traceback error.
Alright, so i did a complete reinstall of Django and Mysqlclient through PIP which solved the problem. I now have acess to the django shell.

Installation of django-scheduler: $python manage.py runserver returns KeyError: u'__module__'

I installed django-scheduler with pip (https://github.com/llazzaro/django-scheduler) and I edited settings.py as in the tutorial. When I run $python manage.py runserver I got this:
python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/django_scheduler-0.7.5-py2.7.egg/schedule/models/__init__.py", line 1, in <module>
from schedule.models.calendars import *
File "/usr/local/lib/python2.7/dist-packages/django_scheduler-0.7.5-py2.7.egg/schedule/models/calendars.py", line 110, in <module>
class Calendar(with_metaclass(ModelBase, *get_model_bases())):
File "/usr/lib/python2.7/dist-packages/six.py", line 617, in with_metaclass
return meta("NewBase", bases, {})
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 71, in __new__
module = attrs.pop('__module__')
KeyError: u'__module__'
I tried to reinstall Python (2.7), Django (1.7) and the app. I need a calendar app to my project and this seems the most complete.
Thanks.
I had this same issue. It turned out to be a problem with the version of python's six I had installed. I was using six version 1.6.1, and when I upgraded to version 1.9.0 it took care of this error. Run:
pip-2.7 install --upgrade six
run this script using djago-getversions.py
import pip
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
for i in installed_packages])
print(installed_packages_list)
----------------------------------------------------
check your django installed versions
after that compare or reinstall like these versions:
please check your this version:
[
'adium-theme-ubuntu==0.3.4',
'apt-xapian-index==0.45',
'chardet==2.0.1',
'colorama==0.2.5',
'command-not-found==0.3',
'debtagshw==0.1',
'defer==1.0.6',
'dirspec==13.10',
'django-classy-tags==0.6.1',
'django-cms==3.0.12',
'django-mptt==0.6.1',
'django-sekizai==0.8.1',
'django-treebeard==3.0',
'django==1.6.1',
'djangocms-admin-style==0.2.5',
'djangocms-link==1.5',
'djangocms-snippet==1.4',
'djangocms-text-ckeditor==2.4.3',
'dnspython==1.11.1',
'duplicity==0.6.23',
'html5lib==0.999',
'httplib2==0.8',
'iniparse==0.4',
'lockfile==0.8',
'lxml==3.3.3',
'mercurial==2.8.2',
'mysql-connector-python==1.1.6',
'mysql-python==1.2.3',
'mysql-utilities==1.3.5',
'oauthlib==0.6.1',
'oneconf==0.3.7',
'pam==0.4.2',
'paramiko==1.10.1',
'pexpect==3.1',
'pillow==2.3.0',
'pip==7.1.0',
'piston-mini-client==0.7.5',
'pycrypto==2.6.1',
'pycups==1.9.66',
'pycurl==7.19.3',
'pygments==1.6',
'pygobject==3.12.0',
'pyopenssl==0.13',
'pyserial==2.6',
'pysmbc==1.0.14.1',
'pysqlite==2.6.3',
'python-apt==0.9.3.5ubuntu1',
'python-debian==0.1.21-nmu2ubuntu2',
'pyxdg==0.25',
'reportlab==3.0',
'requests==2.2.1',
'sessioninstaller==0.0.0',
'setuptools==3.3',
'six==1.5.2',
'software-center-aptd-plugins==0.0.0',
'south==1.0.2',
'system-service==0.1.6',
'tortoisehg==2.10',
'twisted-core==13.2.0',
'twisted-web==13.2.0',
'unity-lens-photos==1.0',
'urllib3==1.7.1',
'version==0.1.1',
'virtualenv==13.0.1',
'wheel==0.24.0',
'wxpython-common==2.8.12.1',
'wxpython==2.8.12.1',
'xdiagnose==3.6.3build2',
'youtube-dl==2015.7.7',
'zope.interface==4.0.5'
]

failed to install django-chronograph in django 1.7

I tried to install django-chronograph to django-1.7 for assigning scheduled task in my django web-app.
I followed the instruction as shown here but it gives me the following error when running python manage.py makemigrations or python manage.py syncdb:
user#(none):~/mysite$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", line 23, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/usr/local/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/chronograph/admin.py", line 2, in <module>
from django.conf.urls.defaults import patterns, url
ImportError: No module named defaults
Is it django-chronograph not supported by django-1.7?
I've never heard of this package, but if you search for that error you will find that that import path hasn't worked since Django 1.6.
It could be that it's just the PyPI version that's old, and that the master branch works fine. However, the last commit to this package was in March 2013, and there's an open issue on the project's bitbucket page indicating that it fails to work on 1.6, so I doubt it.
In sum, it appears that this package supports neither Django 1.6 nor 1.7.
They already committed a fix, so to get rid of this error, don't go through:
pip install django-chronograph
I've just installed on Django 1.8 without issues (so far..) using:
pip install -e hg+https://bitbucket.org/wnielson/django-chronograph#f561106f6aaab62f2817e08e51c799320fd916d9#egg=django-chronograph

DJANGO_PATH errors and settings issues

I recently upgraded my Ubuntu to 14.04, and consulted this question to solve my erros, ImportError: No module named _io in ubuntu 14.04. That was solved perfectly.
I also checked out this question as it's similar to mine, Consistently getting ImportError: Could not import settings 'myapp.settings' error, but could not use the same solution.
I do not use manage.py in my project and I have done numerous exports of the PYTHON_PATH to no end of my issues. Here is my traceback;
Traceback (most recent call last):
File "/home/thabang/.virtualenvs/lottostar/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'lottostar.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named lottostar.settings
I found the problem:
The was an issue with the egg files during the virtualenv reinstall. Though the programs were there, they couldn't be found. I just performed another install of the requirements to refresh the egg info.

Cannot successfully merge devserver patches together for deployment to Heroku

I have tried to push my new code to Heroku but I experiencing an ImportError which says:
Starting process with command `python manage.py runserver --insecure 0.0.0.0:13192 --noreload`
Traceback (most recent call last):
execute_from_command_line(sys.argv
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "manage.py", line 10, in <module>
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException, \
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
File "/app/.heroku/python/lib/python2.7/site-packages/devserver/management/commands/runserver.py", line 3, in <module>
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
utility.execute()
ImportError: cannot import name AdminMediaHandler
I have found in the documentation that django.core.servers.basehttp.AdminMediaHandler from 1.4 would be replaced with django.contrib.staticfiles.handlers.StaticFilesHandler. My question is where do I place the StaticFilesHandler in place of the AdminMediaHandler?
Update:
I have now tried to merge the two patches together by placing git+git://github.com/dcramer/django-devserver#egg=django-devserver in my requirements. But I am still receiving the same error when trying to deploy
No need to try and merge the patches of django-devserver together. Django-devserver 0.5.0 is compatible with Django 1.5, once I placed 'django-deveserver 0.5.0' in my requirements.txt my app could deploy without crashing.