导入数据时报错, ModuleNotFoundError: No module named 'Mxshop.settings'
来源:3-8 导入商品类别数据
Albino
2017-09-04
报错信息:
Traceback (most recent call last): File "D:/workspace/Mxshop/db_tools/import_category_data2.py", line 14, in <module> django.setup() File "D:\Envs\VueShop\lib\site-packages\django\__init__.py", line 22, in setup configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) File "D:\Envs\VueShop\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__ self._setup(name) File "D:\Envs\VueShop\lib\site-packages\django\conf\__init__.py", line 41, in _setup self._wrapped = Settings(settings_module) File "D:\Envs\VueShop\lib\site-packages\django\conf\__init__.py", line 110, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "D:\Envs\VueShop\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 978, in _gcd_import File "<frozen importlib._bootstrap>", line 961, in _find_and_load File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked ModuleNotFoundError: No module named 'Mxshop.settings'
manage.py
if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Mxshop.settings")
import_category_data.py
import sys import os pwd = os.path.dirname(os.path.realpath(__file__)) sys.path.append(pwd+"../") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Mxshop.settings") # 初始化django import django django.setup()
写回答
4回答
-
三秋
2019-05-13
如果是非win环境
sys.path.append(pwd+"../")
修改为
sys.path.append(pwd+"/..")
改了路径导入成功了,并没有在win下测试。
312020-04-18 -
Albino
提问者
2017-09-04
目录结构如下
00 -
bobby
2017-09-04
你截图我看看你的目录结构是如何的
052018-10-19 -
Albino
提问者
2017-09-04
改成Mxshop.Mxshop.settings就可以运行了
00
Python前后端分离开发Vue+Django REST framework实战
Django REST framework课程视频,RESTFul API前后端分离开发
2873 学习 · 2457 问题
相似问题