electrum icon indicating copy to clipboard operation
electrum copied to clipboard

How to get libsecp256k1 when running from source on Windows?

Open nc50lc opened this issue 5 years ago • 15 comments

Tested on Feb10 Build to the Latest Build. OS: Windows10 Python versions: 3.6.1 and 3.8 All other dependencies are installed

When trying to run Electrum: C:\Python\Python361>python electrum-master/run_electrum

E | ecc_fast | libsecp256k1 library failed to load Error: Failed to load libsecp256k1.

libsecp256k1 was installed through: C:\Python\Python361>python -m pip install libsecp256k1

Requirement already satisfied: libsecp256k1 in c:\python\python361\lib\site-packages (0.1)

In comparison, the dev build copy that I have downloaded last February 5 is working despite not having libsecp256k1. It's just crashing when I'm trying to enable lightning due to obvious reasons.

This might be caused by this PR: https://github.com/spesmilo/electrum/pull/5947 "make libsecp256k1 a mandatory dependency"

nc50lc avatar Feb 21 '20 03:02 nc50lc

Like the README says, libsecp256k1 is a non-python dependency; you should not install it via pip.

libsecp256k1 was installed through: C:\Python\Python361>python -m pip install libsecp256k1 Requirement already satisfied: libsecp256k1 in c:\python\python361\lib\site-packages (0.1)

This package you installed is named libsecp256k1 but it is virtually empty. Someone is probably just namesquatting it.

What you will need is a dll, named libsecp256k1-0.dll, e.g. placed into the inner "electrum" folder. As the README says, we provide a script to build this yourself when running from source, contrib/make_libsecp256k1.sh, however atm this script only works on Unix-like systems (Linux/Mac).

Our own build script for the Windows binaries is cross-compiling from Linux to Windows. If you have access to a Linux machine (e.g. VM) or perhaps even using WSL (Windows Subsystem for Linux), you can cross-compile from there to Windows this dll.

Whether you need a 32 bit or a 64 bit binary depends on the Python interpreter you have installed. To compile a 32 bit (x86) dll, run:

GCC_TRIPLET_HOST="i686-w64-mingw32" ./contrib/make_libsecp256k1.sh

To compile a 64 bit (x86_64, amd64) dll, run:

GCC_TRIPLET_HOST="x86_64-w64-mingw32" ./contrib/make_libsecp256k1.sh

I guess this should be made easier... We weren't/aren't sure how many people there are running from source on Windows.

SomberNight avatar Feb 21 '20 04:02 SomberNight

Thanks! I'll try it later. But I guess I can close this issue now.

nc50lc avatar Feb 21 '20 05:02 nc50lc

I can't seem to get this to work either... I compiled libsecp256k1 using the .sh in the contrib folder as advised and then copied the .dll and the .so that it generated to my Windows box...

Still getting:

E | ecc_fast | libsecp256k1 library failed to load Error: Failed to load libsecp256k1.

Untitled

After hacking in some debug into ecc_fast.py

E | ecc_fast | LibPath: E:\electrum-master\electrum\libsecp256k1-0.dll WARNING: [WinError 193] %1 is not a valid Win32 application E | ecc_fast | LibPath: libsecp256k1-0.dll WARNING: [WinError 193] %1 is not a valid Win32 application

Seems the .dll being produced isn't correct? ???

HardCorePawn avatar Feb 21 '20 06:02 HardCorePawn

@HardCorePawn

[WinError 193] %1 is not a valid Win32 application

I get that exception if the dll is for the wrong architecture (32 vs 64 bit).


Let's keep this issue open, as the current workaround is not ideal.

SomberNight avatar Feb 21 '20 14:02 SomberNight

Turns out that: sudo apt-get install gcc-mingw-w64

Is a "good idea"™ if you're building this outside of the build-wine docker "fresh_clone" thing ;)

Not sure why it didn't complain and still produced a .dll file earlier? Anyway, it seems to have produced a "proper" x64 bit .dll file now

22/02/2020 08:45 743,971 libsecp256k1-0.dll

And with that copied over to the Windows 10 box and put in the /electrum-master/electrum directory, Electrum is starting up OK when running from source

HardCorePawn avatar Feb 21 '20 19:02 HardCorePawn

Download the raw nupkg file from https://www.nuget.org/packages/Secp256k1.Net (use "Download package" link in "Info" section on the right), unzip the file, extract libsecp256k1.dll from runtimes\win-x86\native or runtimes\win-x64\native, place it as libsecp256k1-0.dll in the electrum project folder.

