I tried to experiment with what the nvim documentation (connecting chapter in api.txt) says. The experiment is to use python repl to execute an instruction to nvim listening for socket communication.

What I did

I opened TMUX on the terminal and split the pane into left and right. In the left pane, execute nvim --listen In the right pane, I opened python repl and had it run the following commands in order.

import pynvim
nvim = pynvim.attach('socket', path='')
nvim.command('echo "Hello"')

When I run this code, I get an error in executing the second line of code. What could be the cause of this?


I ran the lsof -i :6666 command to confirm that the neovim process is occupying the port.

The following is the error output.


Python Repl Output Error

import pynvim
nvim = pynvim.attach('socket',path='')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/user1/.asdf/installs/python/3.11.1/lib/python3.11/site-packages/pynvim/__init__.py", line 111, in attach
    socket_session(path) if session_type == 'socket' else
  File "/Users/user1/.asdf/installs/python/3.11.1/lib/python3.11/site-packages/pynvim/msgpack_rpc/__init__.py", line 35, in socket_session
    return session('socket', path)
  File "/Users/user1/.asdf/installs/python/3.11.1/lib/python3.11/site-packages/pynvim/msgpack_rpc/__init__.py", line 19, in session
    loop = EventLoop(transport_type, *args, **kwargs)
  File "/Users/user1/.asdf/installs/python/3.11.1/lib/python3.11/site-packages/pynvim/msgpack_rpc/event_loop/base.py", line 93, in __init__
    raise e
  File "/Users/user1/.asdf/installs/python/3.11.1/lib/python3.11/site-packages/pynvim/msgpack_rpc/event_loop/base.py", line 90, in __init__
    getattr(self, '_connect_{}'.format(transport_type))(*args)
  File "/Users/user1/.asdf/installs/python/3.11.1/lib/python3.11/site-packages/pynvim/msgpack_rpc/event_loop/asyncio.py", line 96, in _connect_socket
  File "/Users/user1/.asdf/installs/python/3.11.1/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
  File "/Users/user1/.asdf/installs/python/3.11.1/lib/python3.11/asyncio/unix_events.py", line 259, in create_unix_connection
    await self.sock_connect(sock, path)
  File "/Users/user1/.asdf/installs/python/3.11.1/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect
    return await fut
  File "/Users/user1/.asdf/installs/python/3.11.1/lib/python3.11/asyncio/selector_events.py", line 642, in _sock_connect
FileNotFoundError: [Errno 2] No such file or directory
  • Welcome to vi SE. Please edit and tell us which error you receive. Makes it easier for people to help you. Thank you.
    – Friedrich
    Jun 8 at 16:42
  • Thank you for your replay. Friedrich! I'll add error outpu.
    – ksk srs
    Jun 8 at 16:53


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.