Yesterday I wrote a short python script in VS Code and ran it successfully. Today I open VS Code but find it I can't run any python script. There is no run button on the top bar. I right click in the empty space, there is no run python option also. How can I fix it?
The left sidebar should have a little bug icon (for "debug"). Once you click on that, your run button should appear in the top left.
Related
Im really quite new to coding and brand new to Python so apologies if this is a dumb question.
I'm writing basic scripts in VS Code and when I run them the result in the terminal is just..... ugly. Instead of just printing the result of my code, it prints details about my version of Windows, a little copyright notice, the full file path to my code... then eventually gets round to executing my actual code.
Is there any way for me to configure the terminal so that it just shows my code and not all the other bits? I've already seem about an extension called Code Runner, but this prints to the "Output" tab and doesn't allow any user input
If you are using PowerShell, you can add "args": ["-NoLogo"], like this to Hides the copyright banner at startup :
"terminal.integrated.defaultProfile.windows": "PowerShell",
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"path": ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"],
"args": ["-NoLogo"],
}
},
And you also can change the value of console in the launch.json file. But internalConsole does not accept the user input. And externalTerminal will prompt a cmd window out of the VSCode.
Maybe you can try Jupyter code cells:
https://code.visualstudio.com/docs/python/jupyter-support-py
Try jupyter on visual studio code interface
https://code.visualstudio.com/docs/datascience/jupyter-notebooks
You have to follow these steps:
install python extension for vs code.
python extension
2.After installing reopen vs code and you will see a play button at right-top corner.
play button
3.Click that button and run your code!
go to settings
search for terminal
find Code-runner : Run in Terminal and turn that off.
Installed PyCharm on the new windows10.
If i create a new project everything works ok - all buttons on the places.
But if i run ANY .py file associated with pycharm i see just the code and no Run or configure buttons. There is also no indexing\something bar at the bottom. I've waited for couple hours and nothing changed.
The same thing on new linux.
What am i doing wrong?
(i also can't rightclick the file cuz 'nothing here' appears)
as you can see - no buttons..?
SOLVED.
solution
1. Uninstall PyCharm 20.x.x
2. Install PyCharm 19.x.x
Seems you started PyCharm in the light edit mode (see https://blog.jetbrains.com/idea/2020/04/lightedit-mode/), try to run PyCharm first and then create project on top of your directory or just open this directory.
Pycharm associated all .py to edit, you will open the source code.
To run, try "right click" and search for "RUN" or click "CTRL+SHIFT+F10"
Here is a link to the jetbrain tutorial on how to open/hide a navigation bar.
Use the navigation bar
This is because when you install Pycharm and start with new scratch file, Pycharm doesn't know which file you want to run so you can see Run. To Run your script Right-Click in the space and then click on Run. After this you will get a Run button in the top-right of the corner.
Hope it helps!
I just installed Thonny and took a look at some beginner guides. I can easily run whole script by pressing "play" button (or pressing F5). However I could not figure out how to run only some particular lines in the script.
In Thonny there is a ‘de-bugger’ button at the top (or f6) and if you press that you run through your code one line at a time. It is extremely useful for when you are trying to find out where your code goes wrong. I hope you find this helpful :).
I have a python file named "python_file.py" and I want to run it with a command line such as "python python_file.py" by typing it in the terminal, and not in the python console. I succeed one time, but when I change my working directory, it no longer works.
When I tried, it displays something like "python isn't known as a intern program, a runnable program or a command file".
And I'm using Python 3.7.
Can someone help me ?
You need to create a run/debug configuration, as explained in the official help:
Click on the button left of the green arrow symbol (the green arrow might be greyed out, but that's fine):
Click on Edit Configurations.
Click on the + symbol
Click on Python.
On the right side, enter/activate the following:
Name (a string that describes your according project)
Single instance only (this is less complicated for you)
Click on the Configuration tab.
Select a type of target from the Script path/Module name
Enter the path to your Python script in the according box.
Select the Python interpreter (Python 3.x will be fine).
In the Execution section, select either Emulate terminal in output console or Run with Python console.
Apply the changes and close the dialog.
Click on the button left of the green arrow symbol to run your program from the internal command line.
I downloaded and installed Visual Studio along with Anaconda to get access to all of the packages that come pre installed with Anaconda. I am trying to figure out how to run code such that it runs in the interactive shell. Right now when I hit F5 an Anaconda 3 cmd line window comes up with the prompt "Press any key to continue..." comes up. My question is: how can I make it so that when I hit F5 my code is executed in the interactive Python shell much like it does on the basic IDLE that comes with Python.
This seems like a question that a simple Google Search could fix, but for some reason I cannot find the answer. I've done some google searching, and I watched the Visual Studio python official Microsoft series about it. One of the videos touched on using the interactive shell, but even in the video, when he clicked the Start (Run) button, the code ran in what looked like the command line.
I have used IDLE in the past, and now I think it is time to make the change to a bigger IDE. I love the code completion and templates of visual studio, and I can't wait to solve this (noob) question.
Thanks
I am struggling with this as well. There is a Visual Studio Shell command execute file in Python interactive which is bound to Shift+Alt+F5 by default.
This works: if the focus is in a code window then the current file is executed. If the focus is in the Solution Explorer window, the file selected as "Startup item" is executed. There seems to be a glitch however: Some import statements from the specific file which work fine on the standard Ctrl+F5 will fail on Shift+Alt+F5. I need to figure out why this is the case and will report here.
EDIT: Once in the interactive windows, change the working directory to the folder containing the project: os.chdir etc. Then import your-filename works flawlessly. So I assume that there is some problem with selecting the working directory while executing Shift+Alt+F5.
Add
import os
os.chdir(r"C:\My\script\\path\")
to the top of your script.
Then Shift+Alt+F5 works as expected.
I'm not sure if it's the best way to do that, but here is what I do to quickly run Python script in Interactive Shell in Visual Studio 2017:
Add #%% sequence at the beginning of *.py file
Press Ctrl+Enter having cursor active in text editor
Code from #%% to end of file (or another #%%) will appear on Interactive Window
#%% is basically beginning of the cell. Cell is a part of code you would want to run at once in Interactive Shell. Cell begins with #%% and ends with another #%% which initializes another cell.
For example: you have following code in Visual Studio:
#%% Cell 1
print("Hello world1")
print("Hello world2")
#%% Cell 2
print("Hello world3")
When you click/focus on third line and press Ctrl+Enter you will run second and third line in Interactive Window.
To make a same experience like in c# where you can use F5 to start debugging python in Visual studio 2017 , you need to
1) create a new visual studio project ( ctrl + shift + N)
2) Select python as project type
3) Now you can create new python file ( *.py) and start code python ( ctrl + N)
4) Now you can right click the py file that you just created and use "set as startup file" command
5) Hit F5 to start python IDE debug experience ( breakpoint , inspect value , data type etc) , see below screen shoot