首页 > 解决方案 > ModuleNotFoundError:没有名为“脚本”的模块,但脚本实际存在且目录精确

问题描述

我创建了一个python sript,但是当我从他们的文件夹中导入脚本时,我得到 ModuleNotFoundError: No module named 'reconstructors' but the scripts are there

funtions/reconstructors.py
funtions/handlers.py

import reconstructors as resx
import handlers as hand

然后当我调用脚本时,我将它们sentenceform.py用于另一个脚本,我得到

ModuleNotFoundError:没有名为“reconstructors”的模块

那么如果删除重构器,我会得到

ModuleNotFoundError:没有名为“处理程序”的模块

这是sentenceform.py

import reconstructors as resx
import handlers as hand

def storeNewWrd(datname, val):
    import json_function as js
    data= js.loadJsonData(datname)
    find = hand.existInJsonData(dataname, val, 'words')
    if  find == False:
        data['words'].append({val : val})
        js.EditJsonData(data, datname)
        return True
    else:
        return False

def like(arg, dic):
    word1 = arg.split()
    word2 = dic.split()
    sol =0

    for wd2 in word2:
        for wd1 in word1:
            if wd1 == wd2:
                sol += 1 
    if sol/len(word2) * 100 > 97.0:
        return True
    else:
        return False        

# def ReConstructSentence(sentence):



def addWord(sentence):
    import json_function as js
    Wrds = sentence.split()
    data = js.loadJsonData('data')
    for i in range(len(Wrds)):
        Wrds[i] = resx.removeNonWordCharacters(Wrds[i])
        for datas in data['words']:
            if like(datas, Wrds[i]) == True:
                if hand.existInJsonData('data', Wrds[i], 'words'):
                    return False
            else:
                print(sentenceWrds[i])
                # storeNewWrd(datname, val)
                # return True`enter code here`

标签: python

解决方案


诀窍是使用路径定义来指定文件夹以便于访问

import sys
# the mock-0.3.1 dir contains testcase.py, testutils.py & mock.py
sys.path.append('/home/davis/Desktop/lisa/SentForm/functions')
import reconstructors as resx
import json_function as js
import handlers as 

推荐阅读