jellydn / CopilotChat.nvim

Chat with GitHub Copilot in Neovim
GNU General Public License v3.0
100 stars 9 forks source link

ImportError when using :updateremoteplugin. #45

Closed carlesoctav closed 8 months ago

carlesoctav commented 8 months ago

Describe the bug

Encountered ImportError loading plugin at /home/carlesoctav/.local/share/nvim/lazy/CopilotChat.nvim/rplugin/python3/copilot-plugin.py: cannot import name 'LiteralString' from 'typing' (/usr/lib/python3.10/typing.py) Traceback (most recent call last): File "/home/carlesoctav/.local/lib/python3.10/site-packages/pynvim/plugin/host.py", line 193, in _load module = _handle_import(directory, name) File "/home/carlesoctav/.local/lib/python3.10/site-packages/pynvim/plugin/host.py", line 40, in _handle_import return importlib.import_module(name) File "/usr/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load ImportError: cannot import name 'LiteralString' from 'typing' (/usr/lib/python3.10/typing.py)

remote/host: python3 host registered plugins [] remote/host: generated rplugin manifest: /home/carlesoctav/.local/share/nvim/rplugin.vim

Reproduction

Perform all the instructions outlined in the README document.

System Info

i'll put my python dependencies here:
python 3.10.12
importlib-metadata==4.6.4
jeepney==0.7.1
keyring==23.5.0
launchpadlib==1.10.16
lazr.restfulclient==0.14.4
lazr.uri==1.0.6
more-itertools==8.10.0
msgpack==1.0.3
netifaces==0.11.0
numpy==1.26.3
oauthlib==3.2.0
opencv-python==4.9.0.80
prompt-toolkit==3.0.43
PyGObject==3.42.1
PyJWT==2.3.0
pynvim==0.5.0
pyparsing==2.4.7
python-apt==2.4.0+ubuntu2
python-dotenv==1.0.1
PyYAML==5.4.1
regex==2023.12.25
requests==2.31.0
SecretStorage==3.3.1
six==1.16.0
systemd-python==234
tiktoken==0.5.2
ubuntu-advantage-tools==8001
ufw==0.36.1
unattended-upgrades==0.1
urllib3==2.2.0
wadllib==1.3.6
wcwidth==0.2.13
youtube-dl==2021.12.17
zipp==1.0.

Used Package Manager

n/a

Validations

jellydn commented 8 months ago

Please let me know if that's resolved the issue. Thanks.

k-martynov commented 8 months ago

@jellydn I'm getting same error when running: :updateremoteplugin

Encountered ImportError loading plugin at /Users/kirchik/.local/share/nvim/lazy/CopilotChat.nvim/rplugin/python3/copilot-agent.py: cannot import name 'LiteralString' from 'typing' (/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/typing.py)
Traceback (most recent call last):
  File "/Users/kirchik/Library/Python/3.9/lib/python/site-packages/pynvim/plugin/host.py", line 193, in _load
    module = _handle_import(directory, name)
  File "/Users/kirchik/Library/Python/3.9/lib/python/site-packages/pynvim/plugin/host.py", line 40, in _handle_import
    return importlib.import_module(name)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
ImportError: cannot import name 'LiteralString' from 'typing' (/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/typing.py)

remote/host: python3 host registered plugins ['copilot-plugin.py']
remote/host: generated rplugin manifest: /Users/kirchik/.local/share/nvim/rplugin.vim
jellydn commented 8 months ago

Hi @k-martynov, based on your log, it's the old version. We only have python3/copilot-agent.py on main branch. Could you share your config? You also find my config on readme. Thanks.

k-martynov commented 8 months ago

@jellydn here is my config:

  {
    "jellydn/CopilotChat.nvim",
    dependencies = { "zbirenbaum/copilot.lua" },
    opts = {
      mode = "split",
      debug = false,
      prompts = {
        Explain = "Explain how it works.",
        Review = "Review the following code and provide concise suggestions.",
        Tests = "Briefly explain how the selected code works, then generate unit tests.",
        Refactor = "Refactor the code to improve clarity and readability.",
        Spelling = "Please correct any grammar and spelling errors in the following text.",
        Wording = "Please improve the grammar and wording of the following text.",
      },
    },
    build = function()
      vim.defer_fn(function()
        vim.cmd("UpdateRemotePlugins")
        vim.notify("CopilotChat - Updated remote plugins. Please restart Neovim.")
      end, 3000)
    end,
    event = "VeryLazy",
    keys = {
      { "<leader>cce", "<cmd>CopilotChatExplain<CR>",  desc = "CopilotChat - Explain code" },
      { "<leader>cct", "<cmd>CopilotChatTests<CR>",    desc = "CopilotChat - Generate tests" },
      { "<leader>ccr", "<cmd>CopilotChatReview<CR>",   desc = "CopilotChat - Review code" },
      { "<leader>ccR", "<cmd>CopilotChatRefactor<CR>", desc = "CopilotChat - Refactor code" },
      { "<leader>ccS", "<cmd>CopilotChatSpelling<CR>", desc = "CopilotChat - Correct spelling" },
      { "<leader>ccw", "<cmd>CopilotChatWording<CR>",  desc = "CopilotChat - Improve wording" },
    },
  },

After I've moved to canary(I've added to config branch = "canary") version I'm started getting this error:

Encountered ImportError loading plugin at /Users/kirchik/.local/share/nvim/lazy/CopilotChat.nvim/rplugin/python3/copilot-plugin.py: cannot import name 'Unpack' from 'typing' (/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/typing.py)
Traceback (most recent call last):
  File "/Users/kirchik/Library/Python/3.9/lib/python/site-packages/pynvim/plugin/host.py", line 193, in _load
    module = _handle_import(directory, name)
  File "/Users/kirchik/Library/Python/3.9/lib/python/site-packages/pynvim/plugin/host.py", line 40, in _handle_import
    return importlib.import_module(name)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
ImportError: cannot import name 'Unpack' from 'typing' (/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/typing.py)

remote/host: python3 host registered plugins []
remote/host: generated rplugin manifest: /Users/kirchik/.local/share/nvim/rplugin.vim
carlesoctav commented 8 months ago

Hello, there will be a tons of typing errors when using Python 3.10 (i try tweek the repo by my self). A more convenient solution is to install Python 3.12 using pyenv and set it as the global version, without compromising the pre-installed Python if you're using Ubuntu.

relevant link: https://webinstall.dev/pyenv/

k-martynov commented 8 months ago

@carlesoctav @jellydn thanks!

after updating to python 3.12 with pyenv and running again this line: pip install python-dotenv requests pynvim==0.5.0 prompt-toolkit

updateremoreplugins went well