heic格式图片转为jpg格式 安装pyheif

windows不支持,现安装于linux

 pip install pyheif

用pip命令直接安装报错:

Collecting pyheif
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a0/b5/74e08a65b3775153f72b2bf75adf9ca48f41db207e0d21dd7c8876e413cb/pyheif-0.5.1.tar.gz
Requirement already satisfied: cffi>=1.0.0 in /root/miniconda3/envs/pytorch_env/lib/python3.6/site-packages (from pyheif)
Requirement already satisfied: pycparser in /root/miniconda3/envs/pytorch_env/lib/python3.6/site-packages (from cffi>=1.0.0->pyheif)
Building wheels for collected packages: pyheif
  Running setup.py bdist_wheel for pyheif ... error
  Complete output from command /root/miniconda3/envs/pytorch_env/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ydg5ncph/pyheif/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmppv0vja99pip-wheel- --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/pyheif
  copying pyheif/constants.py -> build/lib.linux-x86_64-3.6/pyheif
  copying pyheif/error.py -> build/lib.linux-x86_64-3.6/pyheif
  copying pyheif/reader.py -> build/lib.linux-x86_64-3.6/pyheif
  copying pyheif/__init__.py -> build/lib.linux-x86_64-3.6/pyheif
  copying pyheif/writer.py -> build/lib.linux-x86_64-3.6/pyheif
  creating build/lib.linux-x86_64-3.6/pyheif/data
  copying pyheif/data/version.txt -> build/lib.linux-x86_64-3.6/pyheif/data
  running build_ext
  generating cffi module 'build/temp.linux-x86_64-3.6/_libheif_cffi.c'
  creating build/temp.linux-x86_64-3.6
  building '_libheif_cffi' extension
  creating build/temp.linux-x86_64-3.6/build
  creating build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6
  gcc -pthread -B /root/miniconda3/envs/pytorch_env/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include -I/usr/include -I/root/miniconda3/envs/pytorch_env/include/python3.6m -c build/temp.linux-x86_64-3.6/_libheif_cffi.c -o build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6/_libheif_cffi.o
  build/temp.linux-x86_64-3.6/_libheif_cffi.c:541:31: fatal error: libheif/heif.h: No such file or directory
  compilation terminated.
  error: command 'gcc' failed with exit status 1
  
  ----------------------------------------
  Failed building wheel for pyheif
  Running setup.py clean for pyheif
Failed to build pyheif
Installing collected packages: pyheif
  Running setup.py install for pyheif ... error
    Complete output from command /root/miniconda3/envs/pytorch_env/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ydg5ncph/pyheif/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-n6ojl3e5-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/pyheif
    copying pyheif/constants.py -> build/lib.linux-x86_64-3.6/pyheif
    copying pyheif/error.py -> build/lib.linux-x86_64-3.6/pyheif
    copying pyheif/reader.py -> build/lib.linux-x86_64-3.6/pyheif
    copying pyheif/__init__.py -> build/lib.linux-x86_64-3.6/pyheif
    copying pyheif/writer.py -> build/lib.linux-x86_64-3.6/pyheif
    creating build/lib.linux-x86_64-3.6/pyheif/data
    copying pyheif/data/version.txt -> build/lib.linux-x86_64-3.6/pyheif/data
    running build_ext
    generating cffi module 'build/temp.linux-x86_64-3.6/_libheif_cffi.c'
    creating build/temp.linux-x86_64-3.6
    building '_libheif_cffi' extension
    creating build/temp.linux-x86_64-3.6/build
    creating build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6
    gcc -pthread -B /root/miniconda3/envs/pytorch_env/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include -I/usr/include -I/root/miniconda3/envs/pytorch_env/include/python3.6m -c build/temp.linux-x86_64-3.6/_libheif_cffi.c -o build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6/_libheif_cffi.o
    build/temp.linux-x86_64-3.6/_libheif_cffi.c:541:31: fatal error: libheif/heif.h: No such file or directory
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/root/miniconda3/envs/pytorch_env/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ydg5ncph/pyheif/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-n6ojl3e5-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-ydg5ncph/pyheif/

显示缺少依赖包,查阅了很多资料说是缺少devel。

去pip官网查看

需要先安装libffi libheif-dev libde65-dev

将第一条命令拷贝到linux报错:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package libffi
E: Unable to locate package libheif-dev

显示无法定位软件包,于是找能找到的软件包,输入如下命令

sudo apt search libffi

得到结果

正在排序... 完成
全文搜索... 完成  
libffi-dev/xenial,now 3.2.1-4 amd64 [已安装]
  Foreign Function Interface library (development files)

libffi6/xenial,now 3.2.1-4 amd64 [已安装,自动]
  Foreign Function Interface library runtime

libffi6-dbg/xenial 3.2.1-4 amd64
  Foreign Function Interface library runtime (debug symbols)

libffindex0/xenial 0.9.9.6-2 amd64
  library for simple index/database for huge amounts of small files

libffindex0-dev/xenial 0.9.9.6-2 amd64
  library for simple index/database for huge amounts of small files (development)

搜索后可以看到结果中,显示已安装了libffi-dev和libffi6 (最相关的libffi6)如果没有显示已安装的小伙伴直接输入如下命令:

sudo apt-get install libffi-dev

sudo apt-get install libffi6

再安装libde265-dev

sudo apt-get install libde265-dev

显示如下就安装成功

正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
将会同时安装下列软件:
  libde265-0
下列【新】软件包将被安装:
  libde265-0 libde265-dev
升级了 0 个软件包,新安装了 2 个软件包,要卸载 0 个软件包,有 70 个软件包未被升级。
需要下载 245 kB 的归档。
解压缩后会消耗 709 kB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://archive.ubuntu.com/ubuntu xenial/universe amd64 libde265-0 amd64 1.0.2-2 [234 kB]
获取:2 http://archive.ubuntu.com/ubuntu xenial/universe amd64 libde265-dev amd64 1.0.2-2 [11.6 kB]
已下载 245 kB,耗时 2秒 (100 kB/s)       
debconf: delaying package configuration, since apt-utils is not installed
正在选中未选择的软件包 libde265-0:amd64。
(正在读取数据库 ... 系统当前共安装有 44486 个文件和目录。)
正准备解包 .../libde265-0_1.0.2-2_amd64.deb  ...
正在解包 libde265-0:amd64 (1.0.2-2) ...
正在选中未选择的软件包 libde265-dev:amd64。
正准备解包 .../libde265-dev_1.0.2-2_amd64.deb  ...
正在解包 libde265-dev:amd64 (1.0.2-2) ...
正在处理用于 libc-bin (2.23-0ubuntu11) 的触发器 ...
/sbin/ldconfig.real: file /usr/local/cuda-10.0/targets/x86_64-linux/lib/libcudnn.so.7 is truncated

/sbin/ldconfig.real: file /usr/local/cuda-10.0/targets/x86_64-linux/lib/libcudnn.so is truncated

/sbin/ldconfig.real: file /usr/local/cuda-10.0/targets/x86_64-linux/lib/libcudnn.so.7.6.4 is truncated

再继续安装pyheif

pip install git+https://github.com/david-poirier-csn/pyheif.git

还是报错

Collecting git+https://github.com/david-poirier-csn/pyheif.git
  Cloning https://github.com/david-poirier-csn/pyheif.git to /tmp/pip-9gala2t_-build
Requirement already satisfied: cffi>=1.0.0 in /root/miniconda3/envs/pytorch_env/lib/python3.6/site-packages (from pyheif==0.5.1)
Requirement already satisfied: pycparser in /root/miniconda3/envs/pytorch_env/lib/python3.6/site-packages (from cffi>=1.0.0->pyheif==0.5.1)
Installing collected packages: pyheif
  Running setup.py install for pyheif ... error
    Complete output from command /root/miniconda3/envs/pytorch_env/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-9gala2t_-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-5m593lml-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/pyheif
    copying pyheif/constants.py -> build/lib.linux-x86_64-3.6/pyheif
    copying pyheif/error.py -> build/lib.linux-x86_64-3.6/pyheif
    copying pyheif/reader.py -> build/lib.linux-x86_64-3.6/pyheif
    copying pyheif/__init__.py -> build/lib.linux-x86_64-3.6/pyheif
    copying pyheif/writer.py -> build/lib.linux-x86_64-3.6/pyheif
    creating build/lib.linux-x86_64-3.6/pyheif/data
    copying pyheif/data/version.txt -> build/lib.linux-x86_64-3.6/pyheif/data
    running build_ext
    generating cffi module 'build/temp.linux-x86_64-3.6/_libheif_cffi.c'
    creating build/temp.linux-x86_64-3.6
    building '_libheif_cffi' extension
    creating build/temp.linux-x86_64-3.6/build
    creating build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6
    gcc -pthread -B /root/miniconda3/envs/pytorch_env/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include -I/usr/include -I/opt/local/include -I/root/miniconda3/envs/pytorch_env/include/python3.6m -c build/temp.linux-x86_64-3.6/_libheif_cffi.c -o build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6/_libheif_cffi.o
    build/temp.linux-x86_64-3.6/_libheif_cffi.c:541:31: fatal error: libheif/heif.h: No such file or directory
    compilation terminated.
    error: command 'gcc' failed with exit status 1

还是显示没有libheif/heif.h,下载libheif-dev

apt-get install libheif-dev

报错

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package libheif-dev

卧槽,无情!

更新apt

sudo apt-get update
命中:1 http://security.ubuntu.com/ubuntu xenial-security InRelease       
命中:2 http://archive.ubuntu.com/ubuntu xenial InRelease                 
忽略:3 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64  InRelease
命中:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
命中:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease
忽略:6 https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64  InRelease
命中:7 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64  Release
命中:8 https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64  Release
正在读取软件包列表... 完成  

继续,还是报错

ubuntu是16的版本,比较老,没有源,去找相应的源,安装就行(大佬帮我搞的)。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
在Go语言中,你可以使用第三方来实现HEIC格式图片批量转换为JPG格式。一个常用的是github.com/dsoprea/go-heic-convert。以下是一个简单的示例代码: ```go package main import ( "fmt" "io/ioutil" "os" "path/filepath" "github.com/dsoprea/go-heic-convert/convert" ) func main() { // 输入HEIC图片所在文件夹路径 inputDir := "/path/to/input/directory" // 输出JPG图片所在文件夹路径 outputDir := "/path/to/output/directory" // 获取输入文件夹下的所有HEIC文件 files, err := ioutil.ReadDir(inputDir) if err != nil { fmt.Printf("无法读取输入文件夹:%v\n", err) os.Exit(1) } // 遍历每个HEIC文件并进行转换 for _, file := range files { if !file.IsDir() && filepath.Ext(file.Name()) == ".heic" { inputFile := filepath.Join(inputDir, file.Name()) outputFile := filepath.Join(outputDir, file.Name()+".jpg") err = convert.ConvertHEICFile(inputFile, outputFile) if err != nil { fmt.Printf("转换失败:%s\n", inputFile) } else { fmt.Printf("转换成功:%s\n", inputFile) } } } } ``` 请确保在运行代码之前,你已经安装了`github.com/dsoprea/go-heic-convert`。可以使用以下命令进行安装: ```shell go get -u github.com/dsoprea/go-heic-convert/... ``` 注意:该依赖于ImageMagick和libheif。在使用之前,请确保这两个已经正确安装并配置好环境变量。 运行上述代码时,将输入文件夹路径和输出文件夹路径替换为实际的路径。代码将遍历输入文件夹中的所有HEIC文件,并将其转换为JPG格式并保存在输出文件夹中。转换成功的文件将打印在控制台上,而转换失败的文件将显示相应的错误消息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值