Can't create any opam switch

Can you confirm you cannot create, for example, “5.1.0” ?

Could you share with us how do you set up your opam?

I have a similar error some days ago, and it was related to the missing of the env var OPAMCURL and OPAMFETCH, check if exists into your environment, if not, set them, e.g.: export OPAMCURL=curl

Other way, check the repository that have been inserted into opam init, validate if this version exists on that repository.

For future reference, please post code extracts in plain text form, not as screenshots, unless impossible. Text is more accessible. Thanks!

1 Like

Yes, I can’t create it:

[ERROR] No compiler matching '5.1.0+msvc64' found, use 'opam switch list-available' to see what is available, or use '--packages' to select packages explicitly.

Hey,

I followed this tutorial: OCaml for Windows - Installation

The graphical installer didn’t work for me so I tried following the manual install guide. I completed all the steps. But I had the same error there too so I tried to create a switch from Windows CMD.

The variables you mentioned weren’t defined for me as well, I defined them by set OPAMCURL=curl and set OPAMFETCH=wget. I checked if they were truly set by:

echo %OPAMCURL%
curl

and

echo %OPAMFETCH%
wget

Then I updated opam:

opam update
<><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><><><>
[default] no changes from git+https://github.com/fdopen/opam-repository-mingw.git#opam2

The same error occured again:

opam switch create 4.14.0+mingw64c
<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ocaml-variants.4.14.0+mingw64c] found in cache
[ERROR] The sources of the following couldn’t be obtained, aborting:
- ocaml-variants.4.14.0+mingw64c

Switch initialisation failed: clean up? (‘n’ will leave the switch partially installed) [Y/n] y
Fatal error: exception Not_found

:frowning:

