I can't run my code in Visual Studio Code. When I type $ code hello.py then this happens:
Enter image description here
In the image you have used code hello.py. You should instead use python hello.py. You can run on the command prompt only if you had "Add Python to Path" checked while installing the Python software.
If you are on a Mac
In Mac, Python 2.7 is automatically installed. If you want to use Python 3 then you have to manually install from the Python official website and use python3 hello.py to use Python 3.
Always remember that a Python file will be run by using this command: python yourfile_name.py.
In your image you are trying to run your Python file with this command: code hello.py
Instead of using code hello.py, try to change it with python hello.py.
Related
I am veryy new in coding and wanted to get into it. So I downloaded VS code. But I tried to run a very simple python command and it does not let me. See the picture below.
Visual Studio code is not an IDE, it is a code editor, which means you cannot run nor debug code naturally, for that you would need to run it on the windows terminal, or install extra packages and dependencies. If youre new and just want to learn Python, i suggest starting with a python IDE like the standard one provided or something more advanced like Pycharm, and if you want to program on VsCode and in multiple languages, search some tutorials about how to compile and run code on the windows terminal.
Provide more details about how you installed python from Microsoft Store, from anaconda or via its official page https://www.python.org/downloads/. Try running
python --version
or
python3 --version
If so you can run a python file from terminal. Assuming my file is called test.py
python test.py
i want to configure python3.10 on kubuntu but only can run in terminal, when visual studio code try python can't run python3 from file .py, just using terminal, i want executing python from terminal of visual studio code using python3 fileName.py, what should i do?
The label on the right is a small circle, indicating that you have not saved the file.
You can "ctrl+s" to save it, or the file read by the terminal was blank.
I've been using VS Code from a week and I want to use VS Code built-in Python snippets but it is not working for me. I've tried JS snippets and it is working fine in VS Code but Python snippets are not working.
Image links:
JS Snippet:
PY snippet:
Found the answer:
It seems they decided to remove code snippets from the python extension in the last update:
changelog in vscode
They may be added back in the future but for now i would suggest just using the python snippets extention: https://marketplace.visualstudio.com/items?itemName=frhtylcn.pythonsnippets
Install the Python extension for VS Code from the Visual Studio Marketplace(Link)
To verify that you've installed Python successfully on your machine, run one of the following commands (depending on your operating system):
Linux/macOS: open a Terminal Window and type the following command:
python3 --version
Windows: open a command prompt and run the following command:
py -3 --version
From within VS Code, select a Python 3 interpreter by opening the Command Palette (Ctrl+Shift+P), start typing the Python: Select Interpreter command to search, then select the command. You can also use the Select Python Environment option on the Status Bar if available (it may already show a selected interpreter, too)
Refer to this article for more information
I use Anaconda3 installed python on Windows10.
When I run python --version in git-bash, it works.
$ python --version
Python 3.7.3
$ which python
/d/Programs/Anaconda3/python
But when I run python, it output nothing and pending there
$ python
A image may be more clear here.
I can input anything, when press, but nothing happens, just a new line.
$ python
print(1)
Note My issue is different from Python not working in command prompt? which is cannot find the python path.
Try all your commands with $ python3 ... maybe you dont have installed the python 2 version which gets normaly called by $ python ..
I think here has something to do with git-bash GUI. I cannot run it in git-bash, but I can run it in windows cmd.
How can I use Python 3.7 in my command line?
My Python interpreter is active on Python 3.7 and my python.pythonPath is /usr/local/bin/python3, though my Python version in my command line is 2.7. I've already installed Python 3.7 on my mac.
lorenzs-mbp:Python lorenzkort$ python --version
Python 2.7.13
If you open tab "Terminal" in your VSCode then your default python is called (in your case python2).
If you want to use python3.7 try to use following command:
python3 --version
Or just type the full path to the python folder:
/usr/local/bin/python3 yourscript.py
In case you want to change default python interpreter, then follow this accepted anwser: How to set Python's default version to 3.x on OS X?
You should use python3 instead of python for running any commands you want to run then it will use the python3 version interpreter.
Also if you are using pip then use pip3.
Hope this helps.
This gives you a complete guide in setting up Visual Studio code for python
Getting Started with Python in VS Code