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'")
Related
I am creating a Django website. I was recently using the management command runserver_plus provided by Django Extensions to run the development server. When I attempt to run the website through terminal I receive the error message:
C:\Users\Hp\anaconda3\DJANGO\website> python manage.py runserver_plus --cert-file
cert.crt
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
File "C:\Users\Hp\anaconda3\lib\site-packages\django\core\management\__init__.py", line
446, in execute_from_command_line
utility.execute()
File "C:\Users\Hp\anaconda3\lib\site-packages\django\core\management\__init__.py", line
440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Hp\anaconda3\lib\site-packages\django\core\management\__init__.py", line
279, in fetch_command
klass = load_command_class(app_name, subcommand)
File "C:\Users\Hp\anaconda3\lib\site-packages\django\core\management\__init__.py", line
48, in load_command_class
module = import_module("%s.management.commands.%s" % (app_name, name))
File "C:\Users\Hp\anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Hp\anaconda3\lib\site-
packages\django_extensions\management\commands\runserver_plus.py", line 40, in <module>
from django_extensions.management.utils import RedirectHandler, has_ipdb, setup_logger,
signalcommand
File "C:\Users\Hp\anaconda3\lib\site-packages\django_extensions\management\utils.py",
line 6, in <module>
from django_extensions.management.signals import post_command, pre_command
File "C:\Users\Hp\anaconda3\lib\site-packages\django_extensions\management\signals.py",
line 13, in <module>
pre_command = Signal(providing_args=["args", "kwargs"])
TypeError: __init__() got an unexpected keyword argument 'providing_args'
As you can see on the PyPi page for django-extensions, the highest Django version it supports is 3.2. The providing_args argument for django.dispatch.Signal was removed in Django 4.0, and based on your error you seem to be using that version or later.
Every Django project that I'm trying from git is showing the same error. Although I install all the requirements it is still showing error while I try to run the server.
This is the command which I try to execute:
And this is the final error:
And here is the error.
G:\Study\Python\Django Project\Airline-reservation-django-master>py manage.py makemigration
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 341, in execute
django.setup()
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\apps\config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\vivek\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "G:\Study\Python\Django Project\Airline-reservation-django-master\Airline\models.py", line 2, in <module>
from django.contrib.auth.models import User
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
RuntimeError: __class__ not set defining 'AbstractBaseUser' as <class 'django.contrib.auth.base_user.AbstractBaseUser'>. Was __classcell__ propagat
ed to type.__new__?
it is because it provide its own virtual environment and in that environment not all the requirements install try to install all the requirements again to solve this problem from pycharm
the only thing you have to do is you have to specify your python interpreter and install your require software on that
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.
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.
Very new to Django - I'm trying to get a site set up on Webfaction using their guide. http://docs.webfaction.com/software/django/getting-started.html
I've updated settings.py as instructed but I'm getting a syntax error in my settings.py file. I've tried going through and making sure there are no tabs and just spaces.
Here's the error message:
python3.3 manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/conf/__init__.py", line 128, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/lib/python3.3/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1586, in _gcd_import
File "<frozen importlib._bootstrap>", line 1567, in _find_and_load
File "<frozen importlib._bootstrap>", line 1534, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1024, in load_module
File "<frozen importlib._bootstrap>", line 1005, in load_module
File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 855, in _load_module
File "<frozen importlib._bootstrap>", line 982, in get_code
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "/home/bstolte/webapps/mo_detector/mo_detector/mo_detector/settings.py", line 35
INSTALLED_APPS = (
^
SyntaxError: invalid syntax
Any ideas on why it's failing at INSTALLED_APPS?
Usually when you get a syntax error like that that's pointing at something you don't see any error with, it means there's an unclosed bracket, indentation block or other item preceding that in the file. The settings.py file follows normal Python syntax rules like any other .py file, so look for stuff preceding that line that might cause the parser to choke.