Just installed Anaconda3. It came with the Microsoft Visual Code editor. I would like to use the Anaconda Prompt instead of Powershell or the CMD window from within the editor. Is there a way to change the default?
I didn't find the exact answer I was looking for but I believe my solution may help others so I'm posting my workaround:
Conveniently the Windows CMD or Powershell terminal opens in the same directory as the folder loaded into the Visual Code editor so I wanted to maintain this functionality. Here is how I did it without changing any Environmental Variables.
First change the default terminal from within Visual Code to the CMD terminal instead of Powershell. Add the following code to a batch file.
call "c:\anaconda3\Scripts\activate"
Then I named the batch file and saved it to my root directory. In my case snake.bat. Now when I launch my CMD terminal I just type c:\snake.batand the CMD prompt changes into an Anaconda prompt.
The Visual Code Editor attempts to do this already, but has errors. I believe this is because it opens with Powershell instead of the CMD terminal by default.
Related
So I need to use Python for my work. Unfortunately, since recent hacks, the companies security policies are very strict and there is no way I'm getting admin rights. I managed to persuade our IT to install Python, Visual Studio Code, and the Python extension for it on my computer.
If I try to run python commands in the Python interpreter it works. But when I try to run a Python script in Visual Studio Code it hast to run Power Shell which is also blocked for security reasons.
I get the following error:
The terminal process command 'C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe' failed to launch (exit code: {2})
Is there some way around this? To use Python in Visual Studio Code despite all of the security restrictions?
I tried asking our IT department but they have no idea how to help me...
Thank you in advance.
You can change the VS Code settings and tell it to not use PowerShell as shell in the integrated terminal.
For example, I have put Windows Terminal in there, but you can also use CMD or any other shell such a git bash as long as it's available in your system.
Press ctrl+shift+p and type/select Open Settings (JSON). Then add some of the following to this configuration file, and save.
For Windows Terminal:
"terminal.external.windowsExec": "C:\\Users\\<your-username>\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"
For CMD:
"terminal.external.windowsExec": "C:\\Windows\\system32\\cmd.exe"
I'm used below code in setting file and it works.
"terminal.integrated.defaultProfile.windows": "Command Prompt"
I'm working with Django right now and when I installed it through the command prompt I made a virtualenv called test, now I went into vs code and I am trying to open it up by saying workon test but it's not going into the virutalenv. I am on windows and I am using visual studio code.
To open virtual env through command prompt,
run, activate.bat
\test\Scripts\activate.bat
for bash run,
source test/bin/activate
just go to the left below corner where your python version is written click it, it will open the command palette where select the virtual env. (with its name) that's is test and press ok.
After that open new terminal and you will get what you want
In cmd typing test/Scripts/activate worked, but in vscode terminal, I had to cd till the Scripts and then type .\activate.
Error (Translated): The command "ffplay" is either misspelled or
could not be found.
I have the newest version of vsc installed and the path for the cmd is set to the original path "C:\WINDOWS\system32\cmd.exe". Both terminals have the same path.
Typing in 'python' works on both terminals, while plenty of other commands only work in the external cmd.
Why am i getting this error?
This problem also prevents me from using the module subprocess as every command is just 'not found'.
I noticed that your terminal window has a specific title, which means that you are not using the system default terminal. If you want to use the same environment variable in vscode, a common practice is to start vscode from that terminal, and the vscode that starts this way inherits its environment variable. Enter "code" in the terminal prompt and return to start vscode
so far I have been ok with debugging and running in a python debug terminal. Now that I'm being forced into functions, i have to input the arguments when launching the script, for example:
./python.py BIRTHDAY AHMED
and have it spit out something along the lines of this:
have a happy BIRTHDAY enjoy the day AHMED
problem comes down to me not knowing how to setup a terminal for such use. i have a bash terminal, however it wont recognize my python interpreter (#!/usr/bin/python3).
I added "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" to my user settings to gain the bash terminal as well as installed Git.
Any ideas on how i can get a work in terminal that i can input arguments and recieve an output would be most appreciated. (running on windows 10)
You are providing the path of Git Bash, which only provides enough bash-like functionality to use git. That is why running .sh (Bash Scripts) or .py files doesn't work by default.
If you add python to your PATH environment variable, that will make it so running python.exe filename.py [ARGS] will work on the Integrated Terminal.
Another solution is to install WSL if you are on Windows 10, which does provide full* bash functionality under a modified Ubuntu shell. Then just provide VSCode the path to the WSL bash.exe. (How to here)
I installed Python 3.6, then uninstalled Python 3.4.
I used to be able to double-click .py files in window explorer to run my scripts directly, or by simply typing in command prompt main.py. A console window would open and my script would do it's thing.
After the installation-uninstallation, however, I can no longer do this. Double-clicking .py or simply typing main.py opens Microsoft Visual Studio 2015's create account window.
Right-clicking the .py file and using 'open with', I have tried navigating to my Python 3.6 installation path and opening the script with both python.exe and pythonw.exe. The former opens a console window very briefly, for a split second, and then closes itself. The latter does nothing.
My installation is python-3.6.0-amd64. I have tried the repair option as well as modify option in the installation/setup file I downloaded. Under advanced options in modify option in the setup file, 'associate files with Python (requires the py launcher) is checked.
Following some relevant advice on another stack overflow thread, I ran assoc and ftype setting commands in the windows command prompt with administrative privileges. Now:
C:\WINDOWS\system32>assoc .py .py=Python.File
C:\WINDOWS\system32>ftype Python.File Python.File=C:\Users\me\AppData\Local\Programs\Python\Python36\pythonw.exe "%1" %*
I went to sleep, and came back to this question to give it another go.
...I forgot to put in a time.sleep(), so the script closed itself as soon as it ran, or an exception was called.
whew lads.