When I run a custom command in Django 1.8.3, I'm getting the following stack trace:
(env)MacBook-Air:backend user$ python manage.py questions
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/user/WeVote/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Users/user/WeVote/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/user/WeVote/env/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/user/WeVote/env/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/Users/user/WeVote/wevote/questions/management/commands/questions.py", line 14, in handle
OSError: [Errno 2] No such file or directory: '/Users/user/WeVote/backend/questions/question_files'
The error is valid, that filepath doesn't exist. I go to look at line 14 in questions.py, except that file doesn't exist. Boo.
As you can see, the file structure is different in referencing questions.py file. As some point, I'm sure that was the file structure. I also wrote this in Djano 1.7 and upgraded to 1.8. However, all the other custom commands (written both before and after the upgrade) are working just fine.
Just as a sanity check, I tried a
cd /Users/user/WeVote/wevote/questions/management/commands/
Nope. This is an issue because when I now edit my properly-located questions.py in the management/commands directory, the changes aren't reflected. It's like it's reading a cached version and location of this file.
Also tried deleting and rebuilding both virtualenv and database. No love on either. I'm sure it's something simple I'm overlooking, but I'm out of ideas.
Reference for anyone coming afterwards: The comments from yuvi and Paul Collingwood above succeeded in solving my issue. I ran
find . -name '*.pyc' -delete
and the next time I ran questions.py everything worked well. Thanks both for your comments.
Related
I am in the process of moving the django page to a new server. Due to complications in the apache server configuration, I used mod_wsgi-express integrated into virtualenv python. According to the instructions found on this page: https://pypi.org/project/mod-wsgi/#description , I added mod_wsgi.server to installed Django applications and run the command python manage.py runmodwsgi. Unfortunately, in response I get an error which pastes below. I would be very grateful for any help and explanation why this problem appeared.
Traceback (most recent call last):
File "SAGI-B/manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/g####/.venvs/sa###/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/g####/.venvs/sa###/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/g####/.venvs/sa###/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/g####/.venvs/sa###/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/g####/.venvs/sa###/local/lib/python2.7/site-packages/mod_wsgi/server/management/commands/runmodwsgi.py", line 71, in handle
fields = wsgi_application.split('.')
AttributeError: 'NoneType' object has no attribute 'split'
The Django version I use is 1.10.7 (I know, I should upgrade - I'm in the process). In the settings.py configuration file I didn't find the line with WSGI_APPLICATION = 'xyz.wsgi.application'. Could this be the cause of the error?
The absence of a line with WSGI_APPLICATION = ... in the settings.py file was the reason for the failure.
I'm trying to setup a Django project and am faced with the following error:
WARNINGS:
?: (rest_framework.W001) You have specified a default PAGE_SIZE pagination rest_framework setting,without specifying also a DEFAULT_PAGINATION_CLASS.
HINT: The default for DEFAULT_PAGINATION_CLASS is None. In previous versions this was PageNumberPagination. If you wish to define PAGE_SIZE globally whilst defining pagination_class on a per-view basis you may silence this check.
Traceback (most recent call last):
File "manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 82, in handle
executor.loader.check_consistent_history(connection)
File "/Users/george/.virtualenvs/mixapi/lib/python3.7/site-packages/django/db/migrations/loader.py", line 291, in check_consistent_history
connection.alias,
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration events.0001_initial is applied before its dependency commons.0001_initial on database 'default'.
make: *** [migrate] Error 1
I am running this from within a virtual environment, and have a docker-compose container for a postgres db running. Not sure how to start debugging this or why its happening. Any help would be appreciated
As per your snapshot:
you need to run command:- python manage.py migrate commons and then migrate for events model.
Follow these steps in your migrations folder inside the project:
Delete the pycache and the 0001_initial files.
Delete the db.sqlite3 from the root directory (be careful all your data will go away).
on the terminal run:
python manage.py makemigrations
python manage.py migrate
Note: don't forget to take a backup of your data.
For more detail, you can follow the link
Just got python, pip and virtualenv installed on my windows 7 box.
Ran into the following issues when I want to create a virtual enviroment:
virtualenv test gives me:
------------------------------------------------------------
-c run on 09/18/14 00:24:25
Ignoring indexes: https://pypi.python.org/simple/
Downloading/unpacking setuptools
Cleaning up...
Removing temporary dir C:\Users\Han\test\build...
Exception:
Traceback (most recent call last):
File "c:\python27\lib\site-packages\virtualenv_support\pip-1.5.6-py2.py3-none-any.whl\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "c:\python27\lib\site-packages\virtualenv_support\pip-1.5.6-py2.py3-none-any.whl\pip\commands\install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "c:\python27\lib\site-packages\virtualenv_support\pip-1.5.6-py2.py3-none-any.whl\pip\req.py", line 1177, in prepare_files
url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
File "c:\python27\lib\site-packages\virtualenv_support\pip-1.5.6-py2.py3-none-any.whl\pip\index.py", line 209, in find_requirement
file_locations, url_locations = self._sort_locations(locations)
File "c:\python27\lib\site-packages\virtualenv_support\pip-1.5.6-py2.py3-none-any.whl\pip\index.py", line 128, in _sort_locations
sort_path(os.path.join(path, item))
File "c:\python27\lib\site-packages\virtualenv_support\pip-1.5.6-py2.py3-none-any.whl\pip\index.py", line 109, in sort_path
if mimetypes.guess_type(url, strict=False)[0] == 'text/html':
File "c:\python27\Lib\mimetypes.py", line 287, in guess_type
init()
File "c:\python27\Lib\mimetypes.py", line 348, in init
db.read_windows_registry()
File "c:\python27\Lib\mimetypes.py", line 256, in read_windows_registry
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
WindowsError: [Error 2] The system cannot find the file specified
any ideas? Have tried using the registry checker as well as hard coding the mimetypes.py file: http://www.swarley.me.uk/blog/2014/04/23/python-pip-and-windows-registry-corruption/ but the same error still occurs.
You're getting a different specific error message from the read_windows_registry() function than the one I talked about in my blog post, so I don't think deleting/skipping corrupted registry keys containing null characters is going to work for you.
I just found issue #505 in the virtualenv project which seems to be talking about your specific problem. There are several recommendations in that thread - do any of those solve your problem? It looks like the problem was subsequently fixed by pull request #579 anyway, so perhaps you just need to update to a newer version of virtualenv?
I've uploaded from django 1.6 to django 1.7 and from python 3.2.3 to python 3.4.1.
Suddenly when I try to run the makemessages command to catch the translating messages I find this error:
django.core.exceptions.ImproperlyConfigured: Command Command defines both "requires_model_validation" and "requires_system_checks", which is illegal. Use only "requires_system_checks".
I've googled it and I don't find where or what I should edit. In fact I've never used this parameter so...
Any idea?
The traceback
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/pablo/Workspaces/milao/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/pablo/Workspaces/milao/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/pablo/Workspaces/milao/lib/python3.4/site-packages/django/core/management/__init__.py", line 238, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/pablo/Workspaces/milao/lib/python3.4/site-packages/django/core/management/__init__.py", line 42, in load_command_class
return module.Command()
File "/home/pablo/Workspaces/milao/lib/python3.4/site-packages/django/core/management/base.py", line 228, in __init__
'"requires_system_checks".' % self.__class__.__name__)
django.core.exceptions.ImproperlyConfigured: Command Command defines both "requires_model_validation" and "requires_system_checks", which is illegal. Use only "requires_system_checks".
Finally I've found the answer and it's not related with django core at all. I was not using any command. However one of my installed apps was using it. In this case it's django vinaigrette.
I'll upload the patch ASAP to port this app to django 1.7.
Regards.
Thanks to #Paul Pepper for pointing me in the right direction. For me it was Django devserver causing the issue and updating to the latest version fixed it for me:
pip install -e git://github.com/dcramer/django-devserver.git#HEAD#egg=django-devserver
HEAD was commit e6c882fc11fba013b85d37f04db8f11b531eda9a at the time of this writing.
One of the great features of Django is that you can open a python interpreter set-up for use with your project. This can be used to analyse objects in a database and allows any python commands to be executed on your project. I find it essential for Django development. It is invoked in the project directory using this command:
$ python manage.py shell
I have just started developing a new project and for some reason the shell does not work. I have had a look online for the error and not found anything. I would greatly appreciate any help on this error:
Traceback (most recent call last):
File "manage.py", line 11, in
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 362, in execute_manager
utility.execute()
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 222, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Library/Python/2.6/site-packages/django/core/management/commands/shell.py", line 29, in handle_noargs
shell = IPython.Shell.IPShell(argv=[])
AttributeError: 'module' object has no attribute 'Shell'
Thanks in advance for your help!
It seems like IPython is installed wrongly somehow. Try starting the shell with:
./manage.py shell --plain
to start the standard Python shell, rather than IPython. If that works, then trying removing IPython completely and reinstalling it.
IPython 0.11 has a different API, for which a fix exists in the last Django versions.
For older Django versions, you can use IPython 0.10, which does work:
pip install ipython==0.10