linux-cultist / venv-selector.nvim

Allows selection of python virtual environment from within neovim
MIT License
378 stars 40 forks source link

Relative paths to python programs in anaconda are wrong on windows. #113

Closed wit-l closed 1 month ago

wit-l commented 2 months ago

This bug once appeared, although it was fixed at that time, but now it appears again. I detailed the situation in #87.

wit-l commented 2 months ago

The line 84 in lua/venv-selector/venv.lua did not account for the relative path of the Python executable under Anaconda on the Windows platform. Instead of [venv]/Scripts/python.exe, it should have considered [anaconda venv]/python.exe.

linux-cultist commented 1 month ago

Yes. The current version of the plugin has become a bit complex to maintain due to so many venv managers being added directly to the code. There is a rewrite in the regexp branch that works in a very different way, eliminating all bugs related to finding venvs.

It probably won't work very well on windows yet, and it's on my todo list to properly test it on windows as it's becoming more feature complete. It's using a completely different config that is much more flexible, while allowing you as a user to add whatever search for venvs you want and have it show up in the telescope viewer.

You can read the Readme in the regexp branch to get an idea. But it's still work in progress and I don't think it will work on windows yet, since I never tested it there. But I will.

linux-cultist commented 1 month ago

I installed windows in a virtual environment and added neovim there, and will work on proper windows support in the regexp branch the coming days. Just need to make sure the code handles windows environment variables and paths.

linux-cultist commented 1 month ago

You can try the regexp branch now on windows if you like. I spent some time making sure it works in powershell.

Configuration for lazy.nvim:

return {
  "linux-cultist/venv-selector.nvim",
    dependencies = {
      "neovim/nvim-lspconfig", 
      "mfussenegger/nvim-dap", "mfussenegger/nvim-dap-python", --optional
      { "nvim-telescope/telescope.nvim", branch = "0.1.x", dependencies = { "nvim-lua/plenary.nvim" } },
    },
  lazy = false,
  branch = "regexp", -- This is the regexp branch, use this until its merged with the main branch later
  config = function()
      require("venv-selector").setup()
    end,
    keys = {
      { ",v", "<cmd>VenvSelect<cr>" },
    },
},

Anaconda base and envs locations should be picked up if you have it in the default location on windows ($HOME/anaconda3). If you dont, you can just create two searches for where they are:

The plugin will look in $HOME/anaconda3 and $HOME/anaconda3/envs for anaconda venvs automatically but if you have them in another location, you can create two searches that replaces the build-in ones.

You can see here how the searches are defined right now and you can use that as a base for modification of your own searches: https://github.com/linux-cultist/venv-selector.nvim/blob/regexp/lua/venv-selector/config.lua

linux-cultist commented 1 month ago

Im closing this since the bug is for the old version of the plugin, and the new regexp version will be able to pick up your venvs if you add your own search. You can ask me for help and I can show you a search config that will work. Just need to know where your anaconda base directory is, and where you have your anaconda envs.