ModuleNotFoundError:尽管已安装,但没有名为“tf_slim”的模块

2024-09-27 07:21:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从deepvariant运行call_variants.py。我在安装cuda、tensorflow等设备上苦苦挣扎了好几个小时。。。不幸的是,我遇到了一个问题,我不知道该怎么办。让我们从头开始:

conda create --name tf tensorflow
conda activate tf
python --version
Python 3.7.9
python3 -c 'import tensorflow as tf; print(tf.__version__)'
2.3.0

现在我尝试运行命令:

python ${h_dir}/deepvariant/binaries/DeepVariant/1.0.0/DeepVariant-1.0.0/call_variants.zip \
--outfile ${test_dir}/test.gz \
--examples ${ex_dir}/ex_test.gz --checkpoint $model

我得到:

Traceback (most recent call last):
  File "/tmp/Bazel.runfiles_i55m5mpq/runfiles/com_google_deepvariant/deepvariant/call_variants.py", line 57, in <module>
    from deepvariant import modeling
  File "/tmp/Bazel.runfiles_i55m5mpq/runfiles/com_google_deepvariant/deepvariant/modeling.py", line 51, in <module>
    import tf_slim
ModuleNotFoundError: No module named 'tf_slim'

所以我当然决定安装它:

pip install tf_slim
Collecting tf_slim
  Using cached tf_slim-1.1.0-py2.py3-none-any.whl (352 kB)
Requirement already satisfied: absl-py>=0.2.2 in ./anaconda3/envs/tf/lib/python3.7/site-packages (from tf_slim) (0.11.0)
Requirement already satisfied: six in ./anaconda3/envs/tf/lib/python3.7/site-packages (from absl-py>=0.2.2->tf_slim) (1.15.0)
Installing collected packages: tf-slim
Successfully installed tf-slim-1.1.0

然而:

python3 -c 'import tf_slim as slim; print(slim.__version__)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'tf_slim' has no attribute '__version__'

当然,在运行该命令之后ModuleNotFoundError: No module named 'tf_slim'。那么也许可以安装康达

conda install -c conda-forge tf-slim

但这根本没用。。。我不知道下一步该做什么,期待任何想法

编辑: 当我运行这样的程序时:

try:
    import tf_slim as slim
    print("module 'tf_slim' is installed")
except ModuleNotFoundError:
    print("module 'tf_slim' is not installed")

python test.py
module 'tf_slim' is installed

但是在命令之后,仍然ModuleNotFoundError: No module named 'tf_slim'

“”_(ツ)_/“”


Tags: installedinpytestimportversiontfcall
2条回答

好的,我想我明白了。正如你们所看到的,我使用conda为tensorflow创建环境。正如我所读到的,建议使用此过程,否则您可能会遇到类似ModuleNotFoundError: No module named 'tensorflow'的情况,如here所述。那么我做了什么? 我停用并删除了任何conda环境,我决定在终端中不使用它来运行我的命令。然而,首先,我用python3运行命令,然后我发生了与ModuleNotFoundError: No module named 'tf_slim'相同的错误,我用pip3 install tf_slim安装了它,它成功了!接下来,我运行了deepvariant脚本postprocess_variants.py,我在altair模块上遇到了同样的问题,但我做了同样的操作,两个命令都起作用了

只需卸载tf_slim,然后再次安装tf_slim包,就可以了

相关问题 更多 >

    热门问题