0

Today I was writing code in VIM and wanted to change the PYTHONPATH and so I ran:

:!echo $PYTHONPATH;export PYTHONPATH="/home/oli/git/published_libraries/computer_communication_framework";echo $PYTHONPATH
:/home/oli/git/whole_cell_modelling_suite:/home/oli/git/cluster_control:/home/oli/git/whole_cell_modelling_suite:/home/oli/git/cluster_control
/home/oli/git/published_libraries/computer_communication_framework

Press ENTER or type command to continue

as expected but checking the PYTHONPATH again shows that the change has not been remembered:

:!echo $PYTHONPATH
:/home/oli/git/whole_cell_modelling_suite:/home/oli/git/cluster_control:/home/oli/git/whole_cell_modelling_suite:/home/oli/git/cluster_control

Press ENTER or type command to continue

Can anyone tell me what is going on here and how I can set the PYTHONPATH from inside VIM.

2

Your change happened inside a subprocess you spawned from vim. It is not visible to the parent process.

You might be able to

:let $PYTHONPATH='whatever_you_want'

But it is probably a better idea to adjust the environment in the shell and launch vim

# export PYTHONPATH=...
# vim ...

As pointed out in comments, you can set environment variables only for a single process using env:

# env PYTHONPATH=... vim

Or with bash:

# PYTHONPATH=... vim
  • Single command version: # PYTHONPATH=... vim ... ... especially if you only want this modification for a vim session. – B Layer Jun 30 '19 at 2:01
  • @BLayer agreed, or even with env. – D. Ben Knoble Jun 30 '19 at 12:30
  • 1
    Actually, if you're not using Bash then you'd have to use env so it's good to mention it. In Bash, though, using X=Y mycmd ... starts just one process for the command while using env adds the avoidable overhead of starting a second process. – B Layer Jun 30 '19 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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