我在bash中声明了几个变量(通过~/.bash_profile),它们在bash中工作,也在bash中启动的python中工作。在
示例:
export PUIBy="Dropbox/CUSP/1_1_PUI/PUI_Bycicle_Research/"
但是,当我启动Jupyter notebook时,os.environ
看不到它们,显示了一些默认的变量列表(PWD、SUDO\u USER、USERNAME、JPY_PARENT_PID、SSH_AUTH_SOCK、SUDO UID、GIT_PAGER等)
我的妹妹是Mac OS El船长,anaconda ipython 2.7
尝试
env
而不是export
例如:
env PUIBy="Dropbox/CUSP/1_1_PUI/PUI_Bycicle_Research/" jupyter notebook
来源:link
事实上这个问题和朱庇特无关。它与如何加载不同的.bash文件有关。在
引用here
因为您将变量放入.bash_profile中,所以它只在终端shell中可用,而在非交互式shell中不可用。在
Jupyter notebook是一个web应用程序,即使它运行在您的本地计算机上并且您可以从本地计算机访问它(大多数情况下)。每次打开笔记本电脑,它都会在自己的非交互式shell中启动内核。因此,如果希望环境变量在shell中可见,请将它们放入
.bashrc
文件中,而不是.bash_profile
另外,要查看设置了哪些变量,请使用Jupyter笔记本中的
!export
命令相关问题 更多 >
编程相关推荐