无法在jupyter笔记本中导入模块;错误的系统路径 [英] Cannot import modules in jupyter notebook; wrong sys.path
问题描述
我在iPython/Jupyter笔记本中导入模块时遇到问题.问题从根本上在于sys.path指向的位置.
I am having a problem importing modules in my iPython/Jupyter notebook. The problem fundamentally lies in where the sys.path is pointing to.
在iPython/Jupyter笔记本中,sys.executable
返回:
From the iPython/Jupyter notebook, sys.executable
returns:
'/usr/bin/python'
但是,它从命令行返回:
However, from the command line, it returns:
'//anaconda/bin/python'
我尝试卸载并重新安装anacondas,但问题仍然存在.
I have tried un-installing and re-installing anacondas, but the problem still remains.
我还尝试在bash_profile中增加$ PYTHONPATH使其包含//anaconda/bin/python,但这无法解决.
I have also tried augmenting $PYTHONPATH in my bash_profile to include //anaconda/bin/python, but this doesn't resolve it.
反正有没有永久地改变jupyter笔记本中的sys.path的地方,而不仅仅是使用sys.path.append(...)?
Is there anyway to change the sys.path in my jupyter notebook permanently, without simply using sys.path.append(...)?
推荐答案
-
打开一个新的终端窗口,看看是否有帮助.如果不是,请继续执行2.
Open a new terminal window and see if this helps. If not, proceed with 2.
从终端启动标准的Python会话,然后输入以下内容:
Start a standard Python session from the terminal and type this:
>>> import sys
>>> sys.executable
在笔记本中执行相同操作:
Do the same in the notebook:
In [1]: import sys
sys.executable
比较结果.希望这可以为您提供线索.
Compare the results. Hopefully, this gives you a clue what is going on.
这篇关于无法在jupyter笔记本中导入模块;错误的系统路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!