boskowski avatar May 19 '20 15:05 boskowski

On my station from my MINGW64 shell on Windows 10

pacman -S git python-pip base-devel mingw-w64-x86_64-toolchain
pacman -S mingw-w64-x86_64-python-pyqt5 mingw-w64-x86_64-python-cryptography
git clone https://github.com/spesmilo/electrum.git
cd electrum
git checkout tags/4.0.0b0 -b 4.0.0.tmp
GCC_TRIPLET_HOST="x86_64-w64-mingw32" ./contrib/make_libsecp256k1.sh
cp /mingw64/bin/libgmp-10.dll electrum
python -m venv --system-site-packages .venv
source .venv/bin/activate
.venv/bin/python -m pip install --upgrade setuptools
.venv/bin/python -m pip install --upgrade pip
.venv/bin/python -m pip install -e .[full]
.venv/bin/python run_electrum

Everything worked fine. Verified with a Trezor-1

brianddk avatar Jun 24 '20 21:06 brianddk

I've built a 64-bit DLL for people - that trust me - to use. libsecp256k1-0.zip

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

I've built this libsecp256k1-0.dll now, for 64-bit python.
The build should be reproducible.

$ sha256sum electrum/libsecp256k1-0.dll 
9e719c3ccaa946f08983f148b5880527ed6fcab718b1502cb916b52a9380a1e9  electrum/libsecp256k1-0.dll

Details:

$ GCC_STRIP_BINARIES="1" GCC_TRIPLET_HOST="x86_64-w64-mingw32" ./contrib/make_libsecp256k1.sh

$ git log -n 1
commit b7cc5f329c7d85f416cc35af00d11fe93c74ec09 (HEAD -> master, spesmilo/master, spesmilo/HEAD)

https://github.com/spesmilo/electrum/blob/b7cc5f329c7d85f416cc35af00d11fe93c74ec09/contrib/make_libsecp256k1.sh

LIBSECP_VERSION="dbd41db16a0e91b2566820898a3ab2d7dad4fe00"


ghost43
2021-07-12
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEbXohFtqQngCsIRCLsztfIyxicekFAmDsUwMACgkQsztfIyxi
cekCMA//clofhfhKZ4d0eWcAVm8ESe4VJApn5SshcmAcpnofFRKqHN47UxFqfyX+
18N6RVXm6Pk5ivPlAduVGqESWRCQfz5THNok8vYhJyAcFnbTJw7m4A5qn0+f19U/
zQ1qQFiEAhjottnQEfjc6Dk+ffcl6HgFtyqkDczm5xuiV9e2mdLeRUeC1OCUtHLr
lMUCil/O0BFEYJmkrZ0tW0pEdm8Qgk3cWlOox+kTq7HAcLp7jimwIPippTnRPGzn
cMg7eVrMAuB1fv8AVhNp/Sq+PStuSxisfTtZuSR9lVnMFqLqZsxHAFasvuYDup2v
C5jaLo6jCRjlzWblqfOB1v5g+wR0iruwVpwsTZyFg7am7jw/XwBQkWVmz86tUq0l
z4wYK8m2tmc977KWTXJ5bzCoUwKCyQ9xHkD4ohGLp72y+PUKJUN6PtuuzHwanHQD
MgxBiOR1j2bqzm5lgar13JVFIQKssEBuyCiR6CVpfiYzBBiXZiig2alrryIjOkTP
mgzNK+XNEM4rthyHGMT/qaLk1+8UyPuHqhEEnIAOJo7K1R4QtE8efOaot13f1JD4
tOMsQLuiX08plvzbV6gQFQLIoxyi75GPzpJrlTjI97MVzw4DvRq+/kp/ELYQkOoL
KG+w9PzSPFWV8arTr1futQOaLf6nSdgNLwVscuoB447yBwUzDgk=
=8aWU
-----END PGP SIGNATURE-----

SomberNight avatar Jul 12 '21 14:07 SomberNight

Thank you, guys!

I was able to build libsecp256k1-0.dll following your advices.

Now you can easily build your own libsecp256k1-0.dll (x86 and x64) using docker and https://github.com/Stanislav-Povolotsky/electrum-libsecp256k1-0.dll-builder

Stanislav-Povolotsky avatar Aug 28 '21 23:08 Stanislav-Povolotsky

Like the README says, libsecp256k1 is a non-python dependency; you should not install it via pip.

libsecp256k1 was installed through: C:\Python\Python361>python -m pip install libsecp256k1 Requirement already satisfied: libsecp256k1 in c:\python\python361\lib\site-packages (0.1)

This package you installed is named libsecp256k1 but it is virtually empty. Someone is probably just namesquatting it.

What you will need is a dll, named libsecp256k1-0.dll, e.g. placed into the inner "electrum" folder. As the README says, we provide a script to build this yourself when running from source, contrib/make_libsecp256k1.sh, however atm this script only works on Unix-like systems (Linux/Mac).

Our own build script for the Windows binaries is cross-compiling from Linux to Windows. If you have access to a Linux machine (e.g. VM) or perhaps even using WSL (Windows Subsystem for Linux), you can cross-compile from there to Windows this dll.

Whether you need a 32 bit or a 64 bit binary depends on the Python interpreter you have installed. To compile a 32 bit (x86) dll, run:

GCC_TRIPLET_HOST="i686-w64-mingw32" ./contrib/make_libsecp256k1.sh

To compile a 64 bit (x86_64, amd64) dll, run:

GCC_TRIPLET_HOST="x86_64-w64-mingw32" ./contrib/make_libsecp256k1.sh

I guess this should be made easier... We weren't/aren't sure how many people there are running from source on Windows.

after doing this command through WSL I get the error "collect2: error: ld returned 1 exit status make: *** [Makefile:910: libsecp256k1.la] Error 1 🗯 ERROR: Could not build secp256k1"

developeroka avatar Sep 19 '21 10:09 developeroka

Like the README says, libsecp256k1 is a non-python dependency; you should not install it via pip.

libsecp256k1 was installed through: C:\Python\Python361>python -m pip install libsecp256k1 Requirement already satisfied: libsecp256k1 in c:\python\python361\lib\site-packages (0.1)

This package you installed is named libsecp256k1 but it is virtually empty. Someone is probably just namesquatting it. What you will need is a dll, named libsecp256k1-0.dll, e.g. placed into the inner "electrum" folder. As the README says, we provide a script to build this yourself when running from source, contrib/make_libsecp256k1.sh, however atm this script only works on Unix-like systems (Linux/Mac). Our own build script for the Windows binaries is cross-compiling from Linux to Windows. If you have access to a Linux machine (e.g. VM) or perhaps even using WSL (Windows Subsystem for Linux), you can cross-compile from there to Windows this dll. Whether you need a 32 bit or a 64 bit binary depends on the Python interpreter you have installed. To compile a 32 bit (x86) dll, run:

GCC_TRIPLET_HOST="i686-w64-mingw32" ./contrib/make_libsecp256k1.sh

To compile a 64 bit (x86_64, amd64) dll, run:

GCC_TRIPLET_HOST="x86_64-w64-mingw32" ./contrib/make_libsecp256k1.sh

I guess this should be made easier... We weren't/aren't sure how many people there are running from source on Windows.

after doing this command through WSL I get the error "collect2: error: ld returned 1 exit status make: *** [Makefile:910: libsecp256k1.la] Error 1 🗯 ERROR: Could not build secp256k1"

I made it work thank you all

developeroka avatar Sep 19 '21 10:09 developeroka

Note: I've added a "Running Electrum from source on Windows" guide now in https://github.com/spesmilo/electrum/commit/941db4214c74d51c193c942e9e7ff633a5ff3a36. It is building on brianddk's comment (https://github.com/spesmilo/electrum/issues/5976#issuecomment-649068984) using MSYS2.

SomberNight avatar Jun 09 '22 16:06 SomberNight

Note: I've added a "Running Electrum from source on Windows" guide now in 941db42. It is building on brianddk's comment (#5976 (comment)) using MSYS2.

I followed this the MSYS2 method and the .dll was made no problem but when I get to the final step I get this error:

python3 ./run_electrum Error: No module named 'dns'. Try 'sudo python3 -m pip install '

GiverofMemory avatar Sep 19 '22 21:09 GiverofMemory

try python3 -m pip install dnspython

accumulator avatar Sep 20 '22 14:09 accumulator

I followed this the MSYS2 method and the .dll was made no problem but when I get to the final step I get this error:

python3 ./run_electrum Error: No module named 'dns'. Try 'sudo python3 -m pip install '

The dependencies should have been installed as part of step 1:

Run install (this should install most dependencies): > python3 -m pip install --user -e ".[gui,crypto]"

Try running electrum in the original shell you used for those steps, e.g. powershell/cmd/"windows terminal", instead of msys2 (which is used solely for building libsecp).

SomberNight avatar Sep 20 '22 14:09 SomberNight