Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set PYTHONPATH in fish?

The following works in bash:

~$ echo $PYTHONPATH
<nothing>
~$ export PYTHONPATH=/path/to/test/folder
~$ echo $PYTHONPATH
/path/to/test/folder
~$ python -m test_script
hello world

But not in fish:

Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
~> echo $PYTHONPATH
<nothing>
~> set --universal PYTHONPATH /path/to/test/folder
~> echo $PYTHONPATH
/path/to/test/folder
~> python -m test_script
/usr/bin/python: No module named test_script

I've tried set, set --global and set --universal.

How can I set PYTHONPATH in fish? (If it matters, I'm running Ubuntu 14.04.)

like image 326
lofidevops Avatar asked Jun 19 '14 13:06

lofidevops


2 Answers

Setting the variable is not sufficient, you must export it too (as you do in bash). Exporting means that subprocesses (like the Python call) will get the value too.

From the fish documentation:

-x or --export causes the specified environment variable to be exported to child processes

So a direct equivalent to the bash directive would be:

~> set --export PYTHONPATH /path/to/test/folder

You could add --universal or other arguments, but here the value is temporary, which matches the original bash example.

(Found answer via a similar question.)

like image 52
lofidevops Avatar answered Sep 19 '22 00:09

lofidevops


If you want to make the change permanent then you can add the following line

set -xg PYTHONPATH /path/to/test/folder $PYTHONPATH

to the bottom of ~/.fish/config.fish

like image 42
Jakobovski Avatar answered Sep 18 '22 00:09

Jakobovski