Несуществующая пользовательская ошибка ModuleNotFound для развертывания Django на Apache24Apache

Ответить
Anonymous
 Несуществующая пользовательская ошибка ModuleNotFound для развертывания Django на Apache24

Сообщение Anonymous »

The Problem
I have a Django deployment with Apache24 that was working as expected previously, with the django project name being "API_Materials". However, when I tried to make new migrations with

Код: Выделить всё

python manage.py makemigrations
, a command that never had any problem before, I got the following stacktrace:

Код: Выделить всё

(venv) C:\API\BD_API_Materials>python manage.py makemigrations
Traceback (most recent call last):
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\core\management\base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\core\management\base.py", line 453, in execute
self.check()
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\core\management\base.py", line 485, in check
all_issues = checks.run_checks(
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\core\checks\urls.py", line 36, in check_url_namespaces_unique
if not getattr(settings, "ROOT_URLCONF", None):
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\conf\__init__.py", line 102, in __getattr__
self._setup(name)
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\conf\__init__.py", line 89, in _setup
self._wrapped = Settings(settings_module)
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\conf\__init__.py", line 217, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Program Files\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 992, in _find_and_load_unlocked
File "", line 241, in _call_with_frames_removed
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'MaterialsAPI'
The module that the project tried to use is called "MaterialsAPI", while the project is "API_Materials". However, "MaterialsAPI" is likely a custom name created for this project, however this text doesn't exist in any existent file in the project.
Debugging
First I tried going "back on time" with

Код: Выделить всё

git reset --hard
with an external backup of the current situation, but this didn't fix the problem. While I was attempting to verify if this was specific for

Код: Выделить всё

makemigrations
command, I tried a non-existent command

Код: Выделить всё

makemigration
to check, but the error still persisted:

Код: Выделить всё

(venv) C:\API\BD_API_Materials>python manage.py makemigration
Traceback (most recent call last):
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\core\management\__init__.py", line 255, in fetch_command
app_name = commands[subcommand]
KeyError: 'makemigration'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\API\BD_API_Materials\manage.py", line 22, in 
main()
File "C:\API\BD_API_Materials\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\core\management\__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\core\management\__init__.py", line 262, in fetch_command
settings.INSTALLED_APPS
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\conf\__init__.py", line 102, in __getattr__
self._setup(name)
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\conf\__init__.py", line 89, in _setup
self._wrapped = Settings(settings_module)
File "C:\Users\afonso.campos\Desktop\BD_API_Materials\API\venv\lib\site-packages\django\conf\__init__.py", line 217, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Program Files\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 992, in _find_and_load_unlocked
File "", line 241, in _call_with_frames_removed
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'MaterialsAPI'
Analyzing the stacktrace, it looked like the error was being triggered because he exists in the

Код: Выделить всё

INSTALLED_APPS
section in

Код: Выделить всё

settings.py
, but that was not the case.

Код: Выделить всё

INSTALLED_APPS = [
'corsheaders',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'API_Materials.apps.ApiMaterialsConfig',
'rest_framework',
'rest_framework.authtoken',
'django_extensions',
'drf_yasg',
'cryptographic_fields'
]
With more debugging, I noticed that the directory changed in the middle of the execution (before being " C:\API\BD_API_Materials\ ", the correct directory for the project, and later going to a specific user. This happened maybe because of the apache setup, which used the wrong virtual environment directory, but I attempted to change it and restart the Apache server, which still wouldn't work. In this wrong directory, however, the word "MaterialsAPI" still didn't exist neither in this environment.
Observing the environment variables before the line which cause the error

Код: Выделить всё

settings.INSTALLED_APPS
, the text "MaterialsAPI" was found, with the wrong directory:

Код: Выделить всё

environ({
...
'VIRTUAL_ENV': 'C:\\Users\\afonso.campos\\Desktop\\BD_API_Materials\\API\\venv',
'DJANGO_SETTINGS_MODULE': 'MaterialsAPI.settings'
...
})
Then, I proceed to attempt to "force" the changes in the virtual environment, however when I run the

Код: Выделить всё

manage.py
command, they are reseted to their "wrong" values.
Lastly, this error doesn't occur when I test the project locally in a different environment.


Источник: https://stackoverflow.com/questions/781 ... n-apache24
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Apache»