error message when i run .python manage.py runserver' - linux

I am new to to python,
i keep getting this error message "syntax error "from the wsgi.py file
I have tried to edit the file to python_home to my virtualenv, it still shows the
Can anyone help please
enter image description here
o manage.py package-lock.json requirements.txt ScrumMaster super.file websocketlab
djangowebsocketlab media requirements2.txt Scrum settings.ini update.py
(afo) [root#slave ScrumMaster]# python manage.py runserver 0.0.0.0:8000
Performing system checks...
Testing from slack=================
System check identified no issues (0 silenced).
January 31, 2023 - 06:17:02
Django version 2.1.7, using settings 'ScrumMaster.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f76df181950>
Traceback (most recent call last):
File "/home/linuxjobber/chatscrum/Django/ScrumMaster/afo/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/home/linuxjobber/chatscrum/Django/ScrumMaster/afo/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 137, in inner_run
handler = self.get_handler(*args, **options)
File "/home/linuxjobber/chatscrum/Django/ScrumMaster/afo/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
handler = super().get_handler(*args, **options)
File "/home/linuxjobber/chatscrum/Django/ScrumMaster/afo/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
return get_internal_wsgi_application()
File "/home/linuxjobber/chatscrum/Django/ScrumMaster/afo/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 45, in get_internal_wsgi_application
return import_string(app_path)
File "/home/linuxjobber/chatscrum/Django/ScrumMaster/afo/lib/python3.6/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/usr/local/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 674, in exec_module
File "<frozen importlib._bootstrap_external>", line 781, in get_code
File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/linuxjobber/chatscrum/Django/ScrumMaster/ScrumMaster/wsgi.py", line 26
python_home = /home/<your-user>/chatscrum/Django/ScrumMaster/venv
^
SyntaxError: invalid syntax

Related

ModuleNotFoundError: No module named 'app' on new Django installation

I am trying to set up a simple Django==4.0.6 dev environment on my Ubuntu 20.04. I'm creating a project folder, create and activate a venv first. Then I'm installing Dajngo using pip. I'm then creating a new project in the very same directory and then for testing this out, run the usual python manage.py command. Here's a quick list of commands I am using:
mkdir project && cd project
python3 -m venv venv
source venv/bin/activate
pip install django==4.0.6
django-admin startproject major .
python manage.py migrate
But I'm getting the following error:
Traceback (most recent call last):
File "/project/venv/lib/python3.8/site-packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/project/venv/lib/python3.8/site-packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
File "/project/venv/lib/python3.8/site-packages/django/core/management/base.py", line 95, in wrapped
saved_locale = translation.get_language()
File "/project/venv/lib/python3.8/site-packages/django/utils/translation/__init__.py", line 210, in get_language
return _trans.get_language()
File "/project/venv/lib/python3.8/site-packages/django/utils/translation/__init__.py", line 65, in __getattr__
if settings.USE_I18N:
File "/project/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 87, in __getattr__
self._setup(name)
File "/project/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 74, in _setup
self._wrapped = Settings(settings_module)
File "/project/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 183, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.8/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 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'app'
And further down, the rest of the error reads:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/project/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/project/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/project/venv/lib/python3.8/site-packages/django/core/management/base.py", line 427, in run_from_argv
connections.close_all()
File "/project/venv/lib/python3.8/site-packages/django/db/utils.py", line 212, in close_all
for alias in self:
File "/project/venv/lib/python3.8/site-packages/django/utils/connection.py", line 73, in __iter__
return iter(self.settings)
File "/project/venv/lib/python3.8/site-packages/django/utils/functional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/project/venv/lib/python3.8/site-packages/django/utils/connection.py", line 45, in settings
self._settings = self.configure_settings(self._settings)
File "/project/venv/lib/python3.8/site-packages/django/db/utils.py", line 148, in configure_settings
databases = super().configure_settings(databases)
File "/project/venv/lib/python3.8/site-packages/django/utils/connection.py", line 50, in configure_settings
settings = getattr(django_settings, self.settings_name)
File "/project/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 87, in __getattr__
self._setup(name)
File "/project/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 74, in _setup
self._wrapped = Settings(settings_module)
File "/project/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 183, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.8/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 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'app'
I wasn't able to find a similar case where someone got the same error using a plain new installation in a virtual environment.
I haven't modified any files in the installation, fresh installation only. I was wondering if this has to do anything with my non-env Python. But I couldn't figure out what it is following the traceback.
Update:
I have tested this on every other machine and it works fine as it is a simple installation process for any Django project.
Is your $DJANGO_SETTINGS_MODULE environment variable set to something with app in it by any chance?
Related documentation: https://docs.djangoproject.com/en/4.0/topics/settings/#designating-the-settings
To fix, unset that environment variable.
if you created folder 'app' manually and there don't exists _ _ init _ _.py - you receive those Error.

waagent not deprovisioning on preparing debian VHD Azure

When running the final command which is sudo waagent –force -deprovision after preparing a Debian VHD for Kali but it keeps finishing with the below messages:
Traceback (most recent call last):
File "/usr/sbin/waagent", line 33, in <module>
sys.exit(load_entry_point('WALinuxAgent==2.2.47', 'console_scripts', 'waagent')())
File "/usr/sbin/waagent", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/lib/python3.9/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/usr/lib/python3.9/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 790, in exec_module
File "<frozen importlib.bootstrap>", line 228, in call_with_frames_removed
File "/usr/lib/python3/dist-packages/azurelinuxagent/agent.py", line 34, in <module>
import azurelinuxagent.common.event as event
File "/usr/lib/python3/dist-packages/azurelinuxagent/common/event.py", line 632, in <module>
event_logger = EventLogger()
File "/usr/lib/python3/dist-packages/azurelinuxagent/common/event.py", line 304, in init
osutil = get_osutil()
File "/usr/lib/python3/dist-packages/azurelinuxagent/common/osutil/factory.py", line 50, in get_osutil
return _get_osutil(distro_name, distro_code_name, distro_version, distro_full_name)
File "/usr/lib/python3/dist-packages/azurelinuxagent/common/osutil/factory.py", line 79, in _get_osutil
return DebianOSBaseUtil()
NameError: name 'DebianOSBaseUtil' is not defined`
The deployment fails in Azure and I think this may be apart of that issue. I have reviewed their documentation and seen users having the same issue. Anyone ever faced this issue?
The original document in question that was used is this: https://learn.microsoft.com/en-us/azure/virtual-machines/linux/debian-create-upload-vhd
It looks like there is an error in the factory.py file.
try changing line 25 to add ", DebianOSBaseUtil" to the end of the import statement.

Django: ModuleNotFoundError after reinstalling Python and Django

I have two Django projects (project-x and project-y) which were running fine initially. However after reinstalling python and Django, I keep getting the error ModuleNotFoundError: No module named 'project-x' when I run python3 manage.py runserver for any of my other projects.
This exact error occurs for every new project I create and try to run no matter its location and virtual environment being run. Everything was working before the reinstall and ready to ship so I am desperate to find out whats gone wrong because there is absolutely no reference to project-x in any of the other projects ..
Terminal
chaudim#TD project-y % python3 manage.py runserver
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 61, in execute
super().execute(*args, **options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 68, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/Cellar/python#3.9/3.9.1_6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'project-x'
Projects folder
django-projects
- project-y
- manage.py
- CalendarApp
- init.py
- admin.py
- views.py
- models.py
...
- project-y
- init.py
- settings.py
- urls.py
- wsgi.py
- asgi.py
- project-x
same structure as above...

'Python manage.py runserver' "ValueError: Unable to configure handler 'mail_admins'".:

I'm working on a Django project.
When starting the server I get "ValueError: Unable to configure handler 'mail_admins'".
I'm in the correct directory, with virtual environment started.
I can't make migrations, same error apears.
Everything was working fine was able to start the server on this method in the past with no problem, until today.
Thanks in advance!
Version:
Windows 10
Python 3.8.1
Django==3.1.5
frego#Yisus-Robles MINGW64 ~/Desktop/news
$ python manage.py runserver
Traceback (most recent call last):
File "c:\users\frego\appdata\local\programs\python\python38\lib\logging\config.py", line 563, in configure
handler = self.configure_handler(handlers[name])
File "c:\users\frego\appdata\local\programs\python\python38\lib\logging\config.py", line 744, in configure_handler
result = factory(**kwargs)
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\utils\log.py", line 89, in __init__
self.reporter_class = import_string(reporter_class or settings.DEFAULT_EXCEPTION_REPORTER)
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "c:\users\frego\appdata\local\programs\python\python38\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 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
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\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\views\__init__.py", line 1, in <module>
from django.views.generic.base import View
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 971, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 914, in _find_spec
File "<frozen importlib._bootstrap_external>", line 1342, in find_spec
File "<frozen importlib._bootstrap_external>", line 1314, in _get_spec
File "<frozen importlib._bootstrap_external>", line 1443, in find_spec
File "<frozen importlib._bootstrap_external>", line 1483, in _fill_cache
OSError: [WinError 1392] El archivo o directorio est▒ da▒ado o es ilegible: 'C:\\Users\\frego\\.virtualenvs\\frego-6ij68a4f\\lib\\site-packages\\django\\views\\generic'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\utils\log.py", line 71, in configure_logging
logging.config.dictConfig(DEFAULT_LOGGING)
File "c:\users\frego\appdata\local\programs\python\python38\lib\logging\config.py", line 808, in dictConfig
dictConfigClass(config).configure()
File "c:\users\frego\appdata\local\programs\python\python38\lib\logging\config.py", line 570, in configure
raise ValueError('Unable to configure handler '
ValueError: Unable to configure handler 'mail_admins'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\core\management\__init__.py", line 370, in execute
_parser = self.fetch_command('runserver').create_parser('django', 'runserver')
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\core\management\__init__.py", line 244, in fetch_command
klass = load_command_class(app_name, subcommand)
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\core\management\__init__.py", line 37, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "c:\users\frego\appdata\local\programs\python\python38\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\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\core\management\commands\runserver.py", line 10, in <module>
from django.core.servers.basehttp import (
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\core\servers\basehttp.py", line 17, in <module>
from django.core.handlers.wsgi import LimitedStream
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\core\handlers\wsgi.py", line 5, in <module>
from django.core.handlers import base
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\core\handlers\base.py", line 15, in <module>
from .exception import convert_exception_to_response
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\core\handlers\exception.py", line 18, in <module>
from django.views import debug
File "C:\Users\frego\.virtualenvs\frego-6ij68a4f\lib\site-packages\django\views\__init__.py", line 1, in <module>
from django.views.generic.base import View
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 971, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 914, in _find_spec
File "<frozen importlib._bootstrap_external>", line 1342, in find_spec
File "<frozen importlib._bootstrap_external>", line 1314, in _get_spec
File "<frozen importlib._bootstrap_external>", line 1443, in find_spec
File "<frozen importlib._bootstrap_external>", line 1483, in _fill_cache
OSError: [WinError 1392] El archivo o directorio est▒ da▒ado o es ilegible: 'C:\\Users\\frego\\.virtualenvs\\frego-6ij68a4f\\lib\\site-packages\\django\\views\\generic'
It seems that the error is arisen from the LOGGING in the settings of the project. Take a look in the LOGGING['handlers'].

Unable to run pd.read_excel for scripts that previously worked

I am unable to get my python scripts working. To clarify they did work before but now they not, the code itself is not the issue. Whenever I try to run one I get an error specifically on the line pd.read_excel(file)
Traceback (most recent call last):
File "automated_cleaning.py", line 9, in <module>
df = pd.read_excel(roster_file)
File "C:\Users\"User"\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\util\_decorators.py", line 208, in wrapper
return func(*args, **kwargs)
File "C:\Users\"User"\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\excel\_base.py", line 310, in read_excel
io = ExcelFile(io, engine=engine)
File "C:\Users\"User"\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\excel\_base.py", line 819, in __init__
self._reader = self._engines[engine](self._io)
File "C:\Users\"User"\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\excel\_xlrd.py", line 20, in __init__
import_optional_dependency("xlrd", extra=err_msg)
File "C:\Users\"User"\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\compat\_optional.py", line 90, in import_optional_dependency
module = importlib.import_module(name)
File "C:\Users\"User"\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 724, in exec_module
File "<frozen importlib._bootstrap_external>", line 860, in get_code
File "<frozen importlib._bootstrap_external>", line 791, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\"User"\AppData\Local\Programs\Python\Python37\lib\site-packages\xlrd\__init__.py", line 1187
print "EXTERNSHEET(b7-):"
^
SyntaxError: invalid syntax
Process finished with exit code 1
After searching it seems like the file is corrupt and that is the reason why it is not working. I have tried changing the function to use a different engine but I still get a similar error.
I have tried running pip install to try and fix the package in both Pycharm Terminal and the cmd line but in either scenario it doesn't work.
Any suggestions?
I had similar problem in past, I just updated my xlrd module.
python -m pip install --upgrade xlrd
and also try to put r in file path
pd.read_excel(r"C:\Users\")
I hope you're using python-3.x

Resources