SublimeCodeIntel在Pandas和Numpy中自动补全失败
我在尝试让Sublime Text 3中的Python自动补全功能正常工作,但一直失败。很多博客和设置指南都推荐使用sublimecodeintel。它工作的时候确实很好,但我就是无法让它和我最常用的两个库——numpy和pandas一起工作。
我的设置是:
操作系统:Mac OS X 10.9.4
我通过Homebrew安装了Python 2.7、numpy和pandas。
我使用的是Sublime Text 3,并通过包管理器安装了sublimecodeintel。
举个例子:
import pandas as pd
import matplotlib.pyplot as plt
fig = plt.figure() # autocomplete and tooltips works fine.
data = pd.read_csv('file.csv') # no autocomplete or tooltips.
在使用'plt'的时候,自动补全选项和提示信息在点(.)之后第一次出现,然后在我开始写括号里的内容时又出现一次。但在使用'pd'的时候,什么都没有发生。
我找不到任何相关的文档或之前的问题。是不是我在设置上漏掉了什么?我的配置路径里缺少什么吗?为什么我的库不能使用自动补全功能呢!?
下面是我的配置文件和codintel.log的内容……
非常感谢!
我的sublimecodeintel配置文件:
{
"Python": {
"python": '/usr/local/bin/python',
"pythonExtraPaths": [
"/usr/local/lib/python2.7/site-packages",
"/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/",
"/Library/Python/2.7/site-packages/",
"/Library/Python/2.7/site-packages",
"/usr/local/lib/python2.7/site-packages"
]
}
}
codintel.log中的输出:
+ Info: processing `Python': please wait...
New env with catalogs for 'Python': PyWin32
Updating indexes for 'Python'... The first time this can take a while.
scan_purelang: path: '/Users/oscarbranson/UCDrive/Projects/APT/MassSpectrum/APT_MS_autorange.py' lang: Python
Python Syntax Error in '/Users/oscarbranson/UCDrive/Projects/APT/MassSpectrum/APT_MS_autorange.py': invalid syntax (<unknown>, line 9)
Doing CodeIntel for 'Python' (hold on)...
eval 'plt' at APT_MS_autorange.py#9 <Trigger 'python-complete-object-members' at 168 (explicit)>
start scope is (<Element 'scope' at 0x1066bdf50>, [])
find 'plt ...' starting at (<Element 'scope' at 0x1066bdf50>, []):
is blob 'matplotlib.pyplot' from <Python curdirlib>? no
is blob 'matplotlib.pyplot' from <Python extradirslib>? yes
imports:: setting reldirlib to: '/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib'
is 'plt' accessible on (<Element 'scope' at 0x1066bdf50>, [])? yes: <Element 'scope' at 0x1066aa7d0>
'plt' is <Element 'scope' at 0x1066aa7d0> on (<Element 'scope' at 0x1066aa7d0>, [])
is blob '__future__' from <Python reldirlib>? no
is blob '__future__' from <Python curdirlib>? no
is blob '__future__' from <Python extradirslib>? no
is blob '__future__' from <Python envlib>? no
is blob '__future__' from <Python sitelib>? no
is blob '__future__' from <Python cataloglib: PyWin32>? no
is blob '__future__' from <python-2.7 stdlib>? yes
#... big list here ...
done eval: success
Done 'Python' CodeIntel! Full CodeIntel took 10ms
Autocomplete called (Python) [calltips]
Updating indexes for 'Python'... The first time this can take a while.
scan_purelang: path: '/Users/oscarbranson/UCDrive/Projects/APT/MassSpectrum/APT_MS_autorange.py' lang: Python
Python Syntax Error in '/Users/oscarbranson/UCDrive/Projects/APT/MassSpectrum/APT_MS_autorange.py': invalid syntax (<unknown>, line 11)
Doing CodeIntel for 'Python' (hold on)...
eval 'pd' at APT_MS_autorange.py#27 <Trigger 'python-complete-object-members' at 500 (explicit)>
start scope is (<Element 'scope' at 0x107050de8>, [])
find 'pd ...' starting at (<Element 'scope' at 0x107050de8>, []):
is blob 'pandas' from <Python curdirlib>? no
is blob 'pandas' from <Python extradirslib>? yes
scan_purelang: path: '/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/compat/__init__.py' lang: Python
# ... big list here ...
done eval: success
Done 'Python' CodeIntel! Full CodeIntel took 411ms
1 个回答
我以前一直推荐SublimeCodeIntel,尽管有时候会出现一些小问题,直到我发现了Anaconda
。一旦你设置好(这个过程非常简单),它就能正常工作。它不需要初始化数据库,也不会出现损坏的情况,它会自动发现你添加的新包,运行时也不会打扰你……我对它的好评简直说不完。它使用了JEDI自动补全模块,速度快而且准确。它会自动判断变量的类型,并填入适合的方法和类供你调用。你还可以让它进行参数补全,但我觉得这个有点烦,所以我把它关掉了。它有一点做不到,就是方法链调用,但没有什么是完美的。它还包括代码复杂度检查和代码规范检查的模块,这些功能还不错,但我并不需要,只想在我想检查的时候才检查,所以我也把它关掉了。
我非常推荐你试试这个工具。除了方法链调用的问题,我对它非常满意,也没有再换回去。一个很酷的功能是,你可以在项目文件中为"python_interpreter"
设置不同的值,这样你就可以轻松使用虚拟环境,或者像我一样,一个项目用Python 2,另一个项目用Python 3。
顺便说一下,我不是开发者,也和他/她没有任何关系 :)