python - 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`
解决方案
诀窍是使用路径定义来指定文件夹以便于访问
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
推荐阅读
- git - 当 git 创建树?
- django - Django Migrations:在使用数据库后修改模型的字段
- java - Optional 的 GC 开销
在爪哇 - google-analytics - 在 Google Analytics 中 - 我如何直接链接到今天的统计数据?
- javascript - 如何使用字节数据在 React js 中生成 PDF
- java - 在多维数组中创建对象的问题
- r - ggplot - 具有 2 和 3 y 轴的对齐图的相同 x 轴长度
- rust - “错误:借来的值不够长” 给线程时参考值失去作用域
- python - Scipy.Minimize 的问题,包括边界
- python - Pandas 0.24 read_sql 操作错误