VSCode 中的 Python:每次都将工作目录设置为 python 文件的路径 [英] Python in VSCode: Set working directory to python file's path everytime

查看:44
本文介绍了VSCode 中的 Python:每次都将工作目录设置为 python 文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想从 Spyder 迁移到 VSCode,我遇到了无法访问数据集的问题,因为我的工作目录与数据集的路径不同.

So I want to migrate from Spyder to VSCode, and I come across this problem where I cannot access a dataset as my working directory is not the same as the dataset's path.

launch.json 不是自动生成的,因为我没有调试任何东西(我试过这个).

launch.json is not auto-generated for me as I'm not debugging anything (I tried this).

如何在 VSCode 中将工作目录设置为我想要运行的 Python 文件的目录?(如果这是不好的做法,你能告诉我一个易于使用的配置吗?)我想为 VSCode 的 IPython 终端进行设置.

How do I set the working directory to always be the dir of the Python file I want to run, in VSCode? (and if it's bad practice, could you show me a config that is easy to work with?) I'd like to set this up for VSCode's IPython terminal.

推荐答案

更新的解决方案:从 21/1/2021 开始工作

选项 1:

  1. 找到并打开用户设置文件:
    • Windows %APPDATA%\Code\User\settings.json
    • macOS $HOME/Library/Application Support/Code/User/settings.json
    • Linux $HOME/.config/Code/User/settings.json

选项 2:

  1. 打开设置编辑器:
    • 在 Windows/Linux 上 - 文件 >首选项设置
    • 在 macOS 上 - 代码 >首选项设置
    • 或使用键盘快捷键(Ctrl+,).
  • 扩展 >蟒蛇>终端:在文件目录中执行.
  • 或使用搜索栏并输入此设置 ID python.terminal.executeInFileDir.

这篇关于VSCode 中的 Python:每次都将工作目录设置为 python 文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