neovim:没有名为__future__的模块

时间:2018-05-18 12:55:39

标签: python-2.7 virtualenv neovim pyenv

当我尝试在neovim中打开某些python文件时,出现错误:

"pool.py" 667L, 25276C
function provider#python#Call[9]..remote#host#Require[10]..provider#pythonx#Require, line 15
Vim(if):ch 1 was closed by the client
Traceback (most recent call last):
  File "/home/user/.pyenv/versions/neovim2/lib/python2.7/site.py", line 67, in <module>
    import os
  File "./os.py", line 44, in <module>
    from __future__ import absolute_import
ImportError: No module named __future__
Failed to load python host. You can try to see what happened by starting nvim with $NVIM_PYTHON_LOG_FILE set and opening the generated log file. Also
, the host stderr is available in messages.
Press ENTER or type command to continue

每当我在包含os.pyos.pyc文件的目录中打开python文件时,都会发生这种情况。看起来neovim试图导入本地os.py文件而不是virtualenv中的文件。

我该怎么办?

编辑:事实证明,当我在os.py文件所在的目录中打开文件时,当我在任何地方打开文件而当前工作目录有{时{1}}文件。基本上,看起来python在检查python库之前检查本地目录是否有导入。

1 个答案:

答案 0 :(得分:1)

我明白了。问题出在我的$PYTHONPATH上。我的.bashrc文件中有这个:

export PYTHONPATH="$PYTHONPATH:~/.local/lib/python"

问题在于,当执行该行时,$PYTHONPATH为空,从而导致以:开头的字符串。我不是百分之百确定原因,但是这导致python在检查python库之前检查本地目录中的模块。

我把它改成了

if [ -z "$PYTHONPATH" ]; then
  export PYTHONPATH="~/.local/lib/python"
else
  export PYTHONPATH="$PYTHONPATH:~/.local/lib/python"
fi

现在它有效。