pyexiv2 未找到,但已在 Mac OSX El Capitan 上使用自制软件安装

pyexiv2 not found but already installed with homebrew on Mac OSX El Capitan

我已经用自制软件在 OSX El Capitan 上安装了 pyexiv2,但是当我尝试使用它时,找不到它。

$ brew install pyexiv2
Warning: pyexiv2-0.3.2_1 already installed

$ python mapillary_tools-master/python/geotag_from_gpx.py photos file.gpx
Traceback (most recent call last):
  File "/Users/nighto/Downloads/mapillary_tools-master/python/geotag_from_gpx.py", line 6, in <module>
import pyexiv2
ImportError: No module named pyexiv2

原来在安装 pyexiv2 时,brew 有一个非常重要的输出,我错过了:

==> Caveats
Python modules have been installed and Homebrew's site-packages is not 
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
  mkdir -p /Users/YOUR_USER/Library/Python/2.7/lib/python/site-packages
  echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/YOUR_USER/Library/Python/2.7/lib/python/site-packages/homebrew.pth

所以你只需要 运行 这两个命令就可以正常工作。