如何在 vscode 中为 Python 执行添加命令行选项? [英] How to add a command line option to Python execution in vscode?

查看:48
本文介绍了如何在 vscode 中为 Python 执行添加命令行选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,要在 VScode 中向 python 执行添加命令行选项(在我的情况下,我想要 -i 选项),我将更改变量python.terminal.launchArgs"

It was my understanding that to add a command line option (in my case I want the -i option) to the python execution in VScode, I was to alter the variable "python.terminal.launchArgs"

由于这奇怪地不起作用,我将描述我所采取的步骤,以便知识渊博的人可以发现我的错误.

As this is curiously not working, I am going to describe the steps I took, so that perhaps some more knowledgeable person can spot my mistake.

  1. 我转到文件 > 首选项 > 设置

  1. I went to file > preferences > settings

然后我搜索了python

then I searched for python

我第一次发现 settings.json 是在 Python > Analysis:Disabled 中.我点击了在settings.json中编辑",希望能打开配置文件

The first mention I found to settings.json was in Python > Analysis:Disabled. I clicked "Edit in settings.json", hoping to open the config file

我将配置文件设置如下:

I set the config file as follows:

{
"window.zoomLevel": 3,
"python.pythonPath": "/usr/bin/python3",
"python.terminal.launchArgs": ["-i"]
}

  • 我回到我的代码并按 F5 运行它.它在 vscode 自带的终端上运行.命令行如下

  • I went back to my code and pressed F5 to run it. It ran on the terminal that comes with vscode. The command line was as follows

    lucas@mongolia:~/aulas_ed$ cd /home/lucas/aulas_ed ; env "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" /usr/bin/python3 /home/lucas/.vscode/extensions/ms-python.python-2018.12.1/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 34661 /home/lucas/aulas_ed/teste.py
    

  • 如您所见,这不包括 "-i".

    我尝试在同一窗口中更改 settings.json 中的其他变量.文本大小有效(文本大小立即更改)并且 python 路径变量有效(如果我输入一个无意义的路径,F5 停止工作并且 VScode 开始抱怨未定义的路径——只是说设置文件似乎可以正常工作其他结束.

    I tried altering other variables in settings.json, in the same window. The text size works (text size changes immediately) and the python path variable works (if I type a nonsensical path, F5 stops working and VScode starts complaing about an undefined path -- just to say that the settings file seems to work properly for other ends.

    推荐答案

    找到了方法...但肯定不是这样...

    Found a way... But for sure it's not THE way...

    .vscode/settings.json

    .vscode/settings.json

    {
        "python.terminal.launchArgs": [ 
            "${workspaceFolder}/main.py",
            "--port 8010"
        ]
    }
    

    pythonfile (main.py)

    pythonfile (main.py)

    import sys
    port = int(sys.argv[-2].split(' ')[-1]) if int(sys.argv[-2].split(' ')[-1]) else 8001
    
    # >>>  * Running on http://10.100.100.75:8010/ (Press CTRL+C to quit)
    

    这篇关于如何在 vscode 中为 Python 执行添加命令行选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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