How to run createsuperuser from PyDev Django shell - python

I can't figure out how to do python manage.py createsuperuser in my PyDev Django shell.
I was hoping something below would work, but nothing did. I've never really used these shells before, and hope there's a way to create this superuser with a shell.
import manage
python manage.py createsuperuser
File "<ipython-input-15-fcfe38f02d6e>", line 1
python manage.py createsuperuser
^
SyntaxError: invalid syntax
I tried doing it with the Windows cmd, which led to this error:
C:\Users\Rasmus\workspace\Crowd\src>python manage.py createsuperuser
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py", line 25, in <module>
import MySQLdb as Database
ImportError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "C:\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 327, in execute
django.setup()
File "C:\Anaconda3\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Anaconda3\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Anaconda3\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "C:\Users\Rasmus\workspace\Crowd\src\Cr\models.py", line 3, in <module>
class User(models.Model):
File "C:\Anaconda3\lib\site-packages\django\db\models\base.py", line 108, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Anaconda3\lib\site-packages\django\db\models\base.py", line 307, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Anaconda3\lib\site-packages\django\db\models\options.py", line 263, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Anaconda3\lib\site-packages\django\db\__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Anaconda3\lib\site-packages\django\db\utils.py", line 212, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Anaconda3\lib\site-packages\django\db\utils.py", line 116, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "C:\Anaconda3\lib\site-packages\django\db\backends\mysql\base.py", line 28, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
Which I find weird seeing as my Django is connected to my database and that I can store and retrieve objects from the database within PyDev.
Are there other ways to createsuperuser than using shell or cmd? Like doing it with a method?

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(["manage.py","createsuperuser"])

Based on the error information "loading MySQLdb module: No module named 'MySQLdb'", you need to install MySQL-python

Related

Can not run Django project

I´m having a problem running my old django project. Its giving an error after i run py manage.py.
I tryed to use the command py manage.py makemigrations
Traceback (most recent call last):File "C:\Users\ricardo martins\Downloads\LES-fosquito\LES-fosquito\manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\ricardo martins\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "C:\Users\ricardo martins\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 420, in execute
django.setup()
File "C:\Users\ricardo martins\AppData\Local\Programs\Python\Python310\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\ricardo martins\AppData\Local\Programs\Python\Python310\lib\site-packages\django\apps\registry.py", line 124, in populate
app_config.ready()
File "C:\Users\ricardo martins\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\admin\apps.py", line 27, in ready
self.module.autodiscover()
File "C:\Users\ricardo martins\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\admin\__init__.py", line 50, in autodiscover
autodiscover_modules("admin", register_to=site)
File "C:\Users\ricardo martins\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\module_loading.py", line 58, in autodiscover_modules
import_module("%s.%s" % (app_config.name, module_to_search))
File "C:\Users\ricardo martins\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\ricardo martins\Downloads\LES-fosquito\LES-fosquito\processes\admin.py", line 4, in <module>
from tinymce.widgets import TinyMCE
ModuleNotFoundError: No module named 'tinymce'
Are you using the TinyMCE library in your code? If you are trying to run it locally, try to see if you have the correct dependencies installed, and if it is not needed you can simply remove the import statemnt.

Why does command prompt throws" Syntax Error: Generator expression must be parenthesized " while creating a Django App named Authentication?

