我想在我的mac上导入python3中的matplotlib。这给了我一个错误:
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: bad magic number in 'matplotlib': b'\x03\xf3\r\n'
如果在stackoverflow上做了一些研究,我想2.7应该在sys.path中,对吧?我怎么能删除这个?还有其他建议吗?
>>> sys.path
['', '/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/site-packages', '/usr/local/opt/opencv/lib/python2.7/site-packages', '/usr/local/opt/opencv/lib/python3.6/site-packages']
编辑:有人刚提到这个:
sys.path = [x for x in sys.path if "python2.7" not in x]
运作良好。错误消失但出现了新的错误......
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'matplotlib'
所以我尝试用
重新安装matplotlibbrew install matplotlib --with-python3
这种方法运作良好:
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (caskroom/cask, homebrew/core).
==> Updated Formulae
planck
==> Installing matplotlib from homebrew/science
==> Downloading https://files.pythonhosted.org/packages/f5/f0/9da3ef24ea7eb0ccd1
######################################################################## 100,0%
==> Downloading https://files.pythonhosted.org/packages/dc/8c/7c9869454bdc53e72f
######################################################################## 100,0%
==> python -c import setuptools... --no-user-cfg install --prefix=/usr/local/Cel
==> Downloading https://files.pythonhosted.org/packages/c2/4b/137dea450d6e1e3d47
######################################################################## 100,0%
==> python -c import setuptools... --no-user-cfg install --prefix=/usr/local/Cel
==> Downloading https://files.pythonhosted.org/packages/c5/60/6ac26ad05857c60130
######################################################################## 100,0%
==> python -c import setuptools... --no-user-cfg install --prefix=/usr/local/Cel
==> Downloading https://files.pythonhosted.org/packages/38/bb/bf325351dd8ab6eb3c
######################################################################## 100,0%
==> python -c import setuptools... --no-user-cfg install --prefix=/usr/local/Cel
==> Downloading https://files.pythonhosted.org/packages/51/fc/39a3fbde6864942e8b
######################################################################## 100,0%
==> python -c import setuptools... --no-user-cfg install --prefix=/usr/local/Cel
==> Downloading https://files.pythonhosted.org/packages/d0/e1/aca6ef73a7bd322a7f
######################################################################## 100,0%
==> python -c import setuptools... --no-user-cfg install --prefix=/usr/local/Cel
==> Downloading https://files.pythonhosted.org/packages/b3/b2/238e2590826bfdd113
######################################################################## 100,0%
==> python -c import setuptools... --no-user-cfg install --prefix=/usr/local/Cel
==> Downloading https://files.pythonhosted.org/packages/b8/2f/49e53b0d0e94611a2d
######################################################################## 100,0%
==> python -c import setuptools... --no-user-cfg install --prefix=/usr/local/Cel
==> python -c import setuptools... --no-user-cfg install --prefix=/usr/local/Cel
Last 15 lines from /Users/-/Library/Logs/Homebrew/matplotlib/09.python:
File "setupext.py", line 874, in include_dirs_hook
import numpy
File "numpy/__init__.py", line 142, in <module>
File "numpy/add_newdocs.py", line 13, in <module>
File "numpy/lib/__init__.py", line 8, in <module>
File "numpy/lib/type_check.py", line 11, in <module>
File "numpy/core/__init__.py", line 26, in <module>
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name multiarray
READ THIS: https://docs.brew.sh/Troubleshooting.html
These open issues may also help:
Matplotlib –with-python3 doesn’t compile (because of qhull) https://github.com/Homebrew/homebrew-science/issues/5175
graph-tool dependencies and headers missing during installation https://github.com/Homebrew/homebrew-science/issues/5583
gubbins: influences on quast https://github.com/Homebrew/homebrew-science/issues/5752
rampart: Build a bottle for Linuxbrew https://github.com/Homebrew/homebrew-science/pull/5414
nest: revision for gsl https://github.com/Homebrew/homebrew-science/pull/5888
Formula affected by Homebrew/brew#2482 https://github.com/Homebrew/homebrew-science/issues/5470
nest: Enable concurrent Python 2 & 3 support https://github.com/Homebrew/homebrew-science/pull/5620
Migrate most notable formulae to core https://github.com/Homebrew/homebrew-science/issues/6331
gubbins - Failed to import the site module (since python 3.4 -> 3.5) https://github.com/Homebrew/homebrew-science/issues/3490
graph-tool: symbol binding failed https://github.com/Homebrew/homebrew-science/issues/3259