Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named leaderf #206

Closed
voldikss opened this issue Aug 30, 2018 · 8 comments
Closed

No module named leaderf #206

voldikss opened this issue Aug 30, 2018 · 8 comments

Comments

@voldikss
Copy link
Contributor

voldikss commented Aug 30, 2018

环境:Windows 10 git bash 自带 vim-8.1

执行 LeaderfFiles 后报错:no module named leaderf. 应该是这一行里 python 导入路径有问题。在Linux 下不会出错,但是 Windows 下经常遇到这种错误。

exec g:Lf_py "from leaderf.fileExpl import *"

我手动把这个路径增加到了 python 的环境变量里才可以用。可以的话把这个情况也考虑进去,不然每次手动改很费事。

@Yggdroot
Copy link
Owner

很奇怪,理论上,下面这几行已经把路径加到环境变量里了:

exec g:Lf_py "import vim, sys, os.path"
exec g:Lf_py "cwd = vim.eval('expand(\"<sfile>:p:h\")')"
exec g:Lf_py "sys.path.insert(0, os.path.join(cwd, 'leaderf', 'python'))"

你能加点打印看看出问题时你的sys.path里是什么吗?

@voldikss
Copy link
Contributor Author

voldikss commented Aug 30, 2018

sys.path:

['/c/Users/clouduan/.vim/plugged/LeaderF/autoload\\leaderf\\python', '\\\\?\\E:\\Applications\\Python35\\python35.zip', '_vim_path_']

主要的就在这里了。感觉像是 \\ 这个的问题...我的环境比较特殊,是 git bash 所以路径分隔符是 unix 风格的

@Yggdroot
Copy link
Owner

不是\\的问题,应该是系统识别不了/c/Users/clouduan/.vim/plugged/LeaderF/autoload

@voldikss
Copy link
Contributor Author

voldikss commented Aug 30, 2018

嗯我试了下确实是这样,这个好像没法改,感觉上只能手动改

@Yggdroot
Copy link
Owner

Yggdroot commented Aug 30, 2018

你把上面代码那三行改成下面试试:

exec g:Lf_py "import vim, sys, os.path, re"
exec g:Lf_py "cwd = vim.eval('expand(\"<sfile>:p:h\")')"
exec g:Lf_py "cwd = re.sub(r'(^.)', r'\1:', os.sep.join(cwd.split('/')[1:])) if os.name == 'nt' and cwd.startswith('/') else cwd"
exec g:Lf_py "sys.path.insert(0, os.path.join(cwd, 'leaderf', 'python'))"

@voldikss
Copy link
Contributor Author

可以了,感谢!
另外这个

exec g:Lf_py "cwd = re.sub(r'(^.)', r'\1:', os.sep.join(cwd.split('/')[1:])) if os.name == 'nt' and cwd.startswith('/') else cwd"

这里的 r\1 在外部 python 解释器里是可以的,但是在 vim 中调用python执行时1会被转义成\x01 ,导致 cwd 变成 '\x01:\\Users\\clouduan\\.vim\\plugged\\LeaderF\\autoload\\leaderf\\python'
所以我还得把 \ 转义 r\\1: :neckbeard:

@Yggdroot
Copy link
Owner

exec g:Lf_py "cwd = re.sub(r'(?<=^.)', r':', os.sep.join(cwd.split('/')[1:])) if os.name == 'nt' and cwd.startswith('/') else cwd"

改成这样试试。

@voldikss
Copy link
Contributor Author

可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants