[vim/vim] Vim embedded Python doesn't honor PYTHONDONTWRITEBYTECODE (#3494)

60 views
Skip to first unread message

DervishD

unread,
Sep 29, 2018, 2:52:53 AM9/29/18
to vim/vim, Subscribed

Hi there!

Vim 8.1.332 x64 under Windows 10, Python 3 with dynamic linking.

Looks like at least with this combination, Vim plugins containing Python code generate __pycache__ directories full of .pyc files. Not a life-or-death situation, but I have PYTHONDONTWRITEBYTECODE enabled in my system (as a system environment variable, my installed Python works) and I'd love Vim to honor this ;)

Looks like Vim is not providing the correct environment when loading the Python DLL, or maybe under Windows this is entirely impossible, or maybe Python doesn't even honor the environment variable when used through the DLL, but I thought that since Vim has been the first program showing the issue maybe reporting here is the proper way of starting.

Thanks a lot in advance. I'm including the output of the :version command just in case. Feel free to ask me for any other information you may need, and thanks!!!!


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub

Tony Mechelynck

unread,
Sep 29, 2018, 3:35:48 AM9/29/18
to vim/vim, Subscribed

Hm... I am on Linux, where it seems that shells loaded from Vim don't source the same startup scripts as when they are loaded from login.

Maybe you could just add to your vimrc the line

let $PYTHONDONTWRITEBYTECODE = "1"

or something similar? Maybe (or maybe not) bracketed by if has('python') || has('python3')?

Best regards,
Tony.

DervishD

unread,
Sep 29, 2018, 4:47:40 AM9/29/18
to vim/vim, Subscribed

Hi Tony! Long time no see!!!! I'm very happy to read you again, amiko mia!

Maybe you could just add to your vimrc the line

let $PYTHONDONTWRITEBYTECODE = "1"

or something similar? Maybe (or maybe not) bracketed by if has('python') || has('python3')?

Already tried this, to no avail. Looks like as soon as jedi-vim is loaded, the cache is recreated. No biggie, really, but I wondered why it happened. I'll try to investigate the issue more.

Thanks anyway!!!
Really, I'm happy you are still on the Vim trenches, helping :)

micbou

unread,
Sep 29, 2018, 5:44:15 AM9/29/18
to vim/vim, Subscribed

Looks like Python 3 in Vim does not honor the PYTHONDONTWRITEBYTECODE environment variable on Windows. Python 2 does not suffer from the issue. A workaround is to set sys.dont_write_bytecode to True in vimrc:

py3 sys.dont_write_bytecode = True

DervishD

unread,
Sep 29, 2018, 3:47:52 PM9/29/18
to vim/vim, Subscribed

I'll try that, @micbou , thanks for the suggestions. But the code should be like

py3 import sys; sys.dont_write_bytecode=True

right?

And it worked! I just tested it and it seems that Python 3 under Vim honors this setting. That's great, thanks a lot for the suggestion!

micbou

unread,
Sep 29, 2018, 3:54:16 PM9/29/18
to vim/vim, Subscribed

sys is already imported by Vim so the import statement is not needed (though it doesn't hurt to import it again).

DervishD

unread,
Sep 29, 2018, 3:58:11 PM9/29/18
to vim/vim, Subscribed

@micbou I didn't know sys was already imported by Vim, thanks a lot!!!

Obviously importing it again is not a big deal, but it's slower than not doing it, so I'll remove the import from my .vimrc. Thanks again 👍 :)

Christian Brabandt

unread,
Oct 2, 2018, 2:38:06 PM10/2/18
to vim/vim, Subscribed

Closed #3494.

Reply all
Reply to author
Forward
0 new messages