When I run python code in VSC I get this nonsense that I dont need, Is there a way to remove it? The PS C:\Users.. thing
This information in the VS Code terminal is useful information. When we click the run button, it executes the run command in "Terminal", showing us the path of the python used and the path of the executed file, which avoids the confusion of multiple versions of python.
If you want to omit the displayed paths, you could click F5 to debug the file:
(Please use "console": "internalConsole", in launch.json.)
Or use the VS Code extension such as "Code Runner".
Have you tried adding python to system path?
Are you trying to run code like this?
python main.py
This link has the process for adding python to system variable.
https://datatofish.com/add-python-to-windows-path/
Related
I'm using VS Code for a Python project using a virtualenv. I switched my deafult terminal from powershell to cmd as VS Code was not happy executing powershell scripts.
Now when I open a terminal in my project it opens cmd (as desired), but automatically tries tor run .../Scripts/Activate.ps1, which it doesn't like. I want it to run .../Scripts/Activate.bat as we are in cmd. Runnning it manually for now, but would be nice if I didn't have to.
No doubt there is a setting somewhere to change this, but I cannot find it. Any ideas?
This is a problem related to the Python extension, it should be fixed in the last update.
You can get some information from here.
Whenever I try to run my python code or even the simplest hellow command in VS Code's termilnal, it is just showing this:
C"/users/admin/document/my python file
Why does it happen?
Oh, this is more like an VS-Code question. But anyways: I believe you have to use a command to run the file, just like this:
py <file-path-here>
Example:
py example.py
Also, maybe try installing the Python extension in VSCode.
And make sure you have Python installed correctly (check the button "add Python to path" in the first page of the Python installation setup).
If all of this does not work, make sure to select the correct Python version in VSCode by doing this:
Go to top menu, click view, command pallete, type Python Select Interpreter and choose the correct version.
Also, check if the file ends with .py so VSCode knows that you are working with a Python file.
Since you're new here: you can support me a lot by upvoting this answer or marking this as an answer. <3 Thanls
I would like that iPython run automatically when I launch VSC instead of typing ipython and press enter in the terminal. The answer here How to set ipython/jupyter as the default python terminal for vscode? doesn't work as it is for windows but it shouldn't be really different. Also, is there something similar to the 'Execute' button in Spyder instead of typing %run filename ? Thanks !
I presume you mean you want to run the "Python Interactive Window" and not just an iPython console on startup
There is currently no way to run it on startup. At least no way without writing another extension that would run a command when opening a workspace. It would be simple for us to add one though. Probably a workspace setting. Can you log an issue here:
https://github.com/Microsoft/vscode-python/issues/new
For you second question, 'Execute' in spyder, we have 'Run Current File in Python Interactive Window'. This works on any python file. You can get to it through the context menu on a file or through the command palette.
Sadly the nice workflow of spyder is not provided by any official extension at the moment (as far as I know).
But you can implement the basics easily on your own by writing an extension. Even with no experience in TypeScript you can quickly build an extension which starts an IPython console as soon as you open a python file. I also managed to execute a startup script which implements the runfile method. VS Code also allows keybindings for your functions, so that you can almost work like you can with spyder.
Spyder modified the IPython terminal quite a bit though, so it won't feel exactly the same. But after all, everything there is open source so you could implement it yourself, which is what I'm trying to do in my free time.
I am teaching a class that uses VScode.
I am used to teaching using IDLE, and it is very nice for the students to be able to call their defined functions and run snippets of code in a python terminal, for debugging purposes.
In VScode, they I have been unable to do the same in a satisfactory way.
Option1: I can select all code, right click and run selection/line on terminal. This works for small snippets, but I cannot do it for the whole file (even after selecting the whole file with ctrl-A). On linux, this works, but on windows, it does not, unfortunately (and my students use windows)
Option2: I can use the debug console. This requires adding a breakpoint in one of the last lines of the file, and does not offer tab completion. It works, but is less convenient than IDLE.
Option 3: I can also add the commands to run to the bottom of the file (which is a least preferred alternative, given that is forgoes the interativity of the read-print-eval loop).
Is there any better solution? Installing a VScode extension would not be a problem.
Visual Code is just a text editor like your traditional notepad. to run and debug any kind program you need to install the particular extension for the programming language.
In your case you are using python so you need to install the extension of it. the best one is the "Python" which is developed by microsoft itself. go to your extensions manager and install this extension. right click and click "run python file in terminal" and you are all set.
this will run exactly as they run from the idle(which is default IDE provided by python itself) you can enter the arguments from the console itself. according to me this is the best way to run and debug python programs in VScode.
another way is that VScode shows which python version is installed on your computer on the left bottom side, click on it and the programs will use this interpreter.
out of all the ways listed here and many others, the best method is to run the program in the terminal which is the recommend by python itself and many other programmers.
this method is very simple. what you have to do is open up your command prompt and type the path where python.exe is installed and the type the path of the your program as the argument and press enter. you are done !
ex : C:\Python27\python.exe C:\Users\Username\Desktop\my_python_script.py
You can also pass your arguments of your program in the command prompt itself.
if you do not want to type all this and then just use the solution mentioned above.
hope that your query is solved.
regards
In visual studion code, after installing python, I added a debug configuration provide by visual studio code (called 'current configuration') that lets me run python. I'd like the output of my executed python code to be clean and NOT show this long path every time (in blue text). How can I do this? See image attached.
Make sure that your launch.json configuration console setting is set to "internalConsole"
Unfortunately there is no way to avoid that output as it's required to launch the debugger.
Open your launch.json file and change the value of console to 'none'.