sudo 如何保持 PATH?
- 问题:
sudo
后 PATH 后改变(action) fanglin@lab704-SYS-7048GR-TR:~$ python -V Python 3.6.5 :: Anaconda, Inc. (action) fanglin@lab704-SYS-7048GR-TR:~$ sudo python -V Python 2.7.12
- 解决方法:将
sudo command
改为sudo env "PATH=$PATH" command
即可保持 PATH,来源:stackoverflow.com: Why does sudo change the PATH?
source activate 如何自动更新环境变量
问题: 运行
source activate env_name
之后再运行python -V
仍然是旧环境中的 python-
解决办法:
Locate the directory for the conda environment in your terminal window by running in the terminal
echo $CONDA_PREFIX.
-
Enter that directory and create these subdirectories and files:
cd $CONDA_PREFIX mkdir -p ./etc/conda/activate.d mkdir -p ./etc/conda/deactivate.d touch ./etc/conda/activate.d/env_vars.sh touch ./etc/conda/deactivate.d/env_vars.sh
-
Edit
./etc/conda/activate.d/env_vars.sh
as follows:#!/bin/sh export MY_KEY='secret-key-value' export MY_FILE=/path/to/my/file/
-
Edit
./etc/conda/deactivate.d/env_vars.sh
as follows:#!/bin/sh unset MY_KEY unset MY_FILE
When you run conda activate analytics, the environment variables MY_KEY and MY_FILE are set to the values you wrote into the file. When you run conda deactivate, those variables are erased.
-
来源: