使用 bash 脚本添加到 $PYTHONPATH
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38579398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding to $PYTHONPATH with bash script
提问by cmoses
I wrote a bash script to add to my $PYTHONPATH
. My .sh
file has the following:
我写了一个 bash 脚本来添加到我的$PYTHONPATH
. 我的.sh
文件有以下内容:
sudo echo export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module >> ~/.bashrc
What I want to be added to my .bashrc
is:
我想添加到我的.bashrc
是:
PYTHONPATH=$PYTHONPATH:/path/to/new/python/module
However I can only get it to add:
但是我只能让它添加:
PYTHONPATH=/all/other/python/modules/already/on/path:/path/to/new/python/module
I don't want the actual $PYTHONPATH
value to be added to my .bashrc
, just the variable name. Please help!
我不希望将实际$PYTHONPATH
值添加到 my 中.bashrc
,而只是将变量名添加到。请帮忙!
采纳答案by John1024
Use single-quotes:
使用单引号:
$ echo 'export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module' >> .bashrc
$ cat .bashrc
export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module
The shell does not perform variable expansion on single-quoted strings.
Shell 不会对单引号字符串执行变量扩展。
Note also that, if you are writing to ~/.bashrc
, you should not need sudo
. A user should own his own ~/.bashrc
. Further, as written, the sudo
command only operated on echo
. The redirection >~/.bashrc
is done with the user's level of permission. Since echo
has no need of and gets no benefit from sudo
, sudo
is a practically a no-op. [Hat tip: tripleee]
另请注意,如果您要写入 ,则~/.bashrc
不需要sudo
. 用户应该拥有自己的~/.bashrc
. 此外,如所写,该sudo
命令仅对 进行操作echo
。重定向>~/.bashrc
是在用户的权限级别下完成的。由于echo
不需要也不从中受益sudo
,sudo
因此实际上是无操作的。[帽子提示:三重奏]
回答by payam jome yazdian
try
尝试
echo 'export PYTHONPATH=/path/to/caff-dir/python'
Also, you may need to run following:
此外,您可能需要运行以下命令:
pip install -r requirement.txt