1

我尝试了很长时间在这台 Mac 上使用 python。我试图从我的 mac 中完全删除 python。然后我意识到很难摆脱这个默认的python。幸运的是,我在互联网上读到,在我弄清楚如何删除它之前删除它是一个坏主意。然后我还使用 *.dmg 包安装了 python、numpy、scipy、matplotlib。经过所有的努力,我每次导入pylab时仍然收到此错误消息。请帮我?任何人?

$python

Python 2.7.4 (v2.7.4:026ee0057e2d, Apr  6 2013, 11:43:10) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pylab


Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg/pylab.py", line 1, in <module>
  from matplotlib.pylab import *
File "/Library/Python/2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg/matplotlib/pylab.py", line 221, in <module>
 `from matplotlib import mpl  # pulls in most modules
File "/Library/Python/2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg/matplotlib/mpl.py", line 2, in <module>
 `from matplotlib import axis
File "/Library/Python/2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg/matplotlib/axis.py", line 14, in <module>
 `import matplotlib.text as mtext
File "/Library/Python/2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg/matplotlib/text.py", line 31, in <module>
 `from matplotlib.backend_bases import RendererBase
File "/Library/Python/2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg/matplotlib/backend_bases.py", line 48, in <module>
 `import matplotlib.textpath as textpath
File "/Library/Python/2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg/matplotlib/textpath.py", line 9, in <module>
 `from matplotlib.mathtext import MathTextParser
File "/Library/Python/2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg/matplotlib/mathtext.py", line 52, in <module>
 `import matplotlib._png as _png
ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg/matplotlib/_png.so, 2): Library not loaded: /opt/local/lib/libpng14.14.dylib
Referenced from: /Library/Python/2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg/matplotlib/_png.so
Reason: image not found

此外,我按照http://ipython.org/install.html上的说明安装 Anaconda。安装 Anaconda 后,我进入下一步

$ conda update conda

得到了这个

"-bash: conda: command not found"

我在网上搜索,但似乎没有其他人有这个问题。有人可以在这里给我一个提示吗?非常感谢!


在我的目录 /usr/bin 我有

python python-config python2.5 python2.5-config python2.6 python2.6-config python2.7 python2.7-config

使用命令 which python

我有/Library/Frameworks/Python.framework/Versions/2.7/bin/python

与哪个 ipython

我有/Library/Frameworks/Python.framework/Versions/2.7/bin/ipython

对于 numpy,我下载了 numpy-1.7.0-py2.7-python.org-macosx10.6.dmg 包,scipy-0.12.0-py2.7-python.org-macosx10.6.dmg 用于 scipy 和 matplotlib -1.2.0-py2.7-python.org-macosx10.6.dmg 用于 matplotbib。我下载了 *10.6.dmg 因为这就是我发现的......我找不到像 *10.7.dmg 这样的东西

我没有 .bashrc 或 .bashrc_profile。但我认为 .profile 会做,它看起来像这样

# MacPorts Installer addition on 2012-03-07_at_18:55:26: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
export TERM="xterm-color"
alias ls="ls -G"
export PS1="[\[\e[33m\]\u@\H \[\e[32m\]\w\[\e[0m\]]\n[\[\e[31m\]\!\[\e[0m\]] > "
# Setting PATH for Python 2.7
# The orginal version is saved in .profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

当我输入

$端口

它说这-bash: port: command not found 应该让我担心吗?我也可以评论一下吗

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

也?

4

1 回答 1

1

您似乎拥有 MacPorts。也许您可以使用 MacPorts 安装您选择的 Python,然后使用相应的pip(可能/opt/local/bin/pip是安装必要的 Python 包。

如果您不再使用 MacPorts,我建议改用自制软件:http: //mxcl.github.io/homebrew/。请注意安装 Python 后收到的消息:它告诉您一些 Python 脚本将安装在/usr/local/share/python. 在您的情况下,这可能不是问题(您列出的软件包没有安装 Python 脚本 afaik)。

请记住,同时使用 homebrew 和 MacPorts 可能仍然会混淆 Python 及其包。

最后,您需要确保不要继续使用其他 python 可执行文件。因此,在您的 中.profile,像这样注释掉最后两行:

#PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
#export PATH

更新 然后,摆脱 MacPorts 参考并确保您的 PATH 拾取/usr/local/bin,将您的.profile进一步更改为

# MacPorts Installer addition on 2012-03-07_at_18:55:26: adding an appropriate PATH variable for use with MacPorts.
#export PATH=/opt/local/bin:/opt/local/sbin:$PATH    # <- comment out
# Set /usr/local/bin explicitly for Homebrew
export PATH=/usr/local/bin:$PATH

在新的终端(或选项卡)中开始更新您的设置。

于 2013-05-07T13:00:08.413 回答