fisadev / vim-isort

Vim plugin to sort python imports using https://github.com/timothycrosley/isort
MIT License
219 stars 32 forks source link

No Python Module Detected #36

Open jacobseiler opened 4 years ago

jacobseiler commented 4 years ago

Hi there,

I am getting the error No isort python module detected, you should install it. More info at https://github.com/fisadev/vim-isort when trying to execute isort within Vim. Isort has correctly been pip installed:

$ which isort
/Library/Frameworks/Python.framework/Versions/3.8/bin/isort

and isort example.py indeed does sort the imports.

Vim version is 8.1.

(Searched previous issues and none of the solutions worked. I have pip installed isort through both python3.8 and 2.7).

ajslater commented 4 years ago

Also occurs with NVIM v0.4.3

Integralist commented 4 years ago

Yup I'm getting this.

I had installed isort with pipx (which uses the same python3 interpreter that vim was built with) but I also tried setting up a virtual environment using python3 -m venv foo and activating it and installing isort using normal pip command but the plugin still thinks it can't find isort.

In the end I uninstalled the plugin and just added the following to my vim file:

autocmd BufWritePost *.py :!isort %
ajslater commented 4 years ago

For a homebrew install, remove roxma/python-support module and it will work again.

The issue appears to be the roxma/python-support module b0rking up the sys.path and removing the

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

More sophisticated plugins, like black get around this by the plugin itself installing their dependancies in venvs and appending their special install path to sys.path on plugin load.

fx-kirin commented 4 years ago

I think this is related to using pyenv. Isort plugin seems to use system python on startup.

zsoobhan commented 4 years ago

I had a similar issue which vim-sort could not find isort even though it was installed globally and in the virtualenv.

I had to find the actual python binary vim was using and install it in there.

  1. in vim :py3 import sys; print(sys.path)

  2. navigate to that location and find the python binary, in my case: cd /usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/bin

  3. install isort using this binary ./python3.8 -m pip install isort

I am using pyenv and virtualenv which may have messed up my paths and for some reason vim-isort could not find the "correct" python version when using :py3 on the following line https://github.com/fisadev/vim-isort/blob/05d709d9086be8b344a29d45afe05fbc3a5eb179/ftplugin/python_vimisort.vim#L12

johangp commented 2 years ago

I had the same issue that @zsoobhan described above but that solution didn't work for me because even the command :py3 was not working.

I manage it installing the neovim package into the virtualenv

pip install neovim

adraper2 commented 2 years ago

On Mac M1, I was also getting this issue. This was my solution.

Check to see if under:

vim --version

python & python3 have + instead of -. If they have the -, just run:

brew install vim
aarchiba commented 2 years ago

I am running into this - I have neovim using its own virtualenv, which has isort installed. I can do :py3 import isort but if I run :Isort I get No isort python module detected, you should install it. More info at https://github.com/fisadev/vim-isort. I have done the same thing with black and can confirm that neovim is picking up the black I installed in the virtualenv.