I'm running Django 1.9 on python 3.4 in a virtualenv. It has been working, but today, it's not.
When I run ./manage.py runserver, I get the following error:
(django1)dan#danvb:~/Share/django1/suorganizer$ ./manage.py runserver
Performing system checks...
System check identified no issues (0 silenced). Unhandled exception in
thread started by <function check_errors.<locals>.wrapper at
0x7f48a01d2c80> Traceback (most recent call last): File
"/home/dan/Share/django1/lib/python3.4/site-packages/django/utils/autoreload.py",
line 226, in wrapper
fn(*args, **kwargs) File "/home/dan/Share/django1/lib/python3.4/site-packages/django/core/management/commands/runserver.py",
line 117, in inner_run
self.check_migrations() File "/home/dan/Share/django1/lib/python3.4/site-packages/django/core/management/commands/runserver.py",
line 163, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS]) File "/home/dan/Share/django1/lib/python3.4/site-packages/django/db/migrations/executor.py",
line 20, in __init__
self.loader = MigrationLoader(self.connection) File "/home/dan/Share/django1/lib/python3.4/site-packages/django/db/migrations/loader.py",
line 49, in __init__
self.build_graph() File "/home/dan/Share/django1/lib/python3.4/site-packages/django/db/migrations/loader.py",
line 170, in build_graph
self.load_disk() File "/home/dan/Share/django1/lib/python3.4/site-packages/django/db/migrations/loader.py",
line 105, in load_disk
migration_module = import_module("%s.%s" % (module_name, migration_name)) File
"/home/dan/Share/django1/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 2212, in _find_and_load_unlocked File "<frozen importlib._bootstrap>",
line 321, in _call_with_frames_removed File "<frozen importlib._bootstrap>",
line 2254, in _gcd_import File "<frozen importlib._bootstrap>",
line 2237, in _find_and_load File "<frozen importlib._bootstrap>",
line 2224, in _find_and_load_unlocked ImportError: No module named 'core.migrations.delete'
I uninstalled and reinstalled Django==1.9, and get the same error. In lib/python3.4/site-packages/django/core/, I don't have a migrations directory. I'm not sure what to look for. The command ./manage.py runserver worked for me on this project not so long ago.
Thank you.
Solved.
In I have a Django migrations folder, core/migrations/ in which instead of actually deleting a migration module, I renamed it xxx.delete thinking I might want to revert to it. Upon actually deleting that module, my ImportError was resolved.
Related
I have two django project on the same server.
Project 1 : is running (with gunicorn) to receive rest request and display data.
Project 2: is used only to execute django commands and is not running.
I would like to run a command from project2 inside project1 but when i do nothing is happening.
I tried :
Popen(["/opt/xxx/venv3/bin/python", "/opt/xxx/src/manage.py", "custom_commands", "params"])
os.system("/opt/xxx/venv3/bin/python /opt/xxx/src/manage.py custom_commands params")
without success (i tried to read the ouput of Popen but it's empty).
When i run the same command inside a python shell on the server it works so its must be related to calling a django command from another django project.
----Edit----
I managed to read the stderr with popen and i get :
Traceback (most recent call last):\n File "/opt/project2/venv3/lib/python3.9/site-packages/django/core/management/__init__.py", line 224, in fetch_command\n app_name = commands[subcommand]\nKeyError: \'mail_lre\'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "/opt/project2/src/manage.py", line 22, in <module>\n main()\n File "/opt/project2/src/manage.py", line 18, in main\n execute_from_command_line(sys.argv)\n File "/opt/project2/venv3/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line\n utility.execute()\n File "/opt/project2/venv3/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute\n self.fetch_command(subcommand).run_from_argv(self.argv)\n File "/opt/project2/venv3/lib/python3.9/site-packages/django/core/management/__init__.py", line 231, in fetch_command\n settings.INSTALLED_APPS\n File "/opt/project2/venv3/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__\n self._setup(name)\n File "/opt/project2/venv3/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup\n self._wrapped = Settings(settings_module)\n File "/opt/project2/venv3/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__\n mod = importlib.import_module(self.SETTINGS_MODULE)\n File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n File "<frozen importlib._bootstrap>", line 1030, in _gcd_import\n File "<frozen importlib._bootstrap>", line 1007, in _find_and_load\n File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked\n File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed\n File "<frozen importlib._bootstrap>", line 1030, in _gcd_import\n File "<frozen importlib._bootstrap>", line 1007, in _find_and_load\n File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked\n File "<frozen importlib._bootstrap>", line 680, in _load_unlocked\n File "<frozen importlib._bootstrap_external>", line 790, in exec_module\n File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed\n File "/opt/editik/src/Editik_django/__init__.py", line 4, in <module>\n from utils.apps import app_ready\n File "/opt/project2/src/utils/apps.py", line 15, in <module>\n from api.settings import LOG_EDITIK_DIR\n File "/opt/project2/src/api/__init__.py", line 4, in <module>\n from utils.apps import app_ready\nImportError: cannot import name \'app_ready\' from partially initialized module \'utils.apps\' (most likely due to a circular import) (/opt/project2/src/utils/apps.py)
Really weird since it's working outside django project.
Ok i solved it by adding --pythonpath and --settings at the end of my command.
Like :
Popen(["/opt/xxx/venv3/bin/python", "/opt/xxx/src/manage.py", "custom_commands", "params", "--pythonpath='/opt/xxx/src/'", "--settings='api.settings'"])
os.system("/opt/xxx/venv3/bin/python /opt/xxx/src/manage.py custom_commands params --pythonpath='/opt/xxx/src/' --settings='app.settings'")
When running 'python manage.py shell', I'm getting the following message:
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 "D:\Anaconda3\envs\mysite\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "D:\Anaconda3\envs\mysite\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "D:\Anaconda3\envs\mysite\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "D:\Anaconda3\envs\mysite\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "D:\Anaconda3\envs\mysite\lib\site-packages\django\apps\config.py", line 116, in create
mod = import_module(mod_path)
File "D:\Anaconda3\envs\mysite\lib\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 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'polls.apps.PollsConfigdjango'; 'polls.apps' is not a package
I have tried another solution where I had to use ./manage.py shell --plain, but it's does't work. Also tried a solution that stated the ipython version wasn't correct, but that solution didn't solve anything for me either.
You have an error in your Python code. Django cannot be started because the configuration is invalid. One of your INSTALLED_APPS is broken. A hint what could be wrong is given in the traceback.
For the actual error is, you need to figure it out yourself, as it would probably involve copy-pasting a lot of code from your project here and would not be a good fit for StackOverflow Q&A format.
While running server import error is generated. Here I even don't use this generic types anywhere in my file.
Then how can this error is generated???
C:\Python34\python.exe manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0000000004BC8B70>
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\core\management\commands\runserver.py", line 112, in inner_run
autoreload.raise_last_exception()
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\utils\autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\core\management\__init__.py", line 327, in execute
autoreload.check_errors(django.setup)()
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\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\tagging\models.py", line 5, in <module>
from django.contrib.contenttypes import generic
ImportError: cannot import name 'generic'
Your tagging library does not support Django 2.0. If you check Django's git repo, you will see that there is no more generic module in Django.contrib.contenttypes. It was removed in Django 1.9. Downgrade to Django 1.8 for your library to work or, which I would recommend, use a different tagging library, preferably one that is well enough maintained to support at least Django 1.11.
I had solved the error.
In settings.py file, there is INSTALLED_APPS. I removed 'tagging'
from that which solves all my errors.
Hope this helps.
I have been following tutorial how to import celery and run rabbitmq to my django project. and I have been following a tutorial on youtube. I do not now what I have missed but after the part where i ran python manage.py migrate djcelery it gives the result of:
root#1095ea233e7b:/app/main# python3 manage.py migrate djcelery
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/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 "/app/main/actinbox/settings.py", line 6, in <module>
import djcelery
this is the tutorial that I have been following:
Django Celery Part 1
As I said in a comment, it's probably because you installed celery 4.0.0.
the tutorial you followed uses celery 3.0.23.
If you really want to use the tutorial use pip install django-celery==3.0.23
this is not recommended because it's an outdated version.
I have psycopg2 installed on my computer under C:\Python34\Lib\site-packages\psycopg2
If I use a postgresql database in a django project outside a virtual environment, I get no error.But, when I want to transfer the project to a virtual env so that I can deploy it on heroku. But when I try to migrate the database I get an error saying psycopg2 module is not present. I even tried to install it inside the virtual env using pip install psycopg2 and even that didn't work. Here is the full traceback.
(denv) C:\Users\Saket\denv\musicalguru>python manage.py migrate
Traceback (most recent call last):
File "C:\Users\Saket\denv\lib\site- packages\django\db\backends\postgresql_psycopg2\base.py", line 20, in <module>
import psycopg2 as Database
File "C:\Users\Saket\denv\lib\site-packages\psycopg2\__init__.py", line 50, in<module>from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: DLL load failed: The specified module could not be found.
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:\Users\Saket\denv\lib\sitepackages
\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "C:\Users\Saket\denv\lib\site- packages\django\core\management\__init__.py", line 312, in execute
django.setup()
File "C:\Users\Saket\denv\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Saket\denv\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Users\Saket\denv\lib\site-packages\django\apps\config.py", line 198,in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Saket\denv\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:\Users\Saket\denv\lib\site- packages\django\contrib\auth\models.py", line 41, in <module>
class Permission(models.Model):
File "C:\Users\Saket\denv\lib\site-packages\django\db\models\base.py", line 139, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Users\Saket\denv\lib\site-packages\django\db\models\base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\Saket\denv\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:\Users\Saket\denv\lib\site-packages\django\db\__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\Saket\denv\lib\site-packages\django\db\utils.py", line 240, in__getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\Saket\denv\lib\site-packages\django\db\utils.py", line 111, in
load_backend
return import_module('%s.base' % backend_name)
File "C:\Users\Saket\denv\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:\Users\Saket\denv\lib\sitepackages\django\db\backends\postgresql_psyc
opg2\base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: DLL
load failed: The specified module could not be found.
I used the instructions to install in virtual env from here
And then added PostgreSQL's 'bin' directory on the system path. That seemed to do the trick.
Intalling psycopg2 from source into virtualenv under windows is a pain.
Instead you can create the virtualenv that have access to system wide installed packages.
virtualenv --system-site-packages env_dir