Home > Software engineering >  Running Python with VS Code - The basics
Running Python with VS Code - The basics

Time:10-04

Unfortunately I am but another noob who is frustrated by my lack of understanding what are likely very basic concepts... So here it goes! I simply want to understand the concept behind me running the windows python version command in the .py file, and it not working, versus the same command being run directly in the command prompt, and the command working. To illustrate:

enter image description here I write the command in the editor and run the script. The result is an error.

enter image description here I run the same command directly into the terminal within VS Code. It works. What concept am I missing here? I can print 'Hello World', but I cannot run the version command?

CodePudding user response:

You are mixing OS commands with Python.

To run anything with Python, you must follow and use its programming guidelines and APIs https://docs.python.org/3/

To print Python version write this in your script:

import platform
print(platform.python_version())

To print python version on windows cmd run:

  python --version

or you are using:

  py -3 version
  • Related