1

I found a lot of questions about it, some problem was about 32 or 64 bit, other was about python support compiled in vim, etc.
None was my case.

Preamble: Software installed

I installed Python on Windows10. The official installer suggested me (as default choice) the installation for current user; it is then installed in: c:\Users\USERNAME\AppData\Local\Programs\Python\Python310\

I installed Vim for Windows from the win-32 installer site and I installed 64 bit version with Python support. If I type :version, I see +python/dyn and +python3/dyn.

On "Python side", if I check from Windows terminal:

C:\>python
Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)] on win32

Then there's compiled-in support and there's architecture concordance, and all works.

Now if I launch gvim from start menu, or from the "right-click" menu it works fine. I mean if I execute, in command mode,

:py3 import sys;print(sys.version) 

Vim says:

3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)]

Then all plugins that requires Python (for example Voom) works fine. Even when you start Vim from Explorer or from the Total Commander toolbar, either by clicking on the gvim.exe button or by dragging a file onto the button in the toolbar, everything works as expected. Total Commander button setup

(Total Commander button setup)

Problem

Then there's my problem. I use Joplin to take notes and I can set up an external editor. I use gvim, obviously. :-)

Joplin external editor setup

But when the gvim starts from it the python library isn't loaded, i.e. if I execute:

:py3 import sys;print(sys.version) 

vim says:

E370: Non riesco a caricare la libreria : Parametro non corretto.
E263: Spiacente, comando non disponibile, non riesco a caricare libreria programmi Python.
Premi INVIO o un comando per proseguire

I tried to inform vim about the python path and dll, by this commands:

:set pythonthreedll="c:\Users\USERNAME\AppData\Local\Programs\Python\Python310\python310.dll
:set pythonthreehome="c:\Users\USERNAME\AppData\Local\Programs\Python\Python310\
:let $PYTHONPATH = "c:\Users\USERNAME\AppData\Local\Programs\Python\Python310"

None of this helped me. 70 / 5.000 Risultati della traduzione I don't know if the dlls are loaded at run-time or when gvim starts.

The only solution I found was to copy python310.dll into the vim folder. Then it works.

Why?

How to solve it without copying the dll?

Thanks


[UPDATE]
After the Vivian's reply I double checked all about the PATH.
The problem is actually in the PATH environment variable, but but I can't figure out what's going on.

The installer told me it added python to the path.

python

This is consistent with the fact that I can launch python from the command prompt. Confirmation also comes from checking the PATH variable.

Check PATH from commandline

The control panel also sees the variables correctly.

Control Panel Environment Variables

Unfortunately it’s only Vim that doesn’t notice that Python is in the PATH.
enter image description here

But if I do, in command mode:

:let $PATH .= ';c:\Users\PAOLINIA\AppData\Local\Programs\Python\Python310' 

then Gvim instance loads the Python dlls correctly.

4
  • 1
    The environment variables are copied from mother process to child process. If you start gVim from a custom explorer (e.g. Total Commander) that has been started before your installation of Python it could be that the custom explorer is ignoring the new value of the path environment variable. To verify that run the the Vim command :echo $path. If Python 10 is not part of it I recommend to restart the custom explorer or to start gVim from Windows explorer (or reboot ;-) ) Sep 16, 2022 at 14:30
  • 1
    You've caught the problem! While Total Commander probably monitors environment variables in some way, Joplin had not been restarted after installing Python. I closed and reopened it and now everything works perfectly!
    – Antonio
    Sep 16, 2022 at 14:42
  • Thanks for your feedback. Sep 16, 2022 at 14:46
  • 1
    No, I must thank you for your help! You pointed me in the right direction. Giving feedback is the least I could do.
    – Antonio
    Sep 16, 2022 at 14:50

2 Answers 2

1

Vim needs to find the python310.dll. Like all executable it will search in a number of folders (the list and the order depends on the version of Windows).

But the list always includes:

  • The directory of the executable (the solution you have selected)
  • The working directory
  • The directories in the path environment variable (what I would suggest)

I recommend that you add %LocalAppData%\Programs\Python\Python310 (i.e.: C:\Users\YourUserName\AppData\Local\Programs\Python\Python310) to your path environment variable.

Remarks:

The environment variables are copied from the mother process to child processes. If you start gVim from a custom explorer (e.g. Joplin, TotalCommander, FreeCommander) that has been started before your installation of Python it could be that the custom explorer is ignoring the new value of the path environment variable.

To make sure gVim is aware of the new value of the path environment variable: restart the custom explorer (Joplin, TotalCommander, FreeCommander) and restart gVim.

You can verify that gVim is aware of the new value of the path environment variable by running the following Vim command:

:echo $path
0

I found another way to solve this.
Contrary to what I said above (in the Original Question), adding the two variables pythonthreehome and pythonthreedll works, but the trick is in how the paths are written.

If you write the path in the windows way, it doesn't works, but if you use slash instead of backslash it works!

Then add this to the _vimrc:

set pythonthreehome=c:/Users/USERNAME/Documents/bin/python-3.11.3-embed-win32/
set pythonthreedll=c:/Users/USERNAME/Documents/bin/python-3.11.3-embed-win32/python311.dll

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.