I am new to Django and was trying to make a Django project inside the virtualenv to learn but getting following error on python manage.py startapp Authentication:
python manage.py startapp Authentication
Traceback (most recent call last):
File "C:\Users\Prompt\Desktop\Django\manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "D:\anaconda\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
utility.execute()
File "D:\anaconda\lib\site-packages\django\core\management\__init__.py", line 337, in execute
django.setup()
File "D:\anaconda\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "D:\anaconda\lib\site-packages\django\apps\registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "D:\anaconda\lib\site-packages\django\apps\config.py", line 94, in create
module = import_module(entry)
File "D:\anaconda\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "D:\anaconda\lib\site-packages\django\contrib\admin\__init__.py", line 4, in <module>
from django.contrib.admin.filters import (
File "D:\anaconda\lib\site-packages\django\contrib\admin\filters.py", line 10, in <module>
from django.contrib.admin.options import IncorrectLookupParameters
File "D:\anaconda\lib\site-packages\django\contrib\admin\options.py", line 12, in <module>
from django.contrib.admin import helpers, widgets
File "D:\anaconda\lib\site-packages\django\contrib\admin\widgets.py", line 151
'%s=%s' % (k, v) for k, v in params.items(),
^
SyntaxError: Generator expression must be parenthesized

Django 'python manage.py runserver' has from config import* error

I have an error when i use django.
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/ghk/djangoprojects/myvenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/ghk/djangoprojects/myvenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 308, in execute
settings.INSTALLED_APPS
File "/Users/ghk/djangoprojects/myvenv/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Users/ghk/djangoprojects/myvenv/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/Users/ghk/djangoprojects/myvenv/lib/python3.6/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/ghk/djangoprojects/lab-in-the-wild/labinthewild/settings.py", line 18, in <module>
from config import *
ModuleNotFoundError: No module named 'config'
If I command 'python manage.py runserver', it show this error.
As you said in your comments, you cloned this project from git.
Perhaps config is a local settings file you are meant to create yourself. Check the README and also check for a config example of some sorts

Cannot install MySQL 5.5 with django 1.8.2 on Windows 7 64bit

I had MySQL 5.5 installed as part of XAMPP stack on Win7 64bit. I am using python 3.4 and I want to try out Django. So I installed Django using pip from command line and it worked fine with the default sqlite3 db.
To integrate MySQL, I see installed 'mysql-connector-python' using pip. I changed the engine to ''mysql.connector.django'. I changed the settings.py file with the DATABASE settings as follows:
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'db',
'USER': 'root',
'PASSWORD': '',
}
}
When I check the server, I get the following error:
Traceback (most recent call last):
File "c:\Python34\lib\site-packages\django\db\utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "c:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "c:\Python34\lib\site-packages\mysql\connector\django\base.py", line 50, in <module>
from django.db.backends import (BaseDatabaseFeatures, BaseDatabaseOperations,
ImportError: cannot import name 'BaseDatabaseFeatures'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "c:\Python34\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "c:\Python34\lib\site-packages\django\core\management\__init__.py", line 312, in execute
django.setup()
File "c:\Python34\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "c:\Python34\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "c:\Python34\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "c:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "c:\Python34\lib\site-packages\django\contrib\auth\models.py", line 41, in <module>
class Permission(models.Model):
File "c:\Python34\lib\site-packages\django\db\models\base.py", line 139, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "c:\Python34\lib\site-packages\django\db\models\base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "c:\Python34\lib\site-packages\django\db\models\options.py", line 250, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "c:\Python34\lib\site-packages\django\db\__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "c:\Python34\lib\site-packages\django\db\utils.py", line 240, in __getitem__
backend = load_backend(db['ENGINE'])
File "c:\Python34\lib\site-packages\django\db\utils.py", line 129, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'mysql.connector.django' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'base', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: cannot import name 'BaseDatabaseFeatures'
Found a bug filed here-
https://bugs.mysql.com/bug.php?id=76752
For resolution, it suggests-
Adjust the backend to the changes in Django API. See the release notes for details:
https://docs.djangoproject.com/en/1.8/releases/1.8/#database-backend-api
How do I adjust the backend? I have no idea how to proceed.
Installing from the forked version works.
pip install git+https://github.com/multiplay/mysql-connector-python
From Github repo description this one is
Fork of version 2.0.4 of mysql-connector-python (and probably rebased
at points) until upstream issues are fixed
Got the reference from bug url.
The latest version of mysql-connector-python works with Django 1.8. You can get it from the mysql website.
(version mysql-connector-python-2.1.3)
Install it from the MySQL:
pip install http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.3.tar.gz

No module named '_sqlite3' error

Python 2.6 and Django 1.6 was installed on the server (Suse).
I installed Python 3.4 and Django 1.7.
I can run
django-admin.py startproject hi
Once I run any command related to manage.py like
python manage.py syncdb
I will get this error
File "/usr/local/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 33, in <module>
from pysqlite2 import dbapi2 as Database
ImportError: No module named 'pysqlite2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 35, in <module>
from sqlite3 import dbapi2 as Database
File "/usr/local/lib/python3.4/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.4/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named '_sqlite3'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/usr/local/lib/python3.4/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python3.4/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/usr/local/lib/python3.4/site-packages/django/contrib/auth/models.py", line 40, in <module>
class Permission(models.Model):
File "/usr/local/lib/python3.4/site-packages/django/db/models/base.py", line 122, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/usr/local/lib/python3.4/site-packages/django/db/models/base.py", line 297, in add_to_class
value.contribute_to_class(cls, name)
File "/usr/local/lib/python3.4/site-packages/django/db/models/options.py", line 166, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/usr/local/lib/python3.4/site-packages/django/db/__init__.py", line 40, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/lib/python3.4/site-packages/django/db/utils.py", line 242, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python3.4/site-packages/django/db/utils.py", line 108, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/local/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/usr/local/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 38, in <module>
raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named '_sqlite3'
according to Install pysqlite in virtualenv with python3 support
There is no public version of pysqlite for Python 3.x.
Also, I installed sqlite-autoconf-3080704. and still I get the same error message.
how can I solve it?
You seem to have only a minimum installation of Python 3. If you're using Debian or a Debian-based system like Ubuntu, you can do apt-get install python3 to install the full version.

Categories