我有一个写入项目,其结构如下所示:
- root
- gpucache
- __init__.py
- libgpucache.so
- cache_warpper.py
- test_cache.ipynb
- train.py
libgpucache.so 是用 c++ 编写的,有一个Cache
类,而 cache_wrapper.py 有一个CacheWrapper
类,它是 的扭曲器Cache
,当我在同一目录(test_cache.ipynb)中测试 CacheWrapper 时,它可以工作。
在cache_wrapper.py中我导入libgpucache如下
import libgpucache as gpucache
在 train.py 中,我像下面一样导入 CacheWrapper
from gpucache.cache_wrapper import CacheWrapper
但是当我在根目录中运行 train.py 时,它给出了以下错误:
AttributeError: module 'libgpucache' has no attribute 'NewCache'. Did you mean: 'LFUCache'?
我可以确保 libgpucache 中存在 NewCache 并且它在 test_cache.ipynb 中工作。
有人可以给我一些建议吗?
2
$(document).ready(function() {
$(“.js-gps-inline-related-questions .spacer”).click(function () {
fireRelatedEvent($(this).index() + 1, $(this).data(‘question-id’));
});
function fireRelatedEvent(position, questionId) {
StackExchange.using(“gps”, function() {
StackExchange.gps.track(‘related_questions.click’,
{
position: position,
originQuestionId: 78339235,
relatedQuestionId: +questionId,
location: ‘inline’,
source: ‘Baseline_Fallback’
});
});
}
});
function toggleInlineRelated(showMore) {
var inlineRelatedLess = document.getElementById(“inline_related_var_a_less”);
var inlineRelatedMore = document.getElementById(“inline_related_var_a_more”);
var inlineRelatedSeeMore = document.getElementById(“inline_related_see_more”);
var inlineRelatedSeeLess = document.getElementById(“inline_related_see_less”);
if (showMore) {
inlineRelatedLess.classList.add(“d-none”);
inlineRelatedSeeMore.classList.add(“d-none”);
inlineRelatedMore.classList.remove(“d-none”);
inlineRelatedSeeLess.classList.remove(“d-none”);
}
else {
inlineRelatedMore.classList.add(“d-none”);
inlineRelatedSeeLess.classList.add(“d-none”);
inlineRelatedLess.classList.remove(“d-none”);
inlineRelatedSeeMore.classList.remove(“d-none”);
}
}
NewCache
定义或使用。–
❖
import .libgpucache as gpucache
如果您打算将该目录用作包,则需要将导入更改为gpucache
(显然您确实这样做,因为有一个__init__.py
)。–
|