python自动补全只对部分package有效,例如os, sys;大部分的库都不行

spacemacs

#1

spacemacs, 使用python-mode, anacoda-mode下,如题; 很奇怪,是不是package要放到指定目录才能被解析?


#2

没设置 virtualenv ?


#3

你的spacemacs,anaconda,jedi版本都是最新的吗?还有,你说的哪个库补全不行,举一个例子。“大部分”太笼统了


#4

virtualenv这个是没设,这个必须要设置吗?


#5

最直接的办法,打开一个py文件,检查一下 *anaconda-mode* buffer,把里面的错误信息贴上来让大家给你分析一下。正常情况下如果能够补全,应该是没有报错的:

image


#6

反复尝试了下,发现原来是使用Pip安装的包都无法自动提示,我google下,找到解决办法再来结贴


#7

我觉得不是,我也是pip安装的numpy,但能补全

但很慢,就是文件打开在那里放着,要几分钟后才能补全(不是说几分钟后出现补全项)


#8

几分钟这么吓人?


#9

看了下,可以补全的包是安装在

/usr/local/Cellar/python@2/2.7.15/Frameworks/Python.framework/Versions/2.7/lib/python2.7/

没法补全的包都是安装在

/usr/local/lib/python2.7/site-packages

#10

可能是调用了系统的python好像是同时有两个python,得看一下那些第三方包对应的是哪个python路径,试试 (setq python-shell-interpreter "/urs/local/bin/python")


#11

请问如何看第三方库对应的是哪个python解析器? 我看了我的$path变量

/usr/local/selfbin:/usr/local/jekyll:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin

确实是/usr/local/bin在前面,但是按你的方法还是不行


#12

当我引入系统变量PYTHONPATH, 再启动emacs,尝试补全pandas, 再anaconda-mode中会报如下错误

pans-MacBook-Pro:~ pan$ echo $PYTHONPATH
/usr/local/lib/python2.7/site-packages

anaconda_mode port 50297 Failed to import the site module Traceback (most recent call last): File “/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py”, line 544, in main() File “/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py”, line 530, in main known_paths = addusersitepackages(known_paths) File “/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py”, line 282, in addusersitepackages user_site = getusersitepackages() File “/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py”, line 258, in getusersitepackages user_base = getuserbase() # this will also set USER_BASE File “/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py”, line 248, in getuserbase USER_BASE = get_config_var(‘userbase’) File “/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py”, line 601, in get_config_var return get_config_vars().get(name) File “/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py”, line 580, in get_config_vars import _osx_support File “/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_osx_support.py”, line 4, in import re File “/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py”, line 142, in class RegexFlag(enum.IntFlag): AttributeError: module ‘enum’ has no attribute ‘IntFlag’ 127.0.0.1 - - [17/Jun/2018 09:58:34] ================================================================================ Traceback (most recent call last): File “/Users/pan/.emacs.d/anaconda-mode/0.1.12/service_factory-0.1.5-py2.7.egg/service_factory/providers/basehttp.py”, line 40, in do_POST status, response = self.server.service(data) File “/Users/pan/.emacs.d/anaconda-mode/0.1.12/service_factory-0.1.5-py2.7.egg/service_factory/service.py”, line 50, in call result = self.apply(method, args) File “/Users/pan/.emacs.d/anaconda-mode/0.1.12/service_factory-0.1.5-py2.7.egg/service_factory/service.py”, line 105, in apply server_error(args[‘id’], error) File “/Users/pan/.emacs.d/anaconda-mode/0.1.12/service_factory-0.1.5-py2.7.egg/service_factory/errors.py”, line 91, in server_error raise ServiceException(500, dumps(response)) ServiceException: (500, ‘{“jsonrpc”: “2.0”, “id”: 1, “error”: {“message”: “Server error”, “code”: -32000, “data”: “InternalError(‘The subprocess /usr/local/bin/python3.6 has crashed.’,)”}}’)


#13

感觉默认的解析器是python3,但是我已经设置了

(setq python-shell-interpreter "/usr/local/bin/python")

#14


#15

折腾了好久,目前通过如下方式解决了

M-x pythonic-activate RET /usr/local RET

相当于使用Virtual environment,并且将其值设为/usr/local

但是,没有找到有没有一劳永逸的设置,写到el文件中,每次自动加载就行了;

现在每次编辑python文件前,要先设置一遍。。


#17
(when (featurep 'cocoa)
   (require 'exec-path-from-shell)
   (exec-path-from-shell-initialize))

如果是Mac系统的话,可以尝试 exec-path-from-shell 这个插件, 只要 shell rc 文件中设置好 PATH , 然后把所有 shell rc 的PATH都导入到 Emacs 中, 就可以找到对应的 bin file 了.