I am trying to change the Executing Terminal for python in VSCode from Bash to CMD. I already tried changing the default terminal by following this, but no luck.
Detailed Explanation:
In Vscode , when i hit the run button for executing python. I see that , the execution automatically chooses the Bash terminal , but i would need the execution to happen in CMD.
You can check it in settings.
It's the same as adding the following line into your setting.json:
"terminal.integrated.defaultProfile.windows": "Command Prompt",
If it still doesn't work, try reinstalling vscode
If you just changed your default terminal, try restarting your computer, that worked for me, it wasn't taken into account before I did.
Related
Normally when I would click on "Run" button in VSCode for a Python script it would activate the currently selected virtual environment and simply call python <script_name.py> in the terminal and it all worked fine.
Now all of a sudden every time I try to run a script what is does is instead call a subprocess via conda like so:
conda run -n <environment_name> --no-capture-output --live-stream python <script_name.py>
And this new version is causing some issue because for whatever reason conda refuses to recognise some of the packages as having been installed. The code still works fine when I manually type the run command in the terminal but I want the old behaviour to be back.
Anyone knows how to fix this?
Input: Ctrl + Shift + P .
Enter: Terminal: select default profile .
Change the default to CMD .
Maybe this can help you.
I always used the "Run python file in terminal"-button in Vscode, but some recent update seems to have broken it for me. My default terminal is cmd, but when I use the button, it now uses powershell and does not activate the conda environment, which prevents my code from running.
When I open up a new terminal manually, it rightfully uses cmd, activates the env and python <path> works again.
This is the output after pressing the run-button:
Does anyone know how to set the button to use cmd?
This is an issue of Python Extension. And it should be fixed tomorrow with the new release. You can refer to here for more details.
And have you add "python.terminal.activateEnvironment": true, in the settings.json file? Because it's weird, as the cmd activates the environment while the Powershell does not.
I've been struggling for a long time now to get this running but I just couldn't do it. I am runnning PyCharm Professional on Win10 and I want to code and run Shell scripts, but I cannot get it to work. There is this Shell Plugin from Pycharm but there is just not enough documention for me to understand how it has to be setup.
How do I have to setup PyCharm in order to Run/Debug Shell scripts?
I tried changing the shell used by the Terminal to the WSL Ubuntu shell, which actually worked. Thus I can now manually execute the bash script via the terminal.
I also tried changing the Run/Debug configuration.
changed Run/Debug configuration
as suggesteed, changing the interpreter to bash.exe led to an error message.
interpreter changed to bash.exe
I tried bash.exe, ubuntu.exe and cmd.exe as shells for terminal, all of which threw a file not found error. As before executing it manually with the wsl path format(/mnt/c/..) works. manual execution
"file not found"-error
So I guess it was my misunderstanding in the end, that you can't really work with shell scripts like you do with python. meaning debugging etc and watching variables. I am trying to reduce my file shuffling code in bash anyways and try to stay mainly in python so there is now another motivation for that. thank you very much for helping me though.
I want to be able to have a working jupyter notebook working for VS code out of the box, with minimal work on my side.
I tried opening a jupyter notebook. I immediately found the interpreter and used my conda env with the command pellet (command + shift + P then in the drop down menu found my conda env). This seems to make the terminal work since which python points to the right place:
(automl-meta-learning) brandomiranda~/automl-meta-learning ❯ which python
/Users/brandomiranda/miniconda3/envs/automl-meta-learning/bin/python
also running python scripts from VS Code seems to be working fine too, see output:
(automl-meta-learning) brandomiranda~/automl-meta-learning ❯ /Users/brandomiranda/miniconda3/envs/automl-meta-learning/bin/python /Users/brandomiranda/automl-meta-learning/python_playground.py
x = 1
my_str = this is a string
y = 2
but when I try the jupyter notebook it doesn't work.
Most noticeably my VS code does not have a kernel connected, look at the screenshot:
I tried clicking on a couple of arrows as suggested on reddit (vs_code_jupyter_server_no_kernel_python_not):
When I try running things in my jupyter notebook I get the following error:
Error: Activating Python 3.7.6 64-bit ('base': conda) to run Jupyter failed with Error: StdErr from ShellExec, /Users/brandomiranda/.bashrc: line 31: jump-module.bash: No such file or directory
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
.
which is strange. My shell is not even bash so I don't know why that message is being shown to me (maybe VS Code doesn't know Mac OS Catalina uses zsh? not sure how to fix that for VS Code). Regardless, I proceeded to do what I think the error message is suggesting. So I did the following:
I ran conda init and then went down to the terminal inside vs code and restarted the shell by running zsh but the jupyter kernel still doesn't work on my notebook in vs code. Not sure what's wrong.
In addition, I did what the error message suggested:
(automl-meta-learning) brandomiranda~/automl-meta-learning ❯ conda init zsh
no change /Users/brandomiranda/miniconda3/condabin/conda
no change /Users/brandomiranda/miniconda3/bin/conda
no change /Users/brandomiranda/miniconda3/bin/conda-env
no change /Users/brandomiranda/miniconda3/bin/activate
no change /Users/brandomiranda/miniconda3/bin/deactivate
no change /Users/brandomiranda/miniconda3/etc/profile.d/conda.sh
no change /Users/brandomiranda/miniconda3/etc/fish/conf.d/conda.fish
no change /Users/brandomiranda/miniconda3/shell/condabin/Conda.psm1
no change /Users/brandomiranda/miniconda3/shell/condabin/conda-hook.ps1
no change /Users/brandomiranda/miniconda3/lib/python3.7/site-packages/xontrib/conda.xsh
no change /Users/brandomiranda/miniconda3/etc/profile.d/conda.csh
no change /Users/brandomiranda/.zshrc
No action taken.
but it seems it made no difference.
Any idea how to fix this?
I was suggessted by the developers of the VS code python extension to follow whatever they did here:
https://github.com/microsoft/vscode-python/issues/9566
but I can't figure out exactly it is they want me to do.
How do I fix this?
Related resources:
reddit: https://www.reddit.com/r/vscode/comments/eq2bfv/vs_code_jupyter_server_no_kernel_python_not/
gitissue: https://github.com/microsoft/vscode-python/issues/9636
I initially thought it was a conda issue so I looked into this question: Activate conda environment stopped working in vscode
https://www.reddit.com/r/vscode/comments/eshxka/how_does_one_connect_a_jupyter_kernel_to_vs_code/
https://www.quora.com/unanswered/How-does-one-connect-a-Jupyter-Kernel-to-VS-Code-if-one-does-not-connect-automatically
You need to select the python interpreter for jupyter, you can do it by following the step
Open command panel
Mac: CMD+Shift+P
PC: CTRL+SHIFT+P
Then search for select Interpreter to start jupyter server then hit enter, it will list all the interpreter, then select any interpreter and done!
it's just a one time process, after this, it will get connected automatically.
As bizarre as it seems, I also noticed this the other day and the only thing that works so far for me is to open VS Code by launching it from the Anaconda Navigator:
Then I get, as expected:
If you see the very long discussion I had in the git issue (https://github.com/microsoft/vscode-python/issues/9566) once I removed all the errors thrown by my .bashrc and .zhrc, the jupyter feature in VS code started working for me again. It's super weird (specially because I am NOT using bash at all and I am using zsh as my shell, I would have expected VS code to be robust to my .SHELLrc files throwing errors but it's not).
If that doesn't work, then you might have to install the vsix view extension and install the ms-python-insiders.vsixlinked in the issue (https://github.com/microsoft/vscode-python/issues/9566).
If on Windows VSCode, what worked for me was installing and enabling the Python and Jupyter extensions, then CTRL+SHIFT+P, select Interpreter to start jupyter server. Those extensions were the bottleneck.
I've installed python 2.7 on my machine. Although path variables are set properly, whenever I fire python command, it opens up python prompt in new window. If I try to run it as an administrator, it works fine. But gives an issue for normal user.
It is resolved, python.exe was by default running as an administrator when python command was fired. Resetting it helped in resolving the issue.
reference_image