SirVer / ultisnips

UltiSnips - The ultimate snippet solution for Vim. Send pull requests to SirVer/ultisnips!
GNU General Public License v3.0
7.52k stars 690 forks source link

Some errors with UltiSnips.vim and UltiSnips_Manager, no snippets working #1557

Closed MahbubAlam231 closed 1 week ago

MahbubAlam231 commented 1 week ago

Expected behavior: No errors while running ultisnips.

Actual behavior: Can't use any snippets. When I enter insert mode in a file, the following errors show up:

- Error detected while processing InsertCharPre Autocommands for "*"..script /home/mahbub/.vim/plugged/ultisnips/autoload/UltiSnips.vim

- Error detected while processing TextChangedI Autocommands for "*"..script /home/mahbub/.vim/plugged/ultisnips/autoload/UltiSnips.vim:

- Error detected while processing TextChangedI Autocommands for "*"..function UltiSnips#TrackChange:

- NameError: name 'UltiSnips_Manager' is not defined

- File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 228, in partial_apport_excepthook

- File "/home/mahbub/.vim/plugged/ultisnips/pythonx/UltiSnips/snippet_manager.py", line 7, in <module>

from contextlib import contextmanager

Steps to reproduce


    set nocompatible

    call plug#begin('~/.vim/plugged')

    Plug 'SirVer/ultisnips'

    call plug#end()

    filetype indent plugin on

Not able to debug what's going on. In the mean time can't use any snippets.

MahbubAlam231 commented 1 week ago

Found the error with help from chatGPT:

" The error you're encountering (ImportError: cannot import name 'GenericAlias' from 'types') indicates that there's a conflict between Python’s standard types module and a file named types.py in your project directory (/home/your_computer/python-code/types.py). This is causing Python to load the local file instead of the built-in types module, leading to the import error.

To resolve this, you need to rename or remove the conflicting types.py file from your project directory.

Steps to Resolve:

  1. Rename the Conflicting types.py File:

    • Navigate to your python-code directory and rename the types.py file to something else, like custom_types.py.
      mv /home/your_computer/python-code/types.py /home/your_computer/python-code/custom_types.py
  2. Remove Any Associated types.pyc or __pycache__ Files:

    • After renaming, you should also remove any compiled Python bytecode (.pyc files) or the __pycache__ directory for types.py to avoid conflicts:
      rm -rf /home/your_computer/python-code/__pycache__/types.*
  3. Test Python's Standard Library:

    • After renaming, test if the standard library works properly by running the following command:
      python3 -c "from contextlib import contextmanager"
    • If it runs without errors, the issue is resolved.
  4. Verify in Vim:

    • Open Vim again and check if the UltiSnips error still occurs. Since the root cause was a conflict with the Python types module, this should fix the issue.

Why This Happened:

Python prioritizes local module files over the standard library. Since you had a types.py file in your working directory, it shadowed the built-in types module, leading to the import errors in contextlib, functools, and other modules that depend on types.

Let me know if this resolves the issue! "