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

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

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

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

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

注意到_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."
    )

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

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

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

import imageio_ffmpeg
print(imageio_ffmpeg.get_ffmpeg_version())

输出

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

Process finished with exit code 0

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


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

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

  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值