How can I set PYTHONPATH in fish?

心已入冬 提交于 2019-12-06 03:36:06

问题


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.)


回答1:


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.)




回答2:


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



来源:https://stackoverflow.com/questions/24308310/how-can-i-set-pythonpath-in-fish

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!