当前位置:   article > 正文

FileNotFoundError: Package has no location <module ‘imageio_ffmpeg.binaries‘ (namespace)>

package has no location

Anaconda虚拟环境下安装使用的pythonimageio[ffmpeg]包的时候,报错:

FileNotFoundError: Package has no location <module 'imageio_ffmpeg.binaries' (namespace)>
  • 1

重新安装下载还是一直报错,可能是曾经下载过ffmpeg并且添加了系统环境变量。将该变量删除以后重启仍然报错。报错信息提示不能定位ffmpeg的二进制文件夹,然而明明可以在安装库imageio_ffmpeg的路径里面找到该二进制文件夹1。我的在这里:

D:\Anaconda\envs\pytorch_cpu\Lib\site-packages\imageio_ffmpeg\binaries
  • 1

注意到_utils.py中的get_ffmpeg_exe函数:

def get_ffmpeg_exe():
    """
    Get the ffmpeg executable file. This can be the binary defined by
    the IMAGEIO_FFMPEG_EXE environment variable, the binary distributed
    with imageio-ffmpeg, an ffmpeg binary installed with conda, or the
    system ffmpeg (in that order). A RuntimeError is raised if no valid
    ffmpeg could be found.
    """

    # 1. Try environment variable. - Dont test it: the user is explicit here!
    exe = os.getenv("IMAGEIO_FFMPEG_EXE", None)
    if exe:
        return exe

    # Auto-detect
    exe = _get_ffmpeg_exe()
    if exe:
        return exe

    # Nothing was found
    raise RuntimeError(
        "No ffmpeg exe could be found. Install ffmpeg on your system, "
        "or set the IMAGEIO_FFMPEG_EXE environment variable."
    )

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
'
运行

该函数会首先查找IMAGEIO_FFMPEG_EXE环境变量,于是新增环境变量12

IMAGEIO_FFMPEG_EXE=D:\Anaconda\envs\pytorch_cpu\Lib\site-packages\imageio_ffmpeg\binaries\ffmpeg-win64-v4.2.2.exe
  • 1

再次测试能否正常运行,测试代码:

import imageio_ffmpeg
print(imageio_ffmpeg.get_ffmpeg_version())
  • 1
  • 2

输出

D:\Anaconda\envs\pytorch_cpu\python.exe ...\test.py 
4.2.2

Process finished with exit code 0
  • 1
  • 2
  • 3
  • 4

输出版本号则说明测试成功


  1. 上述路径均应该更改为你的python库路径../site-packages/.../ffmpeg-win64-v4.2.2.exe ↩︎ ↩︎

  2. 设置环境变量的方式如果不会可以自行百度 ↩︎

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/855042
推荐阅读
相关标签
  

闽ICP备14008679号