I’m afraid you’ve hit the deprecated OCaml for Windows (see the deprecation announcement from 2021 on the site.

That repository has been partially maintained elsewhere (see Sunsetting opam-repository-mingw), but there’s no support for OCaml 5.x in it.

However, we released opam 2.2.0 this week! I’d suggest reversing the manual installation you did and heading over to [ANN] opam 2.2.0 is out! for the installation details :blush:

1 Like

Hello,

I have followed the guide you have linked and successfully upgraded opam.

Now I have a different error, which I think is progress! :slight_smile:

C:\Users\omerk>opam switch create ocaml-variants 4.14.0+msvc64

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><><><>
Switch invariant: [“ocaml-variants” {= “4.14.0+msvc64”}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
✶ installed base-bigarray.base
✶ installed base-threads.base
✶ installed base-unix.base
[ERROR] Failed to get extra source “inline-flexdll.patch” of ocaml-variants.4.14.0+msvc64: Download command failed

#=== ERROR while fetching sources for ocaml-variants.4.14.0+msvc64 ============#
OpamSolution.Fetch_fail(“https://gist.githubusercontent.com/fdopen/afe3140904cc975cc9d2e4992e13d547/raw/3d8b647eb196a3174e6c6105881e5d6a4b8fa166/inline-flexdll.patch (Download command failed: "c:\\sox-14-4-2\\wget.exe --content-disposition -t 3 -O C:\\Users\\omerk\\AppData\\Local\\Temp\\opam-9460-b7cd42\\inline-flexdll.patch.part -U opam/2.2.0 – https://gist.githubusercontent.com/fdopen/afe3140904cc975cc9d2e4992e13d547/raw/3d8b647eb196a3174e6c6105881e5d6a4b8fa166/inline-flexdll.patch\” exited with code 1)")

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ ▼ fetch ocaml-variants 4.14.0+msvc64
└─
┌─ The following changes have been performed (the rest was aborted)
│ ✶ install base-bigarray base
│ ✶ install base-threads base
│ ✶ install base-unix base
└─
# Run for /f “tokens=*” %i in (‘opam env --switch=ocaml-variants’) do @%i to update the current shell environment
Switch initialisation failed: clean up? (‘n’ will leave the switch partially installed) [y/n] y

Progress, indeed! :blush: I’d suggest reinitialising opam completely, which I’d do by running opam var root and noting the directory it replies with (I expect, as it was OCaml for Windows this will be something ending with \.opam). I would delete (or rename, if you want to be more cautious) that directory and then re-run opam init.

Out of curiosity (because it may be related to the download problem), which version of Windows are you on?

Hey, I deleted the .\opam direcory, then re-ran opam init:

PS C:\Users\omerk> opam init

<><> Required setup - please read <><><><><><><><><><><><><><><><><><><><><><><>

In normal operation, opam only alters files within ~\AppData\Local\opam.

However, to best integrate with your system, some environment variables
should be set. When you want to access your opam installation, you will
need to run:

>(& opam env) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ }

You can always re-run this setup with ‘opam init’ later.

opam doesn’t have any configuration options for powershell; you will have to run (& opam env) -split ‘\r?\n’ |
ForEach-Object { Invoke-Expression $_ } whenever you change you current ‘opam switch’ or start a new terminal session.
Alternatively, would you like to select a different shell? [y/n] n

then the program terminated.

Then I checked to see if .\opam was created and it wasn’t there.

PS C:\Users\omerk> opam var root

now returns

[ERROR] No config file found for switch playground. Switch broken?
C:\Users\omerk\AppData\Local\opam

I ran opam switch list-available and this time the list was different, it included versions until 5.3.0+trunk.

This time I got the same error:

PS C:\Users\omerk> opam switch create ocaml-variants 5.3.0+trunk

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><><><>
Switch invariant: [“ocaml-variants” {= “5.3.0+trunk”}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
→ installed base-bigarray.base
→ installed base-threads.base
→ installed base-unix.base
[ERROR] Failed to get sources of ocaml-variants.5.3.0+trunk: Download command failed

#=== ERROR while fetching sources for ocaml-variants.5.3.0+trunk ==============#
OpamSolution.Fetch_fail(“https://github.com/ocaml/ocaml/archive/trunk.tar.gz (Download command failed: "c:\\sox-14-4-2\\wget.exe --content-disposition -t 3 -O C:\\Users\\omerk\\AppData\\Local\\opam\\ocaml-variants\\.opam-switch\\sources\\ocaml-variants.5.3.0+trunk\\trunk.tar.gz.part -U opam/2.2.0 – https://github.com/ocaml/ocaml/archive/trunk.tar.gz\” exited with code 1)")

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
± The following actions failed
| - fetch ocaml-variants 5.3.0+trunk
±
± The following changes have been performed (the rest was aborted)
| - install base-bigarray base
| - install base-threads base
| - install base-unix base
±
# Run (& opam env --switch=ocaml-variants) -split ‘\r?\n’ | ForEach-Object { Invoke-Expression $_ } to update the
current shell environment
Switch initialisation failed: clean up? (‘n’ will leave the switch partially installed) [y/n] y

PS: I am running these on Windows 10

Ah - here’s the problem. I’m afraid that 9 year old version of wget doesn’t support the correct TLS stack, having run it locally:

C:\Devel\sox-14-4-2>wget.exe --content-disposition -t 3 -O trunk.tar.gz.part -U opam/2.2.0 https://github.com/ocaml/ocaml/archive/trunk.tar.gz
--2024-07-07 10:35:51--  https://github.com/ocaml/ocaml/archive/trunk.tar.gz
Resolving github.com... 20.26.156.215
Connecting to github.com|20.26.156.215|:443... connected.
OpenSSL: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
Unable to establish SSL connection.

I would possibly simply delete c:\sox-14-4-2\wget.exe (or, again, rename), as I imagine that wget isn’t able to do anything useful these days! (tracking the issue of opam’s UI in this failure mode in Test the download command more explicitly · Issue #6072 · ocaml/opam · GitHub, though).

It’s correct that the .opam directory wasn’t created - opam 2.2.0 by default creates the root in a the rather more Windows-like %LOCALAPPDATA%\opam (which it noted at the top of the opam init)

I deleted c:\sox-14-4-2\wget.exe. Then ran again and got this:

C:\Users\omerk>opam switch create 5.3.0+trunk

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><><><>
Switch invariant: [“ocaml-variants” {= “5.3.0+trunk”}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
✶ installed base-bigarray.base
✶ installed base-threads.base
✶ installed base-unix.base
▼ retrieved ocaml-variants.5.3.0+trunk (https://github.com/ocaml/ocaml/archive/trunk.tar.gz)
[ERROR] The compilation of ocaml-variants.5.3.0+trunk failed at “make -j11”.

#=== ERROR while compiling ocaml-variants.5.3.0+trunk =========================#
# context 2.2.0 | win32/x86_64 | | https://opam.ocaml.org#2b6e600e
# path ~\AppData\Local\opam\5.3.0+trunk.opam-switch\build\ocaml-variants.5.3.0+trunk
# command C:\msys64\usr\bin\make.exe -j11
# exit-code 2
# env-file ~\AppData\Local\opam\log\ocaml-variants-16640-36f7fd.env
# output-file ~\AppData\Local\opam\log\ocaml-variants-16640-36f7fd.out
### output ###
# GEN runtime/primitives
# GEN runtime/caml/opnames.h
# GEN runtime/caml/jumptbl.h
# CC runtime/sak.o
# MKEXE runtime/sak
# GEN runtime/prims.c
# C:/msys64/ucrt64/bin/…/lib/gcc/x86_64-w64-mingw32/13.2.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: C:/msys64/ucrt64/bin/…/lib/gcc/x86_64-w64-mingw32/13.2.0/…/…/…/…/lib/libmingw32.a(lib64_libmingw32_a-crtexewin.o): in function main': \# C:/M/B/src/mingw-w64/mingw-w64-crt/crt/crtexewin.c:67:(.text.startup+0xbd): undefined reference to WinMain’
# collect2.exe: error: ld returned 1 exit status
# make: *** [Makefile:1326: runtime/sak] Error 1
# make: *** Waiting for unfinished jobs…

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build ocaml-variants 5.3.0+trunk
└─
┌─ The following changes have been performed (the rest was aborted)
│ ✶ install base-bigarray base
│ ✶ install base-threads base
│ ✶ install base-unix base
└─
# Run for /f “tokens=*” %i in (‘opam env --switch=5.3.0+trunk’) do @%i to update the current shell environment
Switch initialisation failed: clean up? (‘n’ will leave the switch partially installed) [y/n] y

Also, I don’t know if it helps in any way, when I switch to bash everything works fine. Which doesn’t help me (I guess) because I want to use VS Code as my IDE.

Hmm, there’s still something unexpected about your setup: what’s your PATH? In particular, it’s unexpected that you’re picking up a ucrt64 installation of MSYS2 (OCaml doesn’t support that). Could you also post the output of opam config report and opam config list?

When you’re switching to bash, exactly how are you doing that (i.e. what command do you run or shortcut do you use)?

Sorry, i am a beginner. How do I paste my PATH here? Do you mean the all environment variables in my PATH? if so I can’t copy paste all that here, but I have attached a screenshot:

C:\Users\omerk>opam config report

# opam config report
# opam-version         2.2.0
# self-upgrade         no
# system               arch=x86_64 os=win32 os-distribution=msys2 os-version=10.0.19041
# solver               builtin-mccs+glpk
# install-criteria     -removed,-count[avoid-version,changed],-count[version-lag,request],-count[version-lag,changed],-count[missing-depexts,changed],-changed
# upgrade-criteria     -removed,-count[avoid-version,changed],-count[version-lag,solution],-count[missing-depexts,changed],-new
# jobs                 11
[ERROR] No config file found for switch playground. Switch broken?
# repositories         1 (http), 1 (version-controlled) (default repo at 2b6e600e)
# pinned               0
# current-switch       playground
# invariant            [  ]
# compiler-packages    none
C:\Users\omerk>opam config list

<><> Global opam variables ><><><><><><><><><><><><><><><><><><><><><><><><><><>
arch                      x86_64                                                                          #
          Inferred from system
exe                       .exe                                                                            #
          Suffix needed for executable filenames (Windows)
jobs                      11                                                                              #
          The number of parallel jobs set up in opam configuration
make                      make                                                                            #
          The 'make' command to use
mingw-chost               x86_64-w64-mingw32                                                              #
          Set through 'opam var'
mingw-package-prefix      mingw-w64-clang-x86_64                                                          #
          Set through 'opam var'
mingw-prefix              /clang64                                                                        #
          Set through 'opam var'
msys2-nativedir           C:\Users\omerk\AppData\Local\Programs\DkMLNative\tools\MSYS2                    #
          Set through 'opam var'
msystem                   CLANG64                                                                         #
          Set through 'opam var'
msystem-carch             x86_64                                                                          #
          Set through 'opam var'
msystem-chost             x86_64-w64-mingw32                                                              #
          Set through 'opam var'
msystem-prefix            /clang64                                                                        #
          Set through 'opam var'
opam-version              2.2.0                                                                           #
          The currently running opam version
os                        win32                                                                           #
          Inferred from system
os-distribution           msys2                                                                           #
          Set through 'opam var'
os-family                 windows                                                                         #
          Inferred from system
os-version                10.0.19041                                                                      #
          Inferred from system
root                      C:\Users\omerk\AppData\Local\opam                                               #
          The current opam root directory
switch                    playground                                                                      #
          The identifier of the current switch
sys-ocaml-arch                                                                                            #
          Target architecture of the OCaml compiler present on your system
sys-ocaml-cc                                                                                              #
          Host C Compiler type of the OCaml compiler present on your system
sys-ocaml-libc                                                                                            #
          Host C Runtime Library type of the OCaml compiler present on your system
sys-ocaml-system                                                                                          #
          Target system of the OCaml compiler present on your system
sys-ocaml-version                                                                                         #
          OCaml version present on your system independently of opam, if any
sys-pkg-manager-cmd-msys2 C:\Users\omerk\AppData\Local\Programs\DkMLNative\tools\MSYS2\usr\bin\pacman.exe #
          Set through 'opam var'

<><> Configuration variables from the current switch ><><><><><><><><><><><><><>
prefix   C:\Users\omerk\AppData\Local\opam\playground
lib      C:\Users\omerk\AppData\Local\opam\playground\lib
bin      C:\Users\omerk\AppData\Local\opam\playground\bin
sbin     C:\Users\omerk\AppData\Local\opam\playground\sbin
share    C:\Users\omerk\AppData\Local\opam\playground\share
doc      C:\Users\omerk\AppData\Local\opam\playground\doc
etc      C:\Users\omerk\AppData\Local\opam\playground\etc
man      C:\Users\omerk\AppData\Local\opam\playground\man
toplevel C:\Users\omerk\AppData\Local\opam\playground\lib\toplevel
stublibs C:\Users\omerk\AppData\Local\opam\playground\lib\stublibs

<><> Package variables ('opam var --package PKG' to show) <><><><><><><><><><><>
PKG:name       # Name of the package
PKG:version    # Version of the package
PKG:depends    # Resolved direct dependencies of the package
PKG:installed  # Whether the package is installed
PKG:enable     # Takes the value "enable" or "disable" depending on whether the package is installed
PKG:pinned     # Whether the package is pinned
PKG:bin        # Binary directory for this package
PKG:sbin       # System binary directory for this package
PKG:lib        # Library directory for this package
PKG:man        # Man directory for this package
PKG:doc        # Doc directory for this package
PKG:share      # Share directory for this package
PKG:etc        # Etc directory for this package
PKG:build      # Directory where the package was built
PKG:hash       # Hash of the package archive
PKG:dev        # True if this is a development package
PKG:build-id   # A hash identifying the precise package version with all its dependencies
PKG:opamfile   # Path of the current opam file

I enter bash simply with: > bash

Oops, sorry - from the Command Prompt that’s just echo %PATH%. When pasting the text, it’s worth putting it a codeblock which just means having three backticks in a row on a line before and after (I edited your last reply just to reformat that).

Ah - I can see from the report that you’ve got a DkML installation - is that from a previous attempt?

I will guess that if you run where bash, the first line is C:\msys64\usr\bin\bash.exe? What does opam repo --set-default show?

1 Like

My PATH:

c:\program files (x86)\common files\oracle\java\javapath;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\windows\system32\openssh\;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\windows\system32\openssh\;c:\program files\microsoft sql server\130\tools\binn\;c:\program files\git\cmd;c:\program files\miktex\miktex\bin\x64\;c:\ffmpeg;c:\sox-14-4-2;c:\program files (x86)\pdftk\bin\;c:\mingw64\bin;c:\program files\dotnet\;c:\program files (x86)\smlnj\bin\;c:\program files\nvidia corporation\nvidia nvdlisr;c:\program files\tesseract-ocr;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\MATLAB\R2024a\bin;;C:\ProgramData\chocolatey\bin;C:\Users\omerk\AppData\Local\Programs\opam\bin;C:\Users\omerk\AppData\Local\Programs\Python\Python310\Scripts\;C:\Users\omerk\AppData\Local\Programs\Python\Python310\;C:\Users\omerk\AppData\Local\Programs\Python\Python39\Scripts\;C:\Users\omerk\AppData\Local\Programs\Python\Python39\;C:\Program Files (x86)\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files (x86)\Microsoft Visual Studio\Common\Tools;C:\Program Files (x86)\Microsoft Visual Studio\VC98\bin;C:\Users\omerk\AppData\Local\Microsoft\WindowsApps;C:\Users\omerk\AppData\Local\GitHubDesktop\bin;C:\Users\omerk\AppData\Local\Programs\MiKTeX\miktex\bin\x64\;C:\Users\omerk\AppData\Local\Programs\Microsoft VS Code\bin;C:\msys64\ucrt64\bin;C:\msys64\usr\bin;C:\msys64\mingw64\bin;C:\Users\omerk\AppData\Roaming\npm;

I would guess that DkML is installed from previous attempt.

C:\Users\omerk>where bash
c:\Windows\System32\bash.exe
C:\msys64\usr\bin\bash.exe

C:\Users\omerk> opam repo --set-default
<><> Default repository configuration (for newly created switches) ><><><><><><>
1 default https://opam.ocaml.org

Aha - I think I finally see! You ended up with both an “OCaml for Windows” .opam folder and you had a previous DkML root.

I think that if you delete / move somewhere else C:\Users\omerk\AppData\Local\opam and re-run opam init, you’ll get many more menus asking how you’d like to set-up opam and you should then end up with an OCaml 5.2.0 switch at the end of opam init. I’m assuming that you’re not interested in keeping the DkML opam root around (the opam config report suggests that that root hasn’t had anything done with it).

I have deleted the opam folder.
What should I choose here? I think I have chosen 1st because 2nd option didn’t work even though it was recommended.

How should opam obtain Unix tools?
> 1. Use tools found in PATH (MSYS2 installation at C:\msys64)
  2. Automatically create an internal Cygwin installation that will be managed by opam (recommended)
  3. Use MSYS2 installation found in C:\msys64
  4. Use another existing Cygwin/MSYS2 installation
  5. Abort initialisation

I’m asking because I don’t want to put you through all the hassle again :smiley: . Also, the problems I have faced might have been a product of this choice here.

Either should work fine - although what actually happened when you picked option 2 (i.e. what do you mean by “2nd option didn’t work”?).

Don’t worry at all - it’s really helpful to know about the problems, and we get bug reports and user experiences which we can feed into making it better in future (so I gain, too :smiley:)

2 Likes

Thank, you! 2nd option worked this time. I don’t know what went wrong the first time. Now I have problem downloading ocaml-lsp-server but I’ll create a seperate issue for that.

2 Likes