简体   繁体   English

如何在终端Visual Studio Code中运行Python3函数脚本

[英]How to run Python3 function script in terminal Visual Studio Code

so far I have been ok with debugging and running in a python debug terminal. 到目前为止,我可以调试并在python调试终端中运行。 Now that I'm being forced into functions, i have to input the arguments when launching the script, for example: 现在我被迫进入函数,在启动脚本时必须输入参数,例如:

./python.py BIRTHDAY AHMED

and have it spit out something along the lines of this: 并按照以下方式吐出一些东西:

have a happy BIRTHDAY enjoy the day AHMED

problem comes down to me not knowing how to setup a terminal for such use. 问题归结于我不知道如何设置用于这种用途的终端。 i have a bash terminal, however it wont recognize my python interpreter (#!/usr/bin/python3). 我有一个bash终端,但是它无法识别我的python解释器(#!/ usr / bin / python3)。 I added "terminal.integrated.shell.windows": "C:\\\\Program Files\\\\Git\\\\bin\\\\bash.exe" to my user settings to gain the bash terminal as well as installed Git. 我在用户设置中添加了"terminal.integrated.shell.windows": "C:\\\\Program Files\\\\Git\\\\bin\\\\bash.exe" ,以获得bash终端以及已安装的Git。

Any ideas on how i can get a work in terminal that i can input arguments and recieve an output would be most appreciated. 我对如何在终端中进行工作,可以输入自变量并获得输出的任何想法都将受到赞赏。 (running on windows 10) (在Windows 10上运行)

You are providing the path of Git Bash, which only provides enough bash-like functionality to use git. 您正在提供Git Bash的路径,该路径仅提供足够的类似于bash的功能来使用git。 That is why running .sh (Bash Scripts) or .py files doesn't work by default. 这就是为什么默认情况下无法运行.sh (Bash脚本)或.py文件的原因。

If you add python to your PATH environment variable, that will make it so running python.exe filename.py [ARGS] will work on the Integrated Terminal. 如果将python添加到PATH环境变量中,它将使其运行python.exe filename.py [ARGS]将在Integrated Terminal上运行。

Another solution is to install WSL if you are on Windows 10, which does provide full* bash functionality under a modified Ubuntu shell. 另一个解决方案是,如果您在Windows 10上,则安装WSL ,它在经过修改的Ubuntu外壳下确实提供了完整的bash功能。 Then just provide VSCode the path to the WSL bash.exe . 然后只需提供VSCode到WSL bash.exe的路径即可。 ( How to here ) 如何到这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从终端在 Visual Studio 代码中运行 Python 文件? - How to run a Python file in Visual Studio code from the terminal? 我想在 Visual Studio Code 中使用 Ctrl + Enter 通过集成终端运行 python 脚本 - I want to run a python script via integrated terminal using Ctrl + Enter in Visual Studio Code 如何从 Visual Studio Code 运行 ABAQUS python 脚本? - How to run ABAQUS python script from Visual Studio Code? 更改 Python:在 Visual Studio Code 的终端命令中运行 Python 文件 - Change Python:Run Python File in Terminal command in Visual Studio Code LeetCode Python3 function 注解在 Visual Studio Code 中不起作用 - LeetCode Python3 function annotations do not work in Visual Studio Code Visual Studio Code 终端在 Powershell 中继续运行 Python 脚本 - Visual Studio Code Terminal keeps running Python script in Powershell Visual Studio Code Python 扩展“在终端中运行文件”不起作用 - Visual Studio Code Python extension 'Run File in Terminal' not working Visual Studio 代码(在终端中运行 Python 文件不起作用) - visual studio code (run Python file in terminal does not work) 如何在 Visual Studio 中运行单行 python 代码并在终端中获取 output? - How to run a single line of python code in Visual Studio an get the output in Terminal? Visual Studio Code在同一终端中运行代码 - Visual Studio Code run code in the same terminal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM