Launch VS Code from WSL Bash - windows

I have the Creators update installed. WSL is operational. I can execute most .exe files by simply calling notepad.exe But when it comes to VS Code.... I can't use the default code command or call code.exe... I have also tried code and code.cmd. Why doesn't VS Code execute like other programs? And is there a way to enable the code command?
EDIT: I now get these errors:
me#mypc:/mnt/c/Users/me/Documents/project_folder$ code .
/mnt/c/Program Files (x86)/Microsoft VS Code/bin/code: line 7: realpath: comma
nd not found
/mnt/c/Program Files (x86)/Microsoft VS Code/bin/code: line 14: ./Code.exe: No
such file or directory

The Creators update did install the interop functionality. However, it seems you need to install realpath in WSL in order for the path to be recognized. I'm not sure why this is the case but running sudo apt-get install realpath fixed it for me!
EDIT: After updating to the Fall Creators Update launching VSCode from WSL works out of the box 🎉

You could always create an alias in the WSL Bash shell
alias code="/mnt/c/Program\ Files/Microsoft\ VS\ Code/Code.exe"
If you add this to your .bashrc or .zshrc file then it will always be available when you start a new instance of your environment.

WARNING: Do not change Linux files using Windows apps and tools
Update: The above is not relevant to version 1903 or newer.
With that out of the way, I recently experienced the exact same behavior. Turns out, in my noobish first whack at WSL with VS Code I also installed a native copy from apt which overwrote the Windows path.
So in WSL I removed it with something like this...
$ sudo apt remove code -y; sudo apt autoremove -y
Then confirmed the path was correct...
$ which code
/mnt/c/Program Files/Microsoft VS Code/bin/code
Then relaunched WSL terminal and all was well in the wonderful world of coding once again. :)
Note: I suppose another option would be to fix the path in WSL, but without a GUI package installed it will just launch in the background and never appear anyway.

Another alternative is to use the following:
cmd.exe /c code
This also works for VSCodium:
cmd.exe /c codium

I had the same problem after manually updating Ubuntu on wsl2. I solved this by adding this function to .bashrc config file. It's better solution than alias because it does not block the console.
Before adding it to your config test the function in bash and adjust the path if needed. For sure, you must change {username} to your Windows account username.
function code () { /mnt/c/Users/{username}/AppData/Local/Programs/Microsoft\ VS\ Code/Code.exe; }
If that work add it to your configuration script e.g. .bashrc, .zshrc. Here's a script that does that.
echo "function code () {
/mnt/c/Users/{username}/AppData/Local/Programs/Microsoft\ VS\ Code/Code.exe \"\$#\";
}" >> ~/.bashrc
source ~/.bashrc
code .
Although my recommendation is to make backup and install fresh distro from Microsoft Store then open VS Code with Remote - WSL extension. If there came out an error with initializing WSL Extensions reinstall it first. If you used 19.04 Ubuntu and upgraded to 20.04 it sometimes needs to download initialization scripts for that version or it fails.
That should help :)

I'm new so I don't have enough reputation to comment
I just want to point out that some people(like me) have visual studio code installed in C:\Users\YourUserNameGoesHere\AppData\Local\Programs\Microsoft VS Code instead of C:\Program Files\Microsoft Visual Studio If you cant get it to work, try checking if it is installed in Appdata instead of Program Files.
The escaped WSL path to the x86 visual studio executable is
/mnt/c/Users/UserName/AppData/Local/Programs/Microsoft\ VS\ Code/code.exe

Related

nvim_treesitter installation on windows

bad English (sorry).
I'm trying to get nvim_treesitter to work on my windows machine, on my Linux one it worked great but now when I try on windows the :checkhealth nvim_treesitter gives:
health#nvim_treesitter#check
Installation
ERROR: tree-sitter executable not found
OK: git executable found.
ERROR: cc executable not found.
ADVICE:
Check that either gcc or clang is in your $PATH
Parser/Features H L F I
Legend: H[ighlight], L[ocals], F[olds], I[ndents]
*) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}
and I'm totally new to this thing, any advice would help:)
The main issue from my perspective is "ERROR: cc executable not found.". It means nvim_treesitter couldn't find any compiler on your machine, and so no parsers could be compiled and installed when you issue ":TSInstall {some_parser_name}" commands.
If you have Visual Studio installed (since nvim gets compiled by VS 2017, it's fine to have 2017 or 2019 studio, I guess), try this:
Run "x64 Native Tools Command Prompt for VS 201x" if you've downloaded nvim-win64 release package or "x86 Native Tools Command Prompt for VS 201x" otherwise (nvim-win32 package)
Run nvim in this command prompt (i.e. nvim-qt GUI)
Install any parsers you want, let's say ":TSInstall c". Output should look like this:
Downloading...
Compiling...
Treesitter parser for c has been installed.
Optionally run :checkhealth nvim_treesitter again to see if everything is fine
Thereafter you can run nvim in any console, not via VS Tools one only (still use it to install or update parsers though).
Please also see https://github.com/nvim-treesitter/nvim-treesitter/wiki/Windows-support for various instructions.
For the Error: tree-sitter: You can checkout creating parsers and follow the description or you download the windows binary of the binary files and put it into a directory on your PATH.
For the Error: cc: You need to install gcc
Try to apply this vsc tutorial from Prerequisites â„–3
I had the same issue. It helped me.
Ok, here's what I've done and what helped me:
Go to https://www.msys2.org and follow ALL of the installation steps that are described there:
Download and install
Run pacman -Syu comman
Run pacman -S --needed base-devel mingw-w64-x86_64-toolchain and choose mingw-w64-x86_64-gcc there.
After everything is installed, put into your PATH Environment Variable the path to MinGW64\bin folder (if you installed everything to the default folder it will be c:\msys64\mingw64\bin)
And you are good to go! Now open nvim and run
:TSInstall <yourlang>
For example, :TSInstall php
PS: you can get the list of available languages using :TSInstallInfo

Code command terminal interface on macOS of Visual Studio Code not works after restart system

I use the command on terminal code file.txt to open file with Visual Studio Code, but when I restart the system, the command stop works. And I need open Visual Studio Code, and reconfigure path to use the code command line interface.
How I can fix this? I'm using macOS HighSierra.
After I restart the system the command apparently fade.
-bash: code: command not found
So your issue may be related to how you installed VSCode
I would run below to install the same
brew cask install visual-studio-code
If you don't want to use brew then I would download the app from below link
https://code.visualstudio.com/docs/?dv=osx
And after unzipping move it to Applications folder in finder.
There may be a possibility that MacOS Gatekeeper is interfering with the location of your app after every restart. Which means the symlink gets invalidated every restart and hence the issue
If the problem still happens after restart, you want to exclude VScode out of gatekeeper
spctl --add "/Applications/Visual Studio Code.app"
Try to repeat again what is described in official documentation.
Check whether Visual Studio Code is installed in the correct folder with the command: ls -l /usr/local/bin/code.
You can find out correct path by running the command which code or where code in bash.
If the command returns path like that: /usr/local/bin/code -> /private/var/folders/xf/vnnm636d0k92w3sc7lm95w040000gn/T/AppTranslocation/3815E4B6-43DB-0F8E-AAB9-EDE3AC7F67CC/d/Visual Studio Code.app/Contents/Resources/app/bin/code
/usr/local/bin, it means that the program was installed in a temporary folder.
The path must be: /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code.
If the program was installed in a temporary folder, this could cause this problem.
Drag Visual Studio Code.app to the Applications folder and repeat
instructions from the official documentation.
If after the above described still does not work and the program is not installed in a temporary folder, it is advisable to check bash settings in ~/.bash_profile and ~/.bash_profile.
P.S.
Also, if none of the above does not help, you can try the following: sudo ln -fs "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" "/usr/local/bin/".

pycharm swig how to? [windows]

I would require some guidance in regards to installing a module/package in pycharm (free edition). I have to mention that i have not worked with this IDE yet and wanted to try it out on a little project containing smartcards.
When i try to install "pyscard" i get the error that boils down to
error: command 'swig.exe' failed: No such file or directory
People say just install SWIG, which i guessed already ^^.
The issue i have is that i actually have no idea how to... and none of the pages i found has really enlightended me on this issue.
I downloaded the zip "swigwin-3.0.12" but i am at a loss what to do with it now. EDIT: According to the SWIG page this is an already compiled version and i have to somehow make pycharm recognize that the folder it is in contains the swig.exe it requires.
EDIT2: Adding the folder containing the swig.exe to the PATH variable also did not work ... which i thought would be the issue
EDIT3+Answer:
Ok the link in the comments from "wp78de" was correct my problem was that pycharm/pc restart were needed for it to catch the added PATH variable to the swig.exe (for pycharm that is)
Any advice is appriciated.
Envoirment:
Windows 8.1 Pro 64-bit
Pycharm 2017.2.4
Python 3.6
Basically, you just have to add the directory that contains the swig executable the PATH environment variable. You can do it via CMD or the Windows UI.
If you have added swig to your path, you should be able to call it in the command prompt from any directory: open "cmd", and type swig --help" on that prompt.
A restart of PyCharm (or whatever your IDE is) and Windows might be required.

How to install and use "make" in Windows?

I'm following the instructions of someone whose repository I cloned to my machine. I want to use the make command as part of setting up the code environment, but I'm using Windows. I searched online, but I could only find a make.exe file, a make-4.1.tar.gz file (I don't know what to do with it next) and instructions for how to download MinGW (for GNU; but after installing it I didn't find any mention of "make").
How do I use make in Windows without a GNU compiler or related packages?
make is a GNU command so the only way you can get it on Windows is installing a Windows version like the one provided by GNUWin32. Anyway, there are several options for getting that:
The most simple choice is using Chocolatey. First you need to install this package manager. Once installed you simlpy need to install make (you may need to run it in an elevated/admin command prompt) :
choco install make
Other recommended option is installing a Windows Subsystem for Linux (WSL/WSL2), so you'll have a Linux distribution of your choice embedded in Windows 10 where you'll be able to install make, gccand all the tools you need to build C programs.
For older Windows versions (MS Windows 2000 / XP / 2003 / Vista / 2008 / 7 with msvcrt.dll) you can use GnuWin32.
An outdated alternative was MinGw, but the project seems to be abandoned so it's better to go for one of the previous choices.
GNU make is available on chocolatey.
Install chocolatey from here.
Then, choco install make.
Now you will be able to use Make on windows.
I've tried using it on MinGW, but it should work on CMD as well.
The accepted answer is a bad idea in general because the manually created make.exe will stick around and can potentially cause unexpected problems. It actually breaks RubyInstaller: https://github.com/oneclick/rubyinstaller2/issues/105
An alternative is installing make via Chocolatey (as pointed out by #Vasantha Ganesh K)
Another alternative is installing MSYS2 from Chocolatey and using make from C:\tools\msys64\usr\bin. If make isn't installed automatically with MSYS2 you need to install it manually via pacman -S make (as pointed out by #Thad Guidry and #Luke).
If you're using Windows 10, it is built into the Linux subsystem feature. Just launch a Bash prompt (press the Windows key, then type bash and choose "Bash on Ubuntu on Windows"), cd to the directory you want to make and type make.
FWIW, the Windows drives are found in /mnt, e.g. C:\ drive is /mnt/c in Bash.
If Bash isn't available from your start menu, here are instructions for turning on that Windows feature (64-bit Windows only):
https://learn.microsoft.com/en-us/windows/wsl/install-win10
Download make.exe from their official site GnuWin32
In the Download session, click
Complete package, except sources.
Follow the installation instructions.
Once finished, add the <installation directory>/bin/ to the PATH variable.
Now you will be able to use make in cmd.
Install Msys2 http://www.msys2.org
Follow installation instructions
Install make with $ pacman -S make gettext base-devel
Add C:\msys64\usr\bin\ to your path
On windows 10 or 11, you can run the command winget install GnuWin32.Make in the command line or powershell to quickly install it. Than you can use the command cmake.
There is no need to install choco anymore.
The chances are that besides GNU make, you'll also need many of the coreutils. Touch, rm, cp, sed, test, tee, echo and the like. The build system might require bash features, if for nothing else, it's popular to create temp file names from the process ID ($$$$). That won't work without bash. You can get everything with the popular POSIX emulators for Windows:
Cygwin (http://www.cygwin.org/) Probably the most popular one and the most compatible with POSIX. Has some difficulties with Windows paths and it's slow.
GNUWin (http://gnuwin32.sourceforge.net/) It was good and fast but now abandoned. No bash provided, but it's possible to use it from other packages.
ezwinports (https://sourceforge.net/projects/ezwinports) My current favorite. Fast and works well. There is no bash provided with it, that can be a problem for some build systems. It's possible to use make from ezwinports and bash from Cygwin or MSYS2 as a workaround.
MSYS 1.19 abandoned. Worked well but featured very old make (3.86 or so)
MSYS2 (https://www.msys2.org/) Works well, second fastest solution after ezwinports. Good quality, package manager (pacman), all tooling available. I'd recommend this one.
MinGW abandoned? There was usually MSYS 1.19 bundled with MinGW packages, that contained an old make.exe. Use mingw32-make.exe from the package, that's more up to date.
Note that you might not be able to select your environment. If the build system was created for Cygwin, it might not work in other environments without modifications (The make language is the same, but escaping, path conversion are working differently, $(realpath) fails on Windows paths, DOS bat files are started as shell scripts and many similar issues). If it's from Linux, you might need to use a real Linux or WSL.
If the compiler is running on Linux, there is no point in installing make for Windows, because you'll have to run both make and the compiler on Linux. In the same way, if the compiler is running on Windows, WSL won't help, because in that environment you can only execute Linux tools, not Windows executables. It's a bit tricky!
I could suggest a step by step approach.
Visit GNUwin
Download the Setup Program
Follow the instructions and install GNUWin. You should pay attention to the directory where your application is being installed. (You will need it later1)
Follow these instructions and add make to your environment variables. As I told you before, now it is time to know where your application was installed.
FYI: The default directory is C:\Program Files (x86)\GnuWin32\.
Now, update the PATH to include the bin directory of the newly installed program.
A typical example of what one might add to the path is: ...;C:\Program Files (x86)\GnuWin32\bin
Another alternative is if you already installed minGW and added the bin folder the to Path environment variable, you can use "mingw32-make" instead of "make".
You can also create a symlink from "make" to "mingw32-make", or copying and changing the name of the file. I would not recommend the options before, they will work until you do changes on the minGW.
I once had the same problem. But I am surprised not to find one particular solution here.
Installation from GnuWin32 or via winget are good and easy options. But I only found make 3.8.1 there. This version lacks the very important option -O, which handles the output correctly when compiling multithreaded.
choco appears to offer make 4.3, currently. So one could expect recent versions there.
But there is also the option of self compiling. And if you have to install make, which is used for compiling, this should be a valid option.
head to https://www.gnu.org/software/make/ and download a version of your liking
unpack the tar.gz files (use 7zip and unpack the file twice to retrieve the actual content)
navigate to the created directory
open command prompt in that directory
run build_w32.bat gcc This will start the compilation with the gcc compiler, which you would need to install in advance. When running build_w32.bat without any option they try to use the MSVC compiler. Sidenote: I found it surprising that gnu does not use gcc as default but MSVC :-)
ignore the warnings created during compilation. The result should still be fine
retrieve your fresh gnumake.exe from the directoy GccRel (when compiled with gcc)
put this file somewhere where you like and rename to make.exe
add the location to the system variable %PATH%
As others have noted: This manual installation might cause conflicts if you have various make versions installed by other programs as well.
You can also install scoop, then run:
scoop install make
One solution that may helpful if you want to use the command line emulator cmder. You can install the package installer chocately. First we install chocately in windows command prompt using the following line:
#"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
refreshenv
After chocolatey is installed the choco command can be used to install make. Once installed, you will need add an alias to /cmder/config/user_aliases.cmd. The following line should be added:
make="path_to_chocolatey\chocolatey\bin\make.exe" $*
Make will then operate in the cmder environment.
Install npm
install Node
Install Make
node install make up
node install make
If above commands displays any error then install Chocolatey(choco)
Open cmd and copy and paste the below command (command copied from chocolatey URL)
#"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command " [System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

How to run a makefile in Windows?

I have some demos that I downloaded and they come with a Makefile.win and a Makefile.sgi. How can I run these in Windows to compile the demos?
You can install GNU make with chocolatey, a well-maintained package manager, which will add make to the global path and runs on all CLIs (powershell, git bash, cmd, etc…) saving you a ton of time in both maintenance and initial setup to get make running.
Install the chocolatey package manager for Windows
compatible to Windows 7+ / Windows Server 2003+
Run choco install make
I am not affiliated with choco, but I highly recommend it, so far it has never let me down and I do have a talent for breaking software unintentionally.
If you have Visual Studio, run the Visual Studio Command prompt from the Start menu, change to the directory containing Makefile.win and type this:
nmake -f Makefile.win
You can also use the normal command prompt and run vsvars32.bat (c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools for VS2008). This will set up the environment to run nmake and find the compiler tools.
Check out GnuWin's make (for windows), which provides a native port for Windows (without requiring a full runtime environment like Cygwin)
If you have winget, you can install via the CLI like this:
winget install GnuWin32.Make
Also, be sure to add the install path to your system PATH:
C:\Program Files (x86)\GnuWin32\bin
Check out cygwin, a Unix alike environment for Windows
Here is my quick and temporary way to run a Makefile
download make from SourceForge: gnuwin32
install it
go to the install folder
C:\Program Files (x86)\GnuWin32\bin
copy the all files in the bin to the folder that contains Makefile
libiconv2.dll libintl3.dll make.exe
open the cmd (you can do it with right click with shift) in the folder that contains Makefile and run
make.exe
done.
Plus, you can add arguments after the command, such as
make.exe skel
If you install Cygwin. Make sure to select make in the installer. You can then run the following command provided you have a Makefile.
make -f Makefile
https://cygwin.com/install.html
I use MinGW tool set which provides mingw32-make build tool, if you have it in your PATH system variables, in Windows Command Prompt just go into the directory containing the files and type this command:
mingw32-make -f Makefile.win
and it's done.
I tried all of the above. What helps me:
Download the mingw-get.
Setup it.
Add something like this C:\MinGW\bin to environment variables.
Launch (!important) git bash. Power shell, developer vs cmd, system cmd etc didn't help.
Type mingw-get into the command line.
After type mingw-get install mingw32-make.
Done! Now You might be able to use make-commands from any folder that contains Makefile.
With Visual Studio 2017 I had to add this folder to my Windows 10 path env variable:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64
There's also HostX86
If it is a "NMake Makefile", that is to say the syntax and command is compatible with NMake, it will work natively on Windows. Usually Makefile.win (the .win suffix) indicates it's a makefile compatible with Windows NMake. So you could try nmake -f Makefile.win.
Often standard Linux Makefiles are provided and NMake looks promising. However, the following link takes a simple Linux Makefile and explains some fundamental issues that one may encounter. It also suggests a few alternatives to handling Linux Makefiles on Windows.
Makefiles in Windows
Firstly, add path of visual studio common tools (c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools) into the system path. To learn how to add a path into system path, please check this website:
http://www.computerhope.com/issues/ch000549.htm. You just need to this once.
After that, whenever you need, open a command line and execute vsvars32.bat to add all required visual studio tools' paths into the system path.
Then, you can call nmake -f makefile.mak
PS: Path of visual studio common tools might be different in your system. Please change it accordingly.
I tried with cygwin & gnuwin, and didn't worked for me, I guess because the makefile used mainly specific linux code.
What it worked was use Ubuntu Bash for Windows 10. This is a Marvel if you come from MAC as it is my case:
To install the Ubuntu Bash: https://itsfoss.com/install-bash-on-windows/
Once in the console, to install make simply type "make" and it gives the instructions to download it.
Extras:
Useful enable copy / paste on bash: Copy Paste in Bash on Ubuntu on Windows
In my case the make called Maven, so I have to install it as well: https://askubuntu.com/questions/722993/unable-to-locate-package-maven
To access windows filesystem C: drive, for example: "cd /mnt/c/"
Hope it helps
Install msys2 with make dependency add both to PATH variable.
(The second option is GNU ToolChain for Windows. MinGW version has already mingw32-make included.)
Install Git Bash. Run mingw32-make from Git Bash.
If you have already installed the Windows GNU compiler (MinGW) from MSYS2 then make command comes pre-installed as wingw32-make. Always match cmake makefile generation with the correct make command. Mixing these generate problems.
MinGW makefile generation with MinGW make command
Visual Studio makefile generation with VS equivalent make command
And this is always possible as long as you have the source code. Just delete old build directory and start over by specifying this time the right parameter in cmake ,e.g.
mkdir build
cd build
cmake -G "MinGW MakeFiles" path/to/src/whereCMakeLists.txtInstructionsAre
mingw32-make
myProject.exe # RUN
I have encountered issues during compilation where multiple make commands interact. To prevent this just edit/remove the environmental variables that lead to different make commands. For example to prevent conflicts with mingw, keep only C:\msys64\mingw64\bin but remove C:\msys64\usr\bin. That other path contains the msys make and as I said you do not want to combine make commands during compilation.
Download from https://sourceforge.net/projects/gnuwin32/
Set the variable path in advance setting for recognize in command prompt (C:\Program Files (x86)\GnuWin32\bin)
So if you're using Vscode and Mingw then you should first make sure that the bin folder of the mingw is included in the environment path and it is preferred to change the mingw32-make.exe to make to ease the task and then create a makefile
and include this code in it .
all:
gcc -o filename filename.c
./filename
Then save the makefile and open Vscode Code terminal and write make. Then makefile will get executed.
I am assuming you added mingw32/bin is added to environment variables else please add it and I am assuming it as gcc compiler and you have mingw installer.
First step: download mingw32-make.exe from mingw installer, or please check mingw/bin folder first whether mingw32-make.exe exists or not, else than install it, rename it to make.exe.
After renaming it to make.exe, just go and run this command in the directory where makefile is located. Instead of renaming it you can directly run it as mingw32-make.
After all, a command is just exe file or a software, we use its name to execute the software, we call it as command.
For me installing ubuntu WSL on windows was the best option, that is the best tool for compiling makefile on windows. One thousand is better than Cygwin64, because to compile a makefile you will need another package and compile software like maybe gfortran, netcdf, etc, ect, in ubuntu WSL you can install all of these packages very easily and quickly ;)
The procedure I followed is;
I installed Gnuwin32's make using the installable.
Added the "make" path to the environmental variable PATH.
Verified the installation using "make --version"
Go to http://gnuwin32.sourceforge.net/packages/make.htm and download make-3.81.exe, install and add to Windows path.
May be it can work.
pip install Makefile

Resources