I just pressed that triangle to run the code. I want that button to work because I want to use the debug mode from that button. When I click it, it tries to run three times and it somehow got into anaconda. I checked Python default interpreter path in preferences>settings and it is set to C:\Users\ucanc\AppData\Local\Programs\Python\Python39\python.exe, not the anaconda one. I am pretty new to this and I do not know what is going on.
edit: It seems like it is running as WSL termial that is why it has name#LAPTOP-xxxx:/mnt/c/ in the front.
Related
I can run a python script by pressing the run python file button:
but unable to run the same when pressing the F5 key or run from the dropdown menu.
I can also run in the interactive window fine:
And likewise i can run a notebook fine.
other checks:
I can verify that it doesn't debug by adding a breakpoint and running.
Would there be a key-binding that is missing perhaps ?
What is causing this and how can one fix the issue please ?
It turns out that the error is a bug in the Python extension.
If you go to the Extensions tab, select the Python extension, then click on the little arrow next to Uninstall > Install Another Version... and install 2021.12.1559732655 the debugger should work again.
Here is the link to the fix: https://learn.microsoft.com/en-us/answers/questions/724858/vscode-debugger-not-working-for-python.html
In the meantime disable automatic updates to make it stick until they fix that.
To do this going to settings, typing python.terminal.activateEnvironment into the search bar and deactivating the checkbox.
Normally in left corner of IPython console is button to "run script/stop the current command" but in my program it stuck in "stop" form. I can run scripts with F5 or from the toolbar. While the script is running, the script button in console works, and the script can be stopped with it, but the button doesn't change into "run script" afterwards.
I have absolutely no idea what is responsible. I tried to restart Spyder, restart computer, even reinstall Spyder and reset it to factory defaults. Nothing helped.
This is by design in the IDE. Since you could have multiple files running within the same IDE session, the terminal wouldn't know which one you wanted to run at any given point. That's why the run button/shortcut are specific to one file or selection and are on the top bar. The console can only stop the execution of the currently running statement.
If you want to repeat the statement/file you just ran, type %rerun or %rerun N where N is line number of the command you want to rerun. Other options are here: https://ipython.readthedocs.io/en/stable/interactive/magics.html
In R Studio, Matlab, and in some Python IDEs (like Thonny) you can see a list of the variables in your environment, together with some summary information like values, type etc.
Is there a way to do this in VSCode without going into debugging mode?
Seems like the closest as it gets to the RStudio Environment window is by installing Jupyter. Then you can type #%% in your .py file and a small "Run Cell" button will appear. Running the cell will open the "Python Interactive Window". There you can click the "See Variables Active" button to open up the Variable Window and see your variables... still a bit painful in comparison with RStudio, this should be integrated in VScode's IDE.
See steps here:
https://code.visualstudio.com/docs/python/jupyter-support-py#_variable-explorer-and-data-viewer
VS Code has an IPython mode with a dropdown box called Variables that basically does exactly this.
To enter IPython mode all you need to do is highlight a piece of code and hit Shift+Enter
The first time you do it there might be a bit of setting up to do but it was pretty easy to get it working on my Mac. Not sure what it's like on Windows/Linux though
Note: When I use VS Code I open it from the terminal (simply enter the command 'code') after I've activated my conda environment. That way the IPython interpreter uses my preferred conda environment when it launches.
I initially started learning Python in Spyder, but decided to switch to PyCharm recently, hence I'm learning PyCharm with a Spyder-like mentality.
I'm interested in running a file in the Python console, but every time I rerun this file, it will run under a newly opened Python console. This can become annoying after a while, as there will be multiple Python consoles open which basically all do the same thing but with slight variations.
I would prefer to just have one single Python console and run an entire file within that single console. Would anybody know how to change this? Perhaps the mindset I'm using isn't very PyCharmic?
There is a specific option in PyCharm 2018.2+: Settings | Build, Execution, Deployment | Console | Use existing console for "Run with Python console".
Run with Python console is an option you have enabled in the Run Configuration. Disable it if you don't need a Python console after a script execution:
Hi: If you are looking for re running the code again in the same python console everytime then you have to check the respective box in the Project settings as shown in image below.
To allow only one instance to run, go to "Run" in the top bar, then "Edit Configurations...". Finally, check "Single instance only" at the right side. This will run only one instance and restart every time you run.
One console is one instance of Python being run on your system. If you want to run different variations of code within the same Python kernel, you can highlight the code you want to run and then choose the run option (Alt+Shift+F10 default).
You have an option to Rerun the program.
Simply open and navigate to currently running app with:
Alt+4 (Windows)
⌘+4 (Mac)
And then rerun it with:
Ctrl+R (Windows)
⌘+R (Mac)
Another option:
Show actions popup:
Ctrl+Shift+A (Windows)
⇧+⌘+A (Mac)
And type Rerun ..., IDE then hint you with desired action, and call it.
I think that what you are looking for is the last option in this window; check it and it should work.
Settings -> Build, Execution, Deployment -> Console
I created an executeable of my Python script. Everything works just fine on my first computer but when I try to run this very same executeable in another computer, it wont work. When I try to run my executeable I see that computer tries to open it, because command prompt window appears but nothing else happens, prompt window will disappear. Problem can't be in computer, because both my computers are 32 bit Windows machines and I have done similar things before but this kind of error I see first time.
I don't want to post my code at first, because it is more than 500 lines long. But I will give some more specifications about my problem.
This program I create is actually advanced version of application i made earlier. And earlier version worked fine in both of my computers. This advanced version, I am working on now, is developed into many standalone Python scripts unlike first one which was only one script. Could this be the source of my problem? Should I do something different when running setup.py now when I have many scripts?
And then there is third version of my application. Executeable of it runs fine on computer where I created it, but in my second computer it wont run either. But this time I get error too. When I run this program in my second computer the opening screen of aplication appears, there are some buttons which are meant to open other scripts, when they are clicked on. But when I click them I get following error: The system cannot find the path specified.
If someone is willing to look into my long code, then I am willing to share it. But again I dont want to post it here.
I am using Python 2.7 and windows 7 in my first computer and windows XP on my second computer.
I would be very grateful if someone points me right direction which helps me to solve my problem.