neovim:没有名为 __future__ 的模块
neovim: no module named __future__
当我尝试在 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.py
或 os.pyc
文件的目录中打开 python 文件,就会发生这种情况。看起来 neovim 正在尝试导入本地 os.py 文件而不是 virtualenv 中的文件。
我该怎么办?
编辑:原来不是当我在与 os.py
文件相同的目录中打开文件时,而是当我在当前工作目录有一个 os.py
文件的任何地方打开文件时。基本上,看起来 python 在检查 python 库之前正在检查本地目录的导入。
我明白了。问题出在我的 $PYTHONPATH
上。我的 .bashrc
文件中有这个:
export PYTHONPATH="$PYTHONPATH:~/.local/lib/python"
问题在于,当执行该行时,$PYTHONPATH
为空,导致字符串以 :
开头。我不是 100% 确定为什么,但这导致 python 在检查 python 库之前检查模块的本地目录。
我改成了
if [ -z "$PYTHONPATH" ]; then
export PYTHONPATH="~/.local/lib/python"
else
export PYTHONPATH="$PYTHONPATH:~/.local/lib/python"
fi
现在可以使用了。
当我尝试在 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.py
或 os.pyc
文件的目录中打开 python 文件,就会发生这种情况。看起来 neovim 正在尝试导入本地 os.py 文件而不是 virtualenv 中的文件。
我该怎么办?
编辑:原来不是当我在与 os.py
文件相同的目录中打开文件时,而是当我在当前工作目录有一个 os.py
文件的任何地方打开文件时。基本上,看起来 python 在检查 python 库之前正在检查本地目录的导入。
我明白了。问题出在我的 $PYTHONPATH
上。我的 .bashrc
文件中有这个:
export PYTHONPATH="$PYTHONPATH:~/.local/lib/python"
问题在于,当执行该行时,$PYTHONPATH
为空,导致字符串以 :
开头。我不是 100% 确定为什么,但这导致 python 在检查 python 库之前检查模块的本地目录。
我改成了
if [ -z "$PYTHONPATH" ]; then
export PYTHONPATH="~/.local/lib/python"
else
export PYTHONPATH="$PYTHONPATH:~/.local/lib/python"
fi
现在可以使用了。