我正在尝试运行使用我的应用程序模型的python
脚本,但是出现错误。
我的目录结构:
my_app
-venv (My virtual environment)
-manage.py
-my_web_app
-Scripts
-CreateDBTAFs.py (This is the script i'm trying to execute)
在这里,我的脚本导入(在CreateDBTAFs.py
中):
import sys
sys.path.insert(0, '/my_app/')
import os, sys
PWD = os.getenv('PWD')
os.chdir(PWD)
sys.path.insert(0, os.getenv('PWD'))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "local_settings.py")
import django
django.setup()
#import standalone
#standalone.run('my_app.settings')
from my_web_app.models import MyModel
from django.contrib.auth.models import User
from nltk import word_tokenize
import my_web_app.models
import os
这是错误:
Traceback (most recent call last):
File "my_web_app/Scripts/CreateDBTAFs.py", line 2, in <module>
standalone.run('taf_analytics.settings')
File "/my_app/venv/lib/python3.6/site-packages/standalone.py", line 27, in run
django.setup()
File "/my_app/venv/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/my_app/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 57, in __getattr__
self._setup(name)
File "/my_app/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/my_app/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 107, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/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 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 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'my_app'