我正在尝试使用嵌入式Python运行一些C ++代码。两周前,Code完全正常运行。代码仍在编译,但我现在收到错误
Traceback (most recent call last):
File "./main.py", line 1, in <module>
import numpy as np
File "/usr/local/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/usr/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 74, in <module>
from numpy.testing.nosetester import _numpy_tester
File "/usr/local/lib/python2.7/site-packages/numpy/testing/__init__.py", line 10, in <module>
from unittest import TestCase
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/__init__.py", line 64, in <module>
from .main import TestProgram, main
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 7, in <module>
from . import loader, runner
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/runner.py", line 7, in <module>
from .signals import registerResult
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/signals.py", line 2, in <module>
import weakref
File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
从那时起,我所做的唯一改变就是安装macOS Supplemental Update并将Python从2.7.13_1升级到2.7.14_2(使用Homebrew)。我更改了makefile中的相关链接器标志,即我键入python-config --ldflags
时出现的标志。我还确保我使用的Python绝对是Homebrew,它是按照Homebrew的指示将export PATH="/usr/local/opt/python/libexec/bin:$PATH"
插入我的.bash_profile。
我不确定这个错误是因为Python更新,最近的macOS补充更新还是其他原因。知道问题可能是什么?
由于
答案 0 :(得分:0)
我有同样的问题; 在python 2.7中,NumPy 1.8.0可用, 然后我使用brew安装NumPy(再次),我的python(2.7)中不再可用。 (你得到了同样的错误)
所以我做了#34; brew unlink python&amp;&amp; brew link python&#34;使用NumPy 1.14可用的python 3(而不是2)。 我猜python 2.7与最新版本的NumPy不兼容。