I am trying to use a plugin with neovim that needs a special python library (unidecode). I added that python package to my python interpreter only to find out that the neovim derivation ships it’s own python interpreter.
I first tested this
$ nix-shell --pure -p neovim 'python3.withPackages(p: [p.unidecode])'
$ python -c "import unidecode" # exit code 0
$ nvim -u NONE --headless -c "py3 import unidecode" -cq
Error detected while processing function provider#python3#Call:
line 18:
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'unidecode'
and also checked the respective python search paths (same nix-shell)
$ python -c 'import sys; print(sys.path)'
['',
'/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python38.zip',
'/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8',
'/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8/lib-dynload',
'/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8/site-packages',
'/nix/store/ivsjq570lkr4g8gpgpbqzdw26ia6r76v-python3-3.8.5-env/lib/python3.8/site-packages']
$ nvim -u NONE --headless -c "py3 import sys;print(sys.path)" -cq
['/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python38.zip',
'/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8',
'/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8/lib-dynload',
'/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8/site-packages',
'/nix/store/qrbjgnc7kbh7c25ly8i400gbh31frjk0-python3-3.8.5-env/lib/python3.8/site-packages',
'_vim_path_']
As you might have guessed python3.withPackages(p: [p.unidecode])
did put
unidecode
in /nix/store/ivsjq570lkr4g8gpgpbqzdw26ia6r76v-python3-3.8.5-env/lib/python3.8/site-packages
.
For the record, the python interpreter is also different in neovim and outside (same nix-shell):
$ python -c 'import sys; print(sys.executable)'
/nix/store/ivsjq570lkr4g8gpgpbqzdw26ia6r76v-python3-3.8.5-env/bin/python3.8
$ nvim -u NONE --headless -c 'py3 import sys;print(sys.executable)' -cq
/nix/store/qrbjgnc7kbh7c25ly8i400gbh31frjk0-python3-3.8.5-env/bin/python3.8
I tested if I can set the vim variable python3_host_prog
to the outside python interpreter but that obviously does not work as this python version does not have the pynvim
library installed. I could add that library to its searchpath but than I would have to find the correct path to the outside python interpreter on each launch of neovim.
Is there a way that I can add a python package to the search path of the python interpreter used by neovim, from the nix side of things? The neovim derivation does not have a .withPackages
for python stuff but maybe I can access the one of its python dependency?
Or is there some other simple solution to get a specific python package to load inside neovim’s python interpreter?