Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get error "no module named imp" with Python 3.12 #538

Closed
vds2212 opened this issue Oct 9, 2023 · 8 comments
Closed

Get error "no module named imp" with Python 3.12 #538

vds2212 opened this issue Oct 9, 2023 · 8 comments
Labels

Comments

@vds2212
Copy link

vds2212 commented Oct 9, 2023

Python 3.12 has removed support for the imp library and in particular for the load_module method of that package.
The pynvim package do not support Python 3.12 anymore.

@justinmk
Copy link
Member

justinmk commented Oct 9, 2023

This is fixed but the fix hasn't been released yet. #534

@justinmk justinmk pinned this issue Oct 9, 2023
@justinmk justinmk added the bug label Oct 9, 2023
@vds2212
Copy link
Author

vds2212 commented Oct 10, 2023

I have tested the master branch and indeed it solves my problem.

@wookayin
Copy link
Member

wookayin commented Oct 13, 2023

Workaround: Until released, you can install the master version (0.5.0.devN):

python -m pip install 'pynvim @ git+https://github.com/neovim/pynvim'

Note that path to python (you can verify with which python) should represent the same python you'd like to use in neovim (let g:python3_host_prog = "...", or leave this variable to empty or "python3" which will pick up the python on $PATH).

rdipardo added a commit to rdipardo/vim-cpywrite that referenced this issue Nov 5, 2023
@smprather
Copy link

pip install 'pynvim @ git+https://github.com/neovim/pynvim'

Doesn't work offline though. When will the fix be released?

@slacksystem
Copy link

I'm sorry but I'm having trouble wiht this still. After launching neoivm with my virtualenv (called pyenv)

(pynvim) ~  > pip install 'pynvim @ git+https://github.com/neovim/pynvim'

pipi='pip install'
Collecting pynvim@ git+https://github.com/neovim/pynvim
  Cloning https://github.com/neovim/pynvim to /tmp/pip-install-n0z9krus/pynvim_b42a40d5d77c41389180500b9eb5e358
  Running command git clone --filter=blob:none --quiet https://github.com/neovim/pynvim /tmp/pip-install-n0z9krus/pynvim_b42a40d5d77c41389180500b9eb5e358
  Resolved https://github.com/neovim/pynvim to commit 169673714fd6d9f8bf53ed5ec55b9b01be5f560e
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: msgpack>=0.5.0 in ./.pyenv/versions/pynvim/lib/python3.12/site-packages (from pynvim@ git+https://github.com/neovim/pynvim) (1.0.7)
Requirement already satisfied: greenlet>=3.0 in ./.pyenv/versions/pynvim/lib/python3.12/site-packages (from pynvim@ git+https://github.com/neovim/pynvim) (3.0.1)
Building wheels for collected packages: pynvim
  Building wheel for pynvim (pyproject.toml) ... done
  Created wheel for pynvim: filename=pynvim-0.5.0.dev0-py2.py3-none-any.whl size=45152 sha256=184ea39a7bbec6ab0c64a8e9b22384a8b27d5478683045894a61f7177d780299
  Stored in directory: /tmp/pip-ephem-wheel-cache-5ia1gm3q/wheels/ed/e4/03/32c78f104e48c5c2f0353dcc1ef88cc58a4e8c3a21f41a3165
Successfully built pynvim
Installing collected packages: pynvim
  Attempting uninstall: pynvim
    Found existing installation: pynvim 0.5.0.dev0
    Uninstalling pynvim-0.5.0.dev0:
      Successfully uninstalled pynvim-0.5.0.dev0
Successfully installed pynvim-0.5.0.dev0                                                                                  /4.5s

Launching nvim (Lunarvim, if it matters) with environment active:

:echo g:python_host_prog
/home/<user>/.pyenv/version/pynvim/bin/python

Relevant section of :checkhealth provider:

Python 3 provider (optional) ~
- pyenv: Path: /home/slack/.pyenv/libexec/pyenv
- pyenv: Root: /home/slack/.pyenv
- WARNING No Python executable found that can `import neovim`. Using the first available executable for diagnostics.
- WARNING Could not load Python 3:
  /home/slack/.pyenv/shims/python3 is Python <string>:1: DeprecationWarning: 'pkgutil.get_loader' is deprecated and slated for removal in Python 3.14; use importlib.util.find_spec() instead
  3.12 and cannot provide Python 3.
  /usr/bin/python3.10 does not have the "neovim" module.
  python3.9 not found in search path or not executable.
  python3.8 not found in search path or not executable.
  python3.7 not found in search path or not executable.
  /home/slack/.pyenv/shims/python is Python <string>:1: DeprecationWarning: 'pkgutil.get_loader' is deprecated and slated for removal in Python 3.14; use importlib.util.find_spec() instead
  3.12 and cannot provide Python 3.
  - ADVICE:
    - See :help |provider-python| for more information.
    - You may disable this provider (and warning) by adding `let g:loaded_python3_provider = 0` to your init.vim
- Executable: Not found

Python virtualenv ~
- WARNING $VIRTUAL_ENV is set to: /home/slack/.pyenv/versions/3.12.0/envs/pynvim
  And its /bin directory contains: python, python3, python3-config, python3.12, python3.12-config
  But $PATH yields this python executable: /home/slack/.pyenv/versions/pynvim/bin/python
  And $PATH in subshells yields this python executable: /home/slack/.pyenv/versions/pynvim/bin/python
  And $PATH yields this python3 executable: /home/slack/.pyenv/versions/pynvim/bin/python3
  And $PATH in subshells yields this python3 executable: /home/slack/.pyenv/versions/pynvim/bin/python3
  And $PATH yields this python3-config executable: Usage: /home/slack/.pyenv/versions/pynvim/bin/python3-config --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir|--embed
  
  And $PATH in subshells yields this python3-config executable: Usage: /home/slack/.pyenv/versions/pynvim/bin/python3-config --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir|--embed
  
  And $PATH yields this python3.12 executable: /home/slack/.pyenv/versions/pynvim/bin/python3.12
  And $PATH in subshells yields this python3.12 executable: /home/slack/.pyenv/versions/pynvim/bin/python3.12
  And $PATH yields this python3.12-config executable: Usage: /home/slack/.pyenv/versions/pynvim/bin/python3.12-config --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir|--embed
  
  And $PATH in subshells yields this python3.12-config executable: Usage: /home/slack/.pyenv/versions/pynvim/bin/python3.12-config --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir|--embed
  
  So invoking Python may lead to unexpected results.
  - ADVICE:
    - $PATH ambiguities arise if the virtualenv is not properly activated prior to launching Nvim. Close Nvim, activate the virtualenv, check that invoking Python from the command line launches the correct one, then relaunch Nvim.
    - $PATH ambiguities in subshells typically are caused by your shell config overriding the $PATH previously set by the virtualenv. Either prevent them from doing so, or use this workaround: https://vi.stackexchange.com/a/34996

I'm not sure what I might have done wrong to have it working for everyone else and not for me, but does someone have an idea of how to fix this? If I can provide any more info that would be helpful please let me know.

@wookayin
Copy link
Member

wookayin commented Nov 25, 2023

@slacksystem you need to set g:python3_host_prog, not g:python_host_prog.

Also what's your neovim version? To support python 3.12, neovim 0.9.3 or higher is required. See neovim/neovim#25316

If neovim version is good, then in your case the python host (/home/slack/.pyenv/shims/python3) might have pynvim 0.4.3 installed. Verify your pynvim installation:

$ /home/slack/.pyenv/shims/python3 -c "import pynvim; print(pynvim.__version__)"
0.5.0.dev0

I guess the pip command points to the wrong python. Make sure which pip points the same python3 in the activated virtualenv.

$ /home/slack/.pyenv/shims/python3 -m pip install 'pynvim @ git+https://github.com/neovim/pynvim'

@eriteric

This comment was marked as duplicate.

@justinmk
Copy link
Member

justinmk commented Dec 4, 2023

Released 0.5: https://github.com/neovim/pynvim/releases/tag/0.5.0

@justinmk justinmk closed this as completed Dec 4, 2023
@jamessan jamessan unpinned this issue Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants