golang 编译碰到问题 Package python-2.7 was not found in the pkg-config search path.

golang 运行单测或者编译程序时提示需要配置 PKG_CONFIG_PATH 环境变量,原因是在程序里使用了 go-python 包,要求运行环境有 python2.7,并设置 PKG_CONFIG_PATH 环境变量,解决方案如下:

# pkg-config --cflags  -- python-2.7
Package python-2.7 was not found in the pkg-config search path.
Perhaps you should add the directory containing `python-2.7.pc'
to the PKG_CONFIG_PATH environment variable
No package 'python-2.7' found
pkg-config: exit status 1

解决方案

1、下载 python2.7

访问 Python 2.7.18rc1,下载 Mac 版本的 python2.7 安装器,如果是 windows 版本,安装 windows 即可。

2、查找 pkgconfig 所在的路径,找到 /2.7/lib/pkgconfig 相关的那条路径,复制该路径

sudo find / -name pkgconfig

3、配置环境变量

把路径替换成你刚才复制的

sudo sh -c "echo 'export PKG_CONFIG_PATH=/System/Volumes/Data/Library/Frameworks/Python.framework/Versions/2.7/lib/pkgconfig' >> /etc/profile"

猜你喜欢

转载自blog.csdn.net/qq_41767116/article/details/130051399