我遇到的麻烦主要是因为我对python和OSX缺乏经验,并且试图理解它们是如何工作的。在
所以对于初学者来说,我做了简单的安装,从我所能看出的一切都安装得很好:easy_install -U memory_profiler # pip install -U memory_profiler
接下来我创建了一个示例.py文件只是为了让球滚动:
^{pr2}$
尝试运行它,但出现了以下错误:$ python example.py
Traceback (most recent call last):
File "example.py", line 2, in
@profile
NameError: name 'profile' is not defined
这与其说是关于内存分析器模块的问题,不如说是我做错了什么和配置不正确?我将OSX10.8.2与Python2.7一起使用。在
这就是我的“哪个python”所说的:/Library/Frameworks/Python.framework/Versions/Current/bin/python
因为这是一个象征性的链接,当我转到原始链接时:/Library/Frameworks/Python.framework/Versions/2.7/bin/python
我困惑的地方是容易安装正确的内存_探查器.py此文件夹中的文件:/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
我知道当python运行时,它会检查PYTHONPATH和站点包中的模块。(??) 在
但是如果模块在site packages文件夹中,为什么示例.py工作?另外,如果站点包文件夹中的模块应该是路径的一部分,我想我至少可以运行内存_探查器.py只是想看看它是否由python运行,但却得到了以下错误:python memory_profiler.py
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python:
can't open file 'memory_profiler.py': [Errno 2] No such file or directory
这也让我感到困惑,因为它声明python位于:../2.7/Resources中/Python.app/Contents/MacOS/Python,但我认为它应该是../2.7/bin/python,它不应该检查内存吗_探查器.py文件在../2.7/lib/python2.7/site-packages中?在
还有,为什么这两个文件夹都存在,有什么区别?在/System/Library/Frameworks/Python.framework
/Library/Frameworks/Python.framework
我错过了一大块拼图,所以如果能帮我指出正确的方向,我将不胜感激。在
更新:
我不想说:from memory_profiler import profiler
可能是我的大部分骨灰问题,但现在我得到了这个错误:Traceback (most recent call last):
File "example.py", line 1, in
from memory_profiler import profiler
ImportError: cannot import name profiler