我遇到的麻煩主要是因為我對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