django-admin.py makemessages fails - python

I had created language-files with django-admin.py makemessages -a
A little bit development later all attempts to create *.po files are failing with:
django-admin.py makemessages -v 3 -a
examining files with the extensions: .html and .txt
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/makemessages.py", line 283, in handle_noargs
potfiles = self.build_potfiles()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/makemessages.py", line 299, in build_potfiles
file_list = self.find_files(".")
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/makemessages.py", line 358, in find_files
ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT)]
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/makemessages.py", line 358, in <listcomp>
ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT)]
File "/usr/lib/python3.4/posixpath.py", line 335, in normpath
initial_slashes = path.startswith(sep)
AttributeError: 'NoneType' object has no attribute 'startswith'
I tried it with several file extensions and -ignore patterns.
Do you have any hints?

I have had the same problem since django 1.7. I use manage.py to make messages instead of django-admin.py excluding the environment folder:
python manage.py makemessages --locale=en --ignore=venv/*

This is due to a bug introduced in Django 1.7.1. You can fix this by updating your Django to the latest version using:
pip install -U django
P.S. Related StackOverflow questions and answers on this matter can be found here and here.

Related

Problem with Django startproject: TypeError: '_sre.SRE_Match' object is not subscriptable

Trying to run
django-admin startproject mysite
and there occurs such problem
Traceback (most recent call last):
File "/Users/username/Desktop/test/venv/bin/django-admin", line 10, in <module>
sys.exit(execute_from_command_line())
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/commands/startproject.py", line 20, in handle
super().handle('project', project_name, target, **options)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/templates.py", line 158, in handle
template = Engine().from_string(content)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/engine.py", line 136, in from_string
return Template(template_code, engine=self)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 155, in __init__
self.nodelist = self.compile_nodelist()
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 193, in compile_nodelist
return parser.parse()
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 447, in parse
filter_expression = self.compile_filter(token.contents)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 563, in compile_filter
return FilterExpression(token, self)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 638, in __init__
var, constant = match['var'], match['constant']
TypeError: '_sre.SRE_Match' object is not subscriptable
I guess there is a problem with versions, but don't know exactly what is it.
On version 1.8.6 everything is ok, but when I try to use
from django.urls import path, include
I see that there is no django.urls in this version.
So I'd like to use the latest version and will be grateful, if you can help me!
Python version:
Python 3.6.0a4
It seems that you use an unofficial version of django.
Hello, try this first, dont remove anything leave pip do it for you:
pip install -U django
Now After that rerun startproject command line

how can i solve AttributeError 'NoneType' object has no attribute 'write'

python manage.py migrate
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\commands\migrate.py", line 162, in handle
self.stdout.write(self.style.MIGRATE_HEADING("Operations to perform:"))
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 145, in write
self._out.write(style_func(msg))
AttributeError: 'NoneType' object has no attribute 'write'
please can anyone help out with this error.
it popup anytime i try to use manage.py. anyone please
You can go to Migrations folder and delete all the files other then init.py
and then run the
python manage.py makemigrations
python manage.py migrate
I have exactly the same problem (Python 3.7 and django 1.10). Turns out the problem was that it was running on the bash (from git bash). I guess it errors trying to get stdout.
It works using Windows's command prompt.

Django Error when running server locally - AttributeError: 'list' object has no attribute 'read'

Getting below error when trying to run server in VS Code for Django.
Command: python manage.py runserver
Error:
C:\DjangoServerTest\DjangoServerTest>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 601, in run_with_reloader
exit_code = restart_with_reloader()
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 230, in restart_with_reloader
p = subprocess.run(args, env=new_environ, close_fds=False)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\run\__init__.py", line 145, in __new__
process = cls.create_process(command, stdin, cwd=cwd, env=env, shell=shell)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\run\__init__.py", line 121, in create_process
shlex.split(command),
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\shlex.py", line 305, in split
return list(lex)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\shlex.py", line 295, in __next__
token = self.get_token()
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\shlex.py", line 105, in get_token
raw = self.read_token()
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\shlex.py", line 136, in read_token
nextchar = self.instream.read(1)
AttributeError: 'list' object has no attribute 'read'
Can you please help here?
I too had the same issue.
What i did is that i went to control panel -> search -> advanced system settings ->environment variables -> Path
then cleared all paths
Uninstalled python, and deleted all the python related files in the "C:\Users{user_name}\AppData\Local\Programs" directory
And then downloaded the latest one and installed again.
Then added the scripts folder and the python folder directory into the PATH.
Then installed pip and then django.
Now its woking perfectly.
In short remove all the versions of python completely and then install it again. Also clear all the unwanted "paths" in the environment variables.....
I spent around 2 hours on the same issue that I was facing.
I could not understand why the error is occurring but I found the solution by simply uninstalling python and re-installing it.
In my case I had more than 1 number of python versions installed so I deleted all the 'site-packages' folder too and installed the latest version of python again and it worked.
Let me know if this works for you too.
I had the same Error AttributeError: 'list' object has no attribute 'read' in Django, I uninstalled a package called "subprocess.run" with "pip uninstall [package-name]" and that's all. You can run your project

Django error: too many open files

I'm using Anaconda python and I'm trying to run a simple Django server using the official documentation. When I run python manage.py runserver I get this error
Nuseirs-MacBook-Pro:anothertry nyassin$ python manage.py runserver
Validating models...
0 errors found
November 06, 2013 - 18:27:10
Django version 1.7.dev20131105182658, using settings 'anothertry.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/nyassin/django-trunk/django/core/management/__init__.py", line 416, in execute_from_command_line
utility.execute()
File "/Users/nyassin/django-trunk/django/core/management/__init__.py", line 408, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/nyassin/django-trunk/django/core/management/base.py", line 244, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/nyassin/django-trunk/django/core/management/base.py", line 291, in execute
output = self.handle(*args, **options)
File "/Users/nyassin/django-trunk/django/core/management/commands/runserver.py", line 76, in handle
self.run(*args, **options)
File "/Users/nyassin/django-trunk/django/core/management/commands/runserver.py", line 85, in run
autoreload.main(self.inner_run, args, options)
File "/Users/nyassin/django-trunk/django/utils/autoreload.py", line 359, in main
reloader(wrapped_main_func, args, kwargs)
File "/Users/nyassin/django-trunk/django/utils/autoreload.py", line 325, in python_reloader
reloader_thread()
File "/Users/nyassin/django-trunk/django/utils/autoreload.py", line 304, in reloader_thread
if fn():
File "/Users/nyassin/django-trunk/django/utils/autoreload.py", line 217, in kqueue_code_changed
new_descriptors = set(open(filename) for filename in new_filenames)
File "/Users/nyassin/django-trunk/django/utils/autoreload.py", line 217, in <genexpr>
new_descriptors = set(open(filename) for filename in new_filenames)
IOError: [Errno 24] Too many open files: '//anaconda/lib/python2.7/lib-dynload/resource.so'
Any ideas what might be causing this?
It's an operating system error. The maximum number of open files is limited. Try to find where you open files and forget to close them.
Open less file descriptors at once.
set(open(filename) for filename in new_filenames)
is where the error occurs.

python manage.py runserver fails

I am trying to learn django by following along with this tutorial. I am using django version 1.1.1
I run
django-admin.py startproject mysite
and it creates the files it should. Then I try to start the server by running
python manage.py runserver
but here is where I get the following error.
Traceback (most recent call last):
File "manage.py", line 11, in <module>
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 213, in execute
translation.activate('en-us')
File "/Library/Python/2.6/site-packages/django/utils/translation/__init__.py", line 73, in activate
return real_activate(language)
File "/Library/Python/2.6/site-packages/django/utils/translation/__init__.py", line 43, in delayed_loader
return g['real_%s' % caller](*args, **kwargs)
File "/Library/Python/2.6/site-packages/django/utils/translation/trans_real.py", line 205, in activate
_active[currentThread()] = translation(language)
File "/Library/Python/2.6/site-packages/django/utils/translation/trans_real.py", line 194, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/Library/Python/2.6/site-packages/django/utils/translation/trans_real.py", line 172, in _fetch
for localepath in settings.LOCALE_PATHS:
File "/Library/Python/2.6/site-packages/django/utils/functional.py", line 273, in __getattr__
return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'LOCALE_PATHS'
Now, I can add a LOCALE_PATH atribute and set to an empty tuple to my settings.py file but then it just complains about another setting and so on. What am I missing here?
Something is broken in your django installation. maybe you have a (very) old version somewhere in the path?
LOCALE_PATHS was given a default value in the global settings file a long time ago.
Can't really explain that. Try removing the project directory and starting again.
Are you definitely running the manage.py from within the directory with the settings file?

Categories

Resources