python - 如何在VScode中设置jupyter的运行文件路径?

标签 python visual-studio-code jupyter

当我在VScode中使用jupyter扩展名并在jupyter中运行一行代码以使用相对路径保存文件时,我在另一个文件中找到了文件(iris_tree.dot)。就像我在另一个文件路径中调试/运行代码一样。如何设置Jupyter运行机的正确路径?

#%%
from sklearn.tree import export_graphviz
export_graphviz(
tree_clf,
out_file="iris_tree.dot",
feature_names=iris.feature_names[2:],
class_names=iris.target_names,
rounded=True,
filled=True
)

最佳答案

我是此扩展程序的开发人员之一。默认情况下,我们遵循工作目录的VSCode模式,而不是Jupyter模式。这意味着我们使用当前打开的工作区文件夹的根作为启动jupyter笔记本的当前工作目录。这可能是让您感到困惑的地方。

为了解决这个问题,您可以在笔记本代码中将cwd设置为redhatvicky,也可以在以下VSCode设置中更改默认的当前工作目录。

Python->数据科学->笔记本文件根

由于可以在每个工作空间中更改该设置,因此,仅在包含文件的工作空间中工作时,可以始终将其默认设置为特定位置。

关于python - 如何在VScode中设置jupyter的运行文件路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55491046/

相关文章:

python - 带有异常(exception)词列表的标题大小写

c++ - 从命名空间内的类调用函数?

jupyter-notebook - 将新代码导入 Jupyter Lab

jupyter qtconsole 无法连接到现有内核

python - Jupyter 不渲染 latex

python - 图上的 C++ 反向传播;异构载体?

python - lxml.etree 和 xml.etree.ElementTree 添加没有前缀的命名空间(ns0、ns1 等)

python - NoForeignKeysError : Could not determine join condition . ..没有链接这些表的外键

visual-studio-code - 如何将 VSCode 命令作为任务运行

visual-studio-code - 在 VSCode 中缩小空目录资源管理器?