Python Matplotlib错误:libfreetype.6.dylib
我正在尝试运行以下python脚本(我正在使用Vim): 当我这样做时,我会得到以下信息:Python Matplotlib错误:libfreetype.6.dylib,python,matplotlib,dylib,freetype,Python,Matplotlib,Dylib,Freetype,我正在尝试运行以下python脚本(我正在使用Vim): 当我这样做时,我会得到以下信息: Traceback (most recent call last): File "test.py", line 4, in <module> import matplotlib.pyplot as plt; File "/Library/Python/2.7/site-packages/matplotlib/pyplot.py", line 24, in <module&
Traceback (most recent call last):
File "test.py", line 4, in <module>
import matplotlib.pyplot as plt;
File "/Library/Python/2.7/site-packages/matplotlib/pyplot.py", line 24, in <module>
import matplotlib.colorbar
File "/Library/Python/2.7/site-packages/matplotlib/colorbar.py", line 29, in <module>
import matplotlib.collections as collections
File "/Library/Python/2.7/site-packages/matplotlib/collections.py", line 23, in <module>
import matplotlib.backend_bases as backend_bases
File "/Library/Python/2.7/site-packages/matplotlib/backend_bases.py", line 50, in <module>
import matplotlib.textpath as textpath
File "/Library/Python/2.7/site-packages/matplotlib/textpath.py", line 11, in <module>
import matplotlib.font_manager as font_manager
File "/Library/Python/2.7/site-packages/matplotlib/font_manager.py", line 53, in <module>
from matplotlib import ft2font
ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib/ft2font.so, 2): Library not loaded: @loader_path/../../../libfreetype.6.dylib
Referenced from: /Library/Python/2.7/site-packages/matplotlib/ft2font.so
Reason: image not found
shell returned 1
回溯(最近一次呼叫最后一次):
文件“test.py”,第4行,在
导入matplotlib.pyplot作为plt;
文件“/Library/Python/2.7/site packages/matplotlib/pyplot.py”,第24行,在
导入matplotlib.colorbar
文件“/Library/Python/2.7/site packages/matplotlib/colorbar.py”,第29行,在
将matplotlib.collections导入为集合
文件“/Library/Python/2.7/site packages/matplotlib/collections.py”,第23行,在
导入matplotlib.backend_base作为后端_base
文件“/Library/Python/2.7/site packages/matplotlib/backend_base.py”,第50行,在
将matplotlib.textpath导入为textpath
文件“/Library/Python/2.7/site packages/matplotlib/textpath.py”,第11行,在
将matplotlib.font\u管理器导入为font\u管理器
文件“/Library/Python/2.7/site packages/matplotlib/font_manager.py”,第53行,在
从matplotlib导入ft2font
ImportError:dlopen(/Library/Python/2.7/site-packages/matplotlib/ft2font.so,2):未加载库:@loader\u path/../../../../libfreetype.6.dylib
引用自:/Library/Python/2.7/site-packages/matplotlib/ft2font.so
原因:找不到图像
壳返回1
我尝试在brew
中重新安装brew
、重新安装freetype
、matplotlib
和numpy
,并且卸载了MacPorts,错误没有改变。建议
编辑:在卸载MacPorts,然后重新安装brew
之后,我现在收到了这个错误
Python致命错误:PyThreadState\u Get:没有当前线程
命令终止
该错误仅在导入时出现,因此我猜测问题出在matplotlib
上。我将尝试使用brew
重新安装它
EDIT2:我一直在尝试这样做,但没有效果,但我认为我的错误可能与此有关。检查图像的路径(并双重检查)
这在您的回溯中:
“原因:找不到图像”
也没有必要使用“;”在python中。检查图像的路径(并双重检查)
这在您的回溯中:
“原因:找不到图像”
也没有必要使用“;”在python中。修复了它。。。有点
修好了
我使用brew卸载matplotlib
卸载,然后使用pip安装matplotlib
安装。pip
版本现在可以工作了。虽然我认为我的代码有问题,因为我没有得到图像输出
我卸载了所有安装的python
,然后安装了ipython
,效果很好。另外,我忘了添加plt.show()代码>在myimshow()之后代码>命令…:-(……但至少有人在我之前犯了这个错误
有关任何matplotlib
imshow
问题的详细帮助,请参阅本页:
修复了它……有点
修好了
我用brew uninstall matplotlib
卸载,然后用pip install matplotlib
安装。pip
版本现在可以工作了。尽管我认为我的代码有问题,因为我没有得到图像输出
我卸载了所有安装的python
,然后安装了ipython
,效果很好。而且,我忘了在我的imshow();
命令之后添加plt.show();
。:-(..)但至少有人在我之前犯了这个错误
有关任何matplotlib
imshow
问题的详细帮助,请参阅本页:
听起来你已经(至少部分地)回答了您自己的问题,但我以一种不同的方式解决了相同的错误。摘要:我使用otool
和install\u name\u tool
手动将链接从*。因此
文件更改为不同的*.dylib
。我在这里发布它主要是为了说明如何构建系统如果你不小心,很快就会变成老鼠窝
背景
我正在使用conda来管理我试图从源代码()编译的软件项目的虚拟环境。为了在我的Mac上本地构建这个项目的图形子模块(gr qtgui
),我相信我犯了一些非常令人发指的反自然罪——下面将对此进行详细介绍
我避免构建问题的基本策略是尽可能依赖单个包管理器。在这种情况下,荣誉归于conda
,尽管其中一些需要brew
和pip
。在我写这篇文章时,我现在想知道是否应该链接Qt4的Mac框架,但我最终还是失败了oing是针对conda在~/miniconda3/envs/gr/lib
中安装的libQtCore.dylib
等进行链接的*
图形问题与解决方案
在编译GNU Radio之后,我在这个虚拟环境中安装了matplotlib
ImportError: dlopen(/Users/strotmc1/miniconda3/envs/gr/lib/python2.7/site-packages/matplotlib/ft2font.so, 2): Library not loaded: @rpath/libfreetype.6.dylib
Referenced from: /Users/strotmc1/miniconda3/envs/gr/lib/python2.7/site-packages/matplotlib/ft2font.so
Reason: Incompatible library version: ft2font.so requires version 21.0.0 or later, but libfreetype.6.dylib provides version 14.0.0
我通过导航到有问题的共享对象的目录并检查它来解决它:
>> cd ~/miniconda3/envs/gr/lib/python2.7/site-packages/matplotlib
>> otool -L ft2font.so
ft2font.so:
@rpath/libfreetype.6.dylib (compatibility version 21.0.0, current version 21.0.0)
@rpath/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
>> otool -l ft2font.so
...
Load command 9
cmd LC_LOAD_DYLIB
cmdsize 56
name @rpath/libfreetype.6.dylib (offset 24)
time stamp 2 Wed Dec 31 19:00:02 1969
current version 21.0.0
compatibility version 21.0.0
...
Load command 12
cmd LC_RPATH
cmdsize 272
path /Users/strotmc1/miniconda3/envs/gr/lib (offset 12)
...
换句话说,它正在链接到虚拟环境中的libfreetype.dylib,而不是系统上的libfreetype.dylib。这有点像是一个错误,因为pyplot也在尝试访问图形库,这些图形库已经进行了奇怪的配置。我的解决方案是切换到针对freetype的自制版本的链接:
>> install_name_tool -change @rpath/libfreetype.6.dylib /usr/local/Cellar/freetype/2.9/lib/libfreetype.6.dylib ft2font.so
现在matplotlib工作了
故事的寓意
我从一开始就说这个故事很难看。写完后,我得出以下结论:
尽管能够编译大型软件项目,但我仍然不知道自己到底在做什么
考虑到写一般目的的困难
>> install_name_tool -change @rpath/libfreetype.6.dylib /usr/local/Cellar/freetype/2.9/lib/libfreetype.6.dylib ft2font.so
ImportError: dlopen(/Users/shandou/anaconda3/lib/python3.6/site-
packages/matplotlib/ft2font.cpython-36m-darwin.so, 2): Library not
loaded: @rpath/libfreetype.6.dylib
Referenced from: /Users/shandou/anaconda3/lib/python3.6/site-
packages/matplotlib/ft2font.cpython-36m-darwin.so
Reason: Incompatible library version: ft2font.cpython-36m-darwin.so
requires version 22.0.0 or later, but libfreetype.6.dylib provides
version 21.0.0
File "/Users/shandou/anaconda3/lib/python3.6/site-
packages/matplotlib/backends/backend_macosx.py", line 17, in <module>
from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X
backend will not be able to function correctly if Python is not
installed as a framework. See the Python documentation for more
information on installing Python as a framework on Mac OS X. Please
either reinstall Python as a framework, or try one of the other
backends. If you are using (Ana)Conda please install python.app and
replace the use of 'python' with 'pythonw'. See 'Working with
Matplotlib on OSX' in the Matplotlib FAQ for more information.
$ brew install freetype
$ brew link --overwrite freetype
$ otool -L libfreetype.6.dylib | head -n 2
libfreetype.6.dylib:
/usr/local/opt/freetype/lib/libfreetype.6.dylib (compatibility version 23.0.0, current version 23.0.0)
$ cd /Users/shandou/anaconda3/lib/
$ sudo cp /usr/local/Cellar/freetype/2.9/lib/libfreetype.6.dylib .
brew upgrade freetype
cp /usr/local/Cellar/freetype/2.10.4/lib/libfreetype.dylib ~/opt/anaconda3/lib/
import matplotlib
matplotlib.use('PS')
import matplotlib.pyplot as plt