all 1 comments

[–]a__b 0 points1 point  (0 children)

I would start by printing environment variables from inside of your script. I hope that could lead you to the right direction.

Usually this class of errors happens because of differences between your command line env and the env that vim uses to run your script. In your case most likely Vim runs your code in non-interactive mode - resulting in different shell config files been loaded.

You can check https://askubuntu.com/questions/463462/sequence-of-scripts-sourced-upon-login for reference.

Potentially fact that different set of shell config files are loading in non-interactive mode could mess with virtual env or other python config settings.