ahw / vim-hooks

Easily hook shell scripts into Vim autocmd events.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problems with Python virtualenv

ahw opened this issue · comments

Trying to run a script that makes use of the AWS CLI. Installed the CLI as a Python module using virtualenv and things don't work correctly. Example script:

#!/bin/sh
# vimhook.bufferoutput
source ~/public/my-env/bin/activate

babel $1 > main.js

aws s3 cp main.js s3://example.bucket/

This is likely because I did a manual install of Python so things are in non-standard places on my filesystem. Specifically, in my ~/.zshrc I have the following lines:

export PATH=/Users/andrew/python/bin:$PATH
export PYTHONPATH=/Users/andrew/python/lib/python2.7
export WORKON_HOME=/Users/andrew/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/Users/andrew/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/Users/andrew/bin/virtualenv

My script above works if I add PYTHONPATH=/Users/andrew/python/lib/python2.7 before the invocation of aws.

#!/bin/sh
# vimhook.bufferoutput
source ~/public/my-env/bin/activate

babel $1 > main.js

PYTHONPATH=/Users/andrew/python/lib/python2.7
aws s3 cp main.js s3://example.bucket/

This is annoying, but I'm pretty sure this expected behavior from Vim. I am remembering reading something about how the shell environment you get when you run :! commands is not that same as the custom user shell environment you get when logging in.

Next step will be add something to the README troubleshooting section. Not sure if there's a "fix" other than adding these lines to each hook that relies on virtualenv and/or a custom PYTHONPATH. If a user really wants :! commands to run in the same environment they're used to then that's a personal decision they should make with their doctor.

Updated README.