我开始使用vscode for Python.我有一个简单的测试程序.我想在调试下运行它,我需要设置运行的工作目录.
我是怎么做的?
当我在 VScode 中使用 jupyter 扩展并在 jupyter 中运行一行代码以使用相对路径保存文件时?我在另一个文件中找到了文件(iris_tree.dot)。就像我在另一个文件路径中调试/运行代码一样。如何设置 jupyter runner 的正确路径?
#%%
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
)
Run Code Online (Sandbox Code Playgroud) 所以我想从 Spyder 迁移到 VSCode,我遇到了这个问题,我无法访问数据集,因为我的工作目录与数据集的路径不同。
launch.json不是为我自动生成的,因为我没有调试任何东西(我试过这个)。
如何在 VSCode 中将工作目录设置为始终是我要运行的 Python 文件的目录?(如果这是不好的做法,你能告诉我一个易于使用的配置吗?)我想为 VSCode 的 IPython 终端设置它。
I am trying to run python code using the jupyter extension in vscode here
I have a workspace open at this location /Users/user/Documents/ When I try and run the following code in a file called test.py in a child directory, the current working directory is set at the workspace level rather than the file. Is it possible to change a setting to use the cwd of the file, rather than the workspace? I cannot find one in settings.json and the …