I am running Visual Studio Code on Windows 10 with WSL bash as its terminal:
"terminal.integrated.shell.windows": "C:/Windows/sysnative/bash.exe"
In WSL bash I have both python (v2.7) and python3 (v3.6) installed.
I have installed the Python extension for VS Code. Unfortunately VS Code fails to recognize either version of Python in WSL bash.
For example when I try to discover tests, I get the following error in the Python Test Log output window:
Test Discovery failed:
Error: spawn python ENOENT
How can I configure VS Code to work with Python form WSL bash?
Note: I'm pretty sure I need to configure a path to Python in the "python.pythonPath" key in VS Code's user settings file. I am unsure of which path to put as the value though.
Support for WSL is done through the "WSL - Remote" extension. There is a WSL blog post which covers how to get started.
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 have a virtual environment set up inside bash for Windows (Ubuntu) and VS Code installed (Windows). The Python project runs well inside the venv in bash but I would like to now debug it through Visual Code.
I'm trying to set the python.pythonPath as follows inside settings.json
{
"python.pythonPath": "C:\\repos\\myrepo\\venv\\bin\\python"
}
The error returned is "Please validate the path ..."
Note that through bash for Windows, the filesystem is accessible through /mnt/c/
As for the auto-detection of Python, it only lists the python.exe installed on the windows filesystem (which is of no use to me).
https://code.visualstudio.com/docs/python/environments explains that doing this should be sufficient but doesn't seem to work.
It doesn't work because WSL isn't officially supported yet by the extension as of version 0.8.0. See https://github.com/Microsoft/vscode-python/issues/67 to up-vote and track the issue for detecting WSL-based virtual environments.
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 am using Aptana studio 3 for Python. I created one demo.py file and typed some print statement. I tried to run this file with run as option but there was no sub options to run this file.
I have one doubt here whether the python interpreter is configured or not. Please help me to configure the python interpreter and run this file successfully.
You should be able to find out location of your Python interpreter with command which python in your terminal. I am not using Aptana myself, but after invoking mentioned command, you should set Python's path somewhere in Aptana's settings. If you are using virtual environment, be sure that you invoke which python command after activating virtual env.
Maybe this post can instruct you further.
I'm currently using a Protobuf plugin to generate some custom C# code given a set of Protobuf files. It is running fine on Linux and I would like to run it on Windows as well in order to generate this code directly from my Visual Studio project.
Here is the command line I am (unsuccessfully) using currently :
path\to\protoc.exe --plugin=protoc-gen-my-plugin=path\to\my-plugin.py --my-plugin_out=output\path\gen my_proto.proto
And here is the error I'm getting :
--my-plugin_out: protoc-gen-my-plugin: %1 n'est pas une application Win32 valide.
I have Python 2.7.11 installed and it is in my path. I also tried to run protoc.exe using both x86 and x64 executables.
Is there any limitation I'm not aware of or did I miss something?
I was able to fix my issue by encapsulating the python plugin in a .bat file. Here is the code I used :
#echo off
chdir path\to\my-plugin
python -u my-plugin.py
The "-u" option when running the python script is really important because otherwise the standard input will be buffered. As protoc is passing all the inputs to the plugin (the .proto files to parse) through stdin this is really important. And the output is written by the plugin to stdout, so no issue there.
Here is the final command to execute protoc with my plugin :
path\to\protoc.exe --plugin=protoc-gen-my-plugin=redirect.bat --my-plugin_out=output\path\gen my_proto.proto