Jupyter 中 sys.path[0] 的等价物(如何获取 notebook 文件的目录)
在 Jupyter 中,
jupyter_syspath_example.py
import sys
sys.path[0]不会返回 notebook 文件所在的目录,而是类似这样的内容
jupyter_syspath_output.txt
/usr/lib/python310.zip相反,使用
jupyter_notebook_dir.py
import os.path
os.path.dirname(os.path.realpath("__file__"))If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow