PyCharm manage.py runserver error - django

Sorry to ask a noob question but I have no idea why this is happening.
I've just reinstalled Django 1.3, and am trying PyCharm for the first time. When I run python manage.py runserver from Terminal everything goes without a hitch, however if I try to runserver from within PyCharm I get the following:
Importing Django settings module settings
Traceback (most recent call last):
Validating models...
0 errors found
Django version 1.3, using settings 'glist.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
File "/Applications/PyCharm 1.2.1.app/helpers/pycharm/django_manage.py", line 19, in <module>
run_module(manage_file, None, '__main__')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 180, in run_module
fname, loader, pkg_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/Users/goon/code/glist/manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 67, in handle
self.run(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 76, in run
autoreload.main(self.inner_run, args, options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 131, in main
reloader(main_func, args, kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 104, in python_reloader
reloader_thread()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 83, in reloader_thread
ensure_echo_on()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 77, in ensure_echo_on
attr_list = termios.tcgetattr(fd)
termios.error: (25, 'Inappropriate ioctl for device')
Process finished with exit code 1
Please note that this is all happening before I request any page from within the browser. And, as I said, I have no trouble running from Terminal. Any help would be greatly appreciated.

What version fo pycharm are you using ? Actually it`s a error in django 1.3. It will occur if you try to run django from any ide in reload mode. It can be fixed by patching django. Although PyCharm should automatically switch to no reload mode.
Read this : http://blogs.jetbrains.com/pycharm/2011/03/pycharm-1-2-1-release-candidate-py-test-2-0-buildout-1-5/

Apply the patch. Its Django 1.3.1 error. This worked for me on pYCharm 3.4.1
https://github.com/django/django/commit/3e7ce3c750

Related

SQLite objects created in a thread can only be used in that same thread with Django 2.2.2 and ipdb

I updated my Django project to version 2.2.2 and now when I call to ipdb for debugging, the server tell me that error. If I go back to Django 2.2.1, the error disappears.
System check identified no issues (0 silenced).
June 06, 2019 - 08:19:36
Django version 2.2.2, using settings 'laserapp.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
> /home/lynde/public_html/laserapp/gestion/views.py(192)get_context_data()
191 import ipdb; ipdb.set_trace()
--> 192 context = super(ResumeOrderCodeView, self).get_context_data(**kwargs)
193 try:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 60, in execute
super().execute(*args, **options)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 95, in handle
self.run(**options)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 585, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 570, in start_django
reloader.run(django_main_thread)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 288, in run
self.run_loop()
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 294, in run_loop
next(ticker)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 334, in tick
for filepath, mtime in self.snapshot_files():
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 350, in snapshot_files
for file in self.watched_files():
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 249, in watched_files
yield from iter_all_python_module_files()
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 103, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 120, in iter_modules_and_files
sys_file_paths.append(module.__file__)
AttributeError: module '__main__' has no attribute '__file__'
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev#python.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/IPython/core/history.py", line 780, in writeout_cache
self._writeout_input_cache(conn)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/IPython/core/history.py", line 764, in _writeout_input_cache
(self.session_number,)+line)
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 140030717908736 and this is thread id 140031011022656.
Can somebody know what's the problem there? I'm using django runserver in local machine, with celery and postgresql database.
Thanks!! :)
Try using the --reload flag to run runserver.
./manage.py runserver --noreload
It stops the server reloading on code changes but I think avoids the issue you're having.

Error in runserver with Django on windows 10

I am using python 3.5 and windows 10, but had the same issue using windows 8, and that is the traceback i get while trying to runserver:
Traceback (most recent call last):
File "C:\Users\noabendor87\documents\otree\manage.py", line 10, in
execute_from_command_line(sys.argv, script_file=file)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\otree\management\cli.py", line
177, in execute_from_command_line
utility.execute()
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management__init__
.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\base.py"
, line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\commands
\runserver.py", line 49, in execute
super(Command, self).execute(*args, **options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\base.py"
, line 445, in execute
output = self.handle(*args, **options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\commands
\runserver.py", line 88, in handle
self.run(**options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\core\management\commands
\runserver.py", line 97, in run
autoreload.main(self.inner_run, None, options)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\utils\autoreload.py", li
ne 336, in main
reloader(wrapped_main_func, args, kwargs)
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\utils\autoreload.py", li
ne 307, in python_reloader
exit_code = restart_with_reloader()
File "c:\users\noabendor87\appdata\local\programs\python\python35-32\lib\site-packages\django\utils\autoreload.py", li
ne 293, in restart_with_reloader
exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character
I have already tried following the instructions in the following link:
http://stackoverflow.com/questions/25714826/error-in-manage-py-runserver-with-django-on-windows-8-1
but it did not help.
This is how the lines of code look like:
enter image description here
(Since Im a new user I cannot paste the image to the original post)
Anyone have encountered something similar and have a solution?
I used to have similar problems because of the difficulties with the virtual environment in windows 10. Try running the powershell as an administrator and do "Set-ExecutionPolicy RemoteSigned" or "Set-ExecutionPolicy Unrestricted" if remotesigned does not work. Do this before activating the virtualenv.
first I will like you check the django version you are working with my "type python -m django --version" or "pip freeze". check weather its compatible with the python version on your pc. if it's not install compatible python version. then check weather "init.py" is within your project directory, if not add it to your project directory. then run "Set-ExecutionPolicy -Scope CurrentUser Unrestricted" on your terminal. then run activate your virtualenv, then run "python manage.py runserver"

Django Intro Tutorial - Invoke Python Shell

I am new to django and am starting to go through the documenation and the poll tutorial. Install etc has been no problem and I have gotten as far as creating and activating the simple model however I am now trying to invoke the Python shell using
python manage.py shell
but I keep getting the below error each time.
C:\Users\Owner\Desktop\Programming\Djang\mysite>python manage.py shell
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\python27\lib\site-packages\django\core\management\__init__.py", line
399, in execute_from_command_line
utility.execute()
File "C:\python27\lib\site-packages\django\core\management\__init__.py", line
392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\python27\lib\site-packages\django\core\management\base.py", line 242,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\python27\lib\site-packages\django\core\management\base.py", line 285,
in execute
output = self.handle(*args, **options)
File "C:\python27\lib\site-packages\django\core\management\base.py", line 415,
in handle
return self.handle_noargs(**options)
File "C:\python27\lib\site-packages\django\core\management\commands\shell.py",
line 81, in handle_noargs
self.run_shell(shell=interface)
File "C:\python27\lib\site-packages\django\core\management\commands\shell.py",
line 61, in run_shell
return getattr(self, shell)()
File "C:\python27\lib\site-packages\django\core\management\commands\shell.py",
line 44, in ipython
ip()
File "C:\python27\lib\site-packages\django\core\management\commands\shell.py",
line 37, in _ipython
from IPython import start_ipython
File "C:\python27\lib\site-packages\IPython\__init__.py", line 43, in <module>
from .config.loader import Config
File "C:\python27\lib\site-packages\IPython\config\__init__.py", line 16, in <
module>
from .application import *
File "C:\python27\lib\site-packages\IPython\config\application.py", line 29, i
n <module>
from IPython.external.decorator import decorator
File "C:\python27\lib\site-packages\IPython\external\decorator\__init__.py", l
ine 4, in <module>
from ._decorator import *
File "C:\python27\lib\site-packages\IPython\external\decorator\_decorator.py",
line 165
print('Error in generated code:', file=sys.stderr)
^
SyntaxError: invalid syntax
Thanks in advance for any help on this as although I have some experience in Python I'm finding it very hard to follow the Traceback above.
You are using a Python 3 library (and not backward compatible) with the Python 2.7 version. You need either to reinstall ipython for Python 2 (in C:\python27) or upgrade to Python 3 (and install ipython in C:\python3)
Django is officially compatible with Python 3 since the 1.6 version.

"'django_mongodb_engine' isn't an available database backend" when pushing to Heroku

I have a Django app that successfully ran on Heroku and uses mongodb engine. All of a sudden, I can not push it anymore. It does not seem to recognize the django_mongodb_engine module anymore. I even reverted all changes to the version that last ran, but it's still the same. I suspect a version conflict or so, but can not figure out how to fix it.
This is the error I'm getting:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 429, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/shell.py", line 46, in handle_noargs
from django.db.models.loading import get_models
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/__init__.py", line 78, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 51, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named utils
And these are the important parts from the requirements.txt:
hg+https://bitbucket.org/wkornewald/django-nonrel
git+https://github.com/django-nonrel/mongodb-engine
hg+https://bitbucket.org/wkornewald/djangotoolbox
pymongo==2.2.1
pytz==2012d
I'm especially confused because I reverted all changes. Exactly this code with the same configuration ran perfectly (and still does on my production server), just pushing does not work.
Thanks
Simon
Of course, just when I asked on SO I figure out the answer :-)
I don't know why exactly, but defining the exact revision that i want to check out solved the problem.
So the requirements.txt looks now like this:
-e hg+http://bitbucket.org/wkornewald/django-nonrel#be48c152abc6b15e45155e2bbcfd69c665ccb536#egg=Django-dev
-e git+https://github.com/django-nonrel/mongodb-engine#52257b5d90dcfaa564e708264a9cfe591d301fe6#egg=django_mongodb_engine-dev
-e hg+https://bitbucket.org/wkornewald/djangotoolbox#a8cdf61ba9c0cdc7cbbbd37d693e9a222d9a8e5f#egg=djangotoolbox-dev
pymongo==2.2.1
pytz==2012d

django/postgres: Transaction managed block ended with pending COMMIT/ROLLBACK

I want to run manage.py sqldiff myapp (command from django extension), but I get the following error:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django_extensions/management/commands/sqldiff.py", line 596, in handle
sqldiff_instance.find_differences()
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 222, in inner
self.__exit__(None, None, None)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 207, in __exit__
self.exiting(exc_value, self.using)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 302, in exiting
leave_transaction_management(using=using)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 56, in leave_transaction_management
connection.leave_transaction_management()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 115, in leave_transaction_management
raise TransactionManagementError("Transaction managed block ended with "
django.db.transaction.TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK
manage.py runserver, shell, shell_plus all work fine, but the sqldiff command chokes. I have tried:
restart postgres server
manually connect to postgres from shell via psycopg2, ran
connection.rollback(), and connection.commit()
but the error persists.
Any ideas on what can be done are welcome!
Cheers,
Hoff
I updated an issue with sqldiff causing similar problems. Your best bet is probably to obtain django-extensions from the github repository and do a bit of investigation. Edit sqldiff.py and comment out the transaction code decorating the find_differences method:
# #transaction.commit_manually
def find_differences(self):
...
# transaction.rollback() # reset transaction
...
# transaction.commit()
Now your real problem should be revealed, no longer masked by the transaction exception.