gpt4 book ai didi

python - Django错误: ModuleNotFoundError: No module named 'ofac'

转载 作者:行者123 更新时间:2023-12-01 01:49:11 25 4
gpt4 key购买 nike

我有一个旧项目需要处理。运行项目时,我收到此无模块错误

我没有在虚拟环境中运行该项目。我在我的 MAC 上运行它。我正在运行 Django 2 或更高版本。

请参阅下面的文件夹结构图像。希望能帮助到你。

enter image description here

Traceback (most recent call last):
File "/Users/Dropbox/ofac_project/ofac_sdn/import_save/import_all_sdn.py", line 9, in <module>
django.setup()
File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/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 'ofac'

这是我想要运行的代码:

import csv, sys, os

# project_dir = "/Users/cohen/my-python-project/venv/ofac/ofac_project/ofac_sdn/import_save/"
project_dir = "/Users/Dropbox/ofac_project/ofac_sdn/import_save/"
sys.path.append(project_dir)
os.environ['DJANGO_SETTINGS_MODULE']='ofac.settings'

import django
django.setup()

from ofac_sdn.models import Ofac_Sdn
from ofac_sdn.models import Ofac_Add
from ofac_sdn.models import Ofac_Alt
from ofac_sdn.models import Ofac_Sdn_Comments


file = 'new_sdn.csv'
file1 = 'new_add.csv'
file2 ='new_alt.csv'
file3 ='new_sdn_comments.csv'

data = csv.reader(open(file),delimiter=",")
for row in data:
if row[0] !="Number":
post = Ofac_Sdn()
post.number = row[0]
post.name = row[1]
post.b_i=row[2]
post.programe=row[3]
post.more_info=row[4]
post.vessel_call_sign=row[5]
post.vessel_type=row[6]
post.vessel_dwt=row[7]
post.tonnage=row[8]
post.vessel_flag=row[9]
post.vessel_owner=row[10]
post.dob_aka=row[11]
post.save()

data1 = csv.reader(open(file1),delimiter=",")
for row in data1:
if row[0] !="Number":
post = Ofac_Add()
post.number_id = row[0] #am pus un _id la foreign key k asa stokeaza django foreign key-ul
post.n = row[1]
post.adresa=row[2]
post.oras=row[3]
post.stat=row[4]
post.s=row[5]
post.save()

data2 = csv.reader(open(file2),delimiter=",")
for row in data2:
if row[0] !="Number":
post = Ofac_Alt()
post.number_id = row[0]
post.ceva = row[1]
post.aka=row[2]
post.name_of_aka=row[3]
post.a=row[4]
post.save()

data3 = csv.reader(open(file3),delimiter=",")
for row in data3:
if row[0] !="Number":
post = Ofac_Sdn_Comments()
post.number_id = row[0]
post.more_info = row[1]
post.save()

最佳答案

您似乎将错误的目录添加到项目路径中。为了使用ofac.settings,您需要将项目目录设置为Users/Dropbox/ofac_project(包含manage.py的目录)和ofac

project_dir = "/Users/Dropbox/ofac_project"
sys.path.append(project_dir)
os.environ['DJANGO_SETTINGS_MODULE']='ofac.settings'

import django
django.setup()

关于python - Django错误: ModuleNotFoundError: No module named 'ofac' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50905972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com