我已安装libpng,但安装autopy时出现"找不到'png.h'文件 #include <png.h>"错误
我刚开始学Python,最近想在我的Mac(Mavericks,10.9.4)上安装autopy。 我看了很多介绍和别人的问题,但还是没能成功安装autopy。以下是我安装autopy的步骤:
- 我从http://ethan.tira-thompson.com/Mac_OS_X_Ports.html安装了libpng。
- 作为一个初学者,我查看了/Library/Frameworks和/usr/local,觉得我应该是正确安装了libpng。
- [终端]
git clone git://github.com/msanders/autopy.git
- 根据介绍,我在autopy文件“src/screengrab.c”的第七行写了
#include <OpenGL/gl.h>
。 - [终端]
cd autopy
- [终端]
python setup.py build
然后在命令窗口出现了以下内容:
src/png_io.c:3:10: fatal error: 'png.h' file not found
#include <png.h>
^
1 error generated.
error: command 'cc' failed with exit status 1
我需要在png_io.c中重写“png.h”的文件地址吗?我该怎么在Mac上安装autopy?我是不是漏掉了什么重要的步骤?
4 个回答
0
在我确认 png.h 文件在默认路径下之后
/usr/local/include/png.h
我运行了以下命令,强制将这些路径作为构建的默认选项
sudo CPPFLAGS='-I/usr/local/include/' LDFLAGS='-L/usr/local/lib/' python setup.py build
结果成功了(在 OS X Yosemite 10.10.5 系统上)
记得要运行命令的 install 版本,并且在尝试使用 AutoPy 之前,要先 cd 退出 autopy 目录
1
试试这个,这对我有效。
sudo add-apt-repository ppa:linuxuprising/libpng12
sudo apt update
sudo apt install libpng12-0
1
每次我尝试安装autopy的时候都会遇到这个问题。正如Evert在你问题的评论中提到的,你的编译器找不到libpng
。如果你已经通过你提到的这个链接正确安装了它,那么你可以添加一些环境变量,这样编译器就能找到它,而不需要去修改源代码。
下面是一个在我的OS X Yosemite(10.10.1)上能正常工作的完整示例:
git clone git://github.com/msanders/autopy.git
cd autopy
export LIBRARY_PATH="/usr/local/lib:/usr/local/include/libpng"
export C_INCLUDE_PATH="/usr/local/lib:/usr/local/include/libpng"
python setup.py build
sudo python setup.py install
8
试试这个:
sudo apt-get install libpng-dev
我现在正在安装autopy,卡在同一个步骤。安装了libpng-dev之后,问题就解决了。 :)
安装autopy的完整过程如下:
sudo apt-get install libx11-dev
解决“找不到 #include ”的错误sudo apt-get install libxtst-dev
解决“找不到 #include ”的错误sudo apt-get install libpng-dev
解决“找不到 #include ”的错误easy_install autopy