Swift installation problem on Windows

Hello, I am trying to install swift on a Windows 10 machine, following the installation instructions on swift.org.

(Note that I already have Visual Studio 2019 installed. I am using it to develop an application in C#) that I cannot afford to destroy by reinstalling another version of Visual Studio)

I have downloaded and ran 5.6.2 release file:"swift-5.6.2-RELEASE-windows10.exe"; no problem.

Then I followed the "Installation instructions"; the first two commands work fine:

winget install Git.Git
winget install Python.Python.3 --version 3.10.2150.0

However, when I type in third command:
curl -sOL https://aka.ms/vs/16/release/vs_community.exe

I get an error message:
=> Invoke-WebRequest : A parameter cannot be found that matches parameter name 'sOL'.

If I try to copy&paste and run the fourth command:
start /w vs_community.exe .....
=> I get LOTS of error messages.

Note that following command works fine:
swift --version
=> compnerd.org Swift version 5.6.1 (swift-5.6.1-RELEASE)
Target: x86_64-unknown-windows-msvc

However, if I try to run swift to get to the REPL loop:
swift
=> nothing happens (swift quits instantly)

If I follow the instructions to create a package:

mkdir hello
cd hello
swift package init

I get error message:
=> warning: Failed creating default cache location, Error Domain=NSCocoaErrorDomain Code=256 "(null)"

If I insist and try command "swift run Hello", I get:
warning: Failed creating default cache location, Error Domain=NSCocoaErrorDomain Code=256 "(null)"
'hello': error: invalidManifestFormat(":1:10: note: in file included from :1:\r\r\n#include "AssertionReporting.h"\r\r\n ^\r\r\nC:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims/AssertionReporting.h:16:10: note: in file included from C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims/AssertionReporting.h:16:\r\r\n#include "SwiftStdint.h"\r\r\n ^\r\r\nC:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims/SwiftStdint.h:28:10: error: 'stdint.h' file not found\r\r\n#include <stdint.h>\r\r\n ^\r\r\n:0: error: could not build C module 'SwiftShims'", diagnosticFile: nil)

etc.

Is there any reliable list of instruction that I could follow to have a proper swift compiler on Windows?
Thanks in advance

Are you running these commands from Power Shell or Command Prompt? For me Power Shell gives the same errors but with Command Prompt everything works.

Just yesterday I used these instructions to install Swift on my new computer without any problems so I think they are the realiable instructions you are looking for.

Powershell regards curl to be an alias (short name) of Invoke-WebRequest, and its interface is different from the real curl CLI. That’s why you’re getting such error output.

With any other shell, you should get the correct output. If you tend to use PowerShell, there’s also a simple solution: just replace curl with curl.exe, and PowerShell will correctly refer to it as the curl CLI.

Thanks I would never have guessed. curl ran OK with regular command prompt.

Now if I enter the next command in regular prompt:

start /w vs_community.exe --passive --wait --norestart --nocache ^
--installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community" ^
--add Microsoft.VisualStudio.Component.Windows10SDK.19041 ^
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64

I get error message "cannot find vs-community.exe", although I have Visual Studio 2019 installed and running perfectly... I saw on the Internet that it has been renamed "devenv.exe", but this sounds fishy...

I also tried the same command in power shell, but then I get lots of syntax error messages (???):

At line:2 char:5

  • --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Com ...
  • ~
    

Missing expression after unary operator '--'.
At line:2 char:5

  • --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Com ...
  • ~~~~~~~~~~~
    

Unexpected token 'installPath' in expression or statement.
At line:3 char:5

  • --add Microsoft.VisualStudio.Component.Windows10SDK.19041 ^
  • ~
    

Missing expression after unary operator '--'.
At line:3 char:5

  • --add Microsoft.VisualStudio.Component.Windows10SDK.19041 ^
  • ~~~
    

Unexpected token 'add' in expression or statement.
At line:4 char:5

  • --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64
  • ~

The commands must be run under cmd, not PowerShell. They are fundamentally incompatible, and you cannot create a script which runs under both.

It is fine if you don't want to install another version of Visual Studio, but make sure that you are installing the C++ Desktop workload (which is likely ~25-30G) in addition to the C# workload. The instructions are designed to minimally install Visual Studio (that is the C++ Build tools, and Windows SDK) and so may actually not give you a fully working Visual Studio installation.

The Swift errors indicate that you do not have the necessary components installed. Once you have adjusted the Visual Studio installation, you will need to re-install Swift.

Thanks Saleem,

I just want to install swift on Windows so that I can recompile my Swift programs on Windows, and I am following exactly the instructions written on the Swift.org page. I am OK with using the regular prompt command for the installation, and I have no problem installing the "C++ Desktop workload" or any other missing componant, even though I don't know how. Can you tell me what command I should type in after:

curl -sOL https://aka.ms/vs/16/release/vs_community.exe

(which runs fine) and:

start /w vs_community.exe --passive --wait --norestart --nocache ^
--installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community" ^
--add Microsoft.VisualStudio.Component.Windows10SDK.19041 ^
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64

Which produces error messages...

Thanks in advance
--Max

As you already have Visual Studio partly installed, I don’t know of a good (safe) way to automate it. You could just go to “Add Remove Programs”, find “Visual Studio Installer” and modify the installation. Add in the C++ workload (or you can try to add just the necessary components). Once the new items are installed, repair the swift installation from the “Add Remove Programs” dialog.

Thanks for your patience Saleem,

"C++ Desktop workload" does not show up in any of the installation options I see in the "Workloads" page (see attached screenshot), and if I look up the keyword "Desktop" in the page "Individual Components", no component shows up...

"Desktop Development with C++" is the workload you are looking for (third row on the right).

Thanks Saleem; (actually the option was checked, but I had not rebooted the computer).

Now the command works. Then I ran

c:> del /q vs_community.exe
c:> pip install six

Then I downloaded and installed swift, then I ran:

c:> winget install Swift.Toolchain

and I got following command to work fine:

c:\Users\Max> swift —version
compnerd.org Swift version 5.6.2 (swift-5.6.2-RELEASE)
Target: x86_64-unknown-windows-msvc

However, if I enter the command "swift", I now get following error message (note that I did install python and it seems to work fine):

c:\Users\Max> swift
Python path configuration:
PYTHONHOME = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
PYTHONPATH = (not set)
program name = 'python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\lldb.exe'
sys.base_prefix = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
sys.base_exec_prefix = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
sys.platlibdir = 'lib'
sys.executable = 'C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\lldb.exe'
sys.prefix = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
sys.exec_prefix = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
sys.path = [
'C:\Users\Max\AppData\Local\Programs\Python\Python310\python310.zip',
'C:/hostedtoolcache/windows/Python/3.10.2/x64\DLLs',
'C:/hostedtoolcache/windows/Python/3.10.2/x64\lib',
'C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00002748 (most recent call first):

Hmm, I thought the changes for python made it into 5.6.2. In any case, that is semi expected. Use the compiler not the interpreter. There are some more issues to be resolved there (the details are on the forums).