17

After installing OpenSSL, downloading the pre-built Swig executable, and ensuring the openssl libraries are located in the default c:\pkg, pip install m2crypto results in:

...
C:\Program Files (x86)\gfortran\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Pyth
on27\include -IC:\Python27\PC -Ic:\pkg\include -Ic:\users\evbo\appdata\local\tem
p\pip_build_evbo\m2crypto\SWIG -c SWIG/_m2crypto_wrap.c -o build\temp.win32-2.7\
Release\swig\_m2crypto_wrap.o -DTHREADING

gcc: error: unrecognized command line option '-mno-cygwin'

error: command 'gcc' failed with exit status 1

It seems the binary installer solution for M2crypto is no longer available and I don't see any mistakes I've made based on the M2crypto install doc.

How might I resolve this install issue? Is there a dependency on older versions of GCC?

Community
  • 1
  • 1
ecoe
  • 4,994
  • 7
  • 54
  • 72
  • 1
    *"Are there any succint instructions for how to install M2crypto?"* - that's probably going to get the question closed. You have to find your own offsite resources. – jww Aug 04 '14 at 01:59
  • @jww thanks, I clarified my answer to focus specifically on the install issue I'm having – ecoe Aug 04 '14 at 13:49
  • You might try setting the path. Open a command prompt, and then `set PATH=c:\pkg\include\openssl;%PATH%`. Windows also uses `INCLUDE`, so you might also `set INCLUDE=c:\pkg\include\openssl`. That's assumming a header is located at `c:\pkg\include\openssl\include\openssl\opensslv.h`. Note: I had a problem once with the double `include\openssl`. So you might change the directory to `c:\pkg\include\openssl-xxx`. – jww Aug 04 '14 at 13:58
  • The best I've found so far is this tutorial -http://www.gooli.org/blog/building-m2crypto-on-windows/ although there's supposedly a Windows build on the Project Chandler site (http://chandlerproject.org/bin/view/Projects/MeTooCrypto), but it's down right now. – Mike Driscoll Aug 04 '14 at 20:01
  • @jww thanks but actually openssl expects the libraries to be in a hard-coded location unless you build it yourself (default is `c:\pkg`) and yes @MikeDriscoll, I too would prefer an installer... when it comes back online! – ecoe Aug 04 '14 at 22:18

6 Answers6

7

I got lucky - there's an unofficial binary installer in lieu of chandlerproject.org/bin/view/Projects/MeTooCrypto being down:

https://github.com/saltstack/salt-windows-install/blob/master/deps/win32-py2.7/M2Crypto-0.21.1.win32-py2.7.msi

ecoe
  • 4,994
  • 7
  • 54
  • 72
  • 2
    In case it's not obvious, you have to click "Raw" to download the actual installer. – Chris Rae Nov 14 '14 at 22:41
  • I got the same issue, but installing that .msi didn't fix it – Ambrose Leung Sep 03 '15 at 17:31
  • 1
    @Frederic The issue I was having involved installing M2Crypto, which the .msi is quite robust at ensuring success with. In other words, there is no need to run `pip install m2crypto` after running the .msi file. – ecoe Sep 12 '15 at 14:32
  • 1
    Very nice find. It makes installing offline easy. Thanks for posting. I wonder what the best way to vet the binaries installed by this msi are? – ryyker Feb 01 '18 at 17:18
3

This answer is based on the GitHub comment at https://github.com/iOSForensics/pymobiledevice/issues/25#issuecomment-576119104, for a Python module that requires m2crypto.

Some builds for m2crypto for specific versions of Python are available from their CI: https://ci.appveyor.com/project/m2crypto/m2crypto/history. Try selecting a version, selecting a job that matches your Python version, then going to the "Artifacts" tab and downloading an installer. To install a .whl file, see step 11 of my build tutorial below.

M2Crypto-0.35.2.win-amd64-py3.8.zip is the m2crypto module that I have built on Windows 10 x64, Python 3.8.1. It should work on any x64-based version of Windows with any version of Python 3.8.X.

However, if you are unable to find a build that matches your Python version and system type and architecture, you may need to manually build m2crypto. I adapted the build steps from their CI build scripts: https://gitlab.com/m2crypto/m2crypto/blob/master/appveyor.yml. I built the module by doing the following:

  1. Install the latest Build Tools for Visual Studio 2019. See https://visualstudio.microsoft.com/downloads/ under "All Downloads" -> "Tools for Visual Studio 2019". This direct link was active as of this writing: https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16
  2. In the installer, select "C++ Build Tools", install, and reboot if necessary.
  3. Install the latest full (not Light) OpenSSL for your architecture (Win64/Win32). Current version as of this writing is 1.1.1d. Make note of the directory to which you install OpenSSL. https://slproweb.com/products/Win32OpenSSL.html
  4. In PowerShell, install the Chocolatey package manager. I used this command from their website: Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  5. Install swig with Chocolatey (in PowerShell). choco install -r -y swig
  6. Install the pywin32 dependency. Run pip install pywin32. If you have problems, try first running pip install wheel. To get pip to target a specific Python installation, try launching it using py -[version] -m pip install [module]. Note: you may need to use an elevated (administrator) PowerShell to install Python modules.
  7. Get the latest m2crypto code. If you have git installed, run git clone https://gitlab.com/m2crypto/m2crypto. Otherwise, download and extract the code from GitLab: https://gitlab.com/m2crypto/m2crypto/-/archive/master/m2crypto-master.zip
  8. Use cd to change into the directory m2crypto was cloned/extracted to.
  9. Assuming python launches your desired Python interpreter version, run python setup.py build --openssl="C:\Program Files\OpenSSL-Win64" --bundledlls, replacing C:\Program Files\OpenSSL-Win64 with the directory to which you installed OpenSSL. (On some systems you can use the py launcher to specify a Python version to use, run py -h for more information.)
  10. Generate the installable files. python.exe setup.py bdist_wheel bdist_wininst bdist_msi.
  11. Install the module. cd into the dist directory and run pip install M2Crypto-0.35.2-cp38-cp38-win_amd64.whl, replacing the filename with the generated .whl file. If you have problems, try first running pip install wheel. To get pip to target a specific Python installation, try launching it using py -[version] -m pip install [module]. Alternatively, you can run the generated .exe or .msi installer. Note: you may need to use an elevated (administrator) PowerShell to install Python modules.
John Vandenberg
  • 474
  • 6
  • 16
user9811991
  • 317
  • 5
  • 14
  • 1
    the first link is golden, just downloaded *M2Crypto-0.37.1.win-amd64-py3.7.msi* - it can be so easy – alecxs Dec 19 '20 at 10:03
  • Note at the moment m2crypto doesnt support openssl 3 (e.g. https://gitlab.com/m2crypto/m2crypto/-/issues/302and others), so you need to install the latest v1.1.1, i.e. v1.1.1L at the moment. – John Vandenberg Oct 18 '21 at 05:09
  • https://ci.appveyor.com/project/m2crypto/m2crypto/history builds have been failing, and artifacts are only kept for one month now, so the first suggestion doesnt work. – John Vandenberg Oct 18 '21 at 05:31
2

The https://gitlab.com/m2crypto/m2crypto project provides Windows builds of M2Crypto.

You can find wheels for current Python versions from their AppVeyor builds at https://ci.appveyor.com/project/m2crypto/m2crypto.

For example, to install M2Crypto 0.37.1 from https://ci.appveyor.com/project/m2crypto/m2cryptohttps://ci.appveyor.com/project/m2crypto/m2crypto/builds/37187357/job/5c56adinoe9l8kng/artifacts with pip for 64-bit Python 3.8, run:

pip install \
  https://ci.appveyor.com/api/buildjobs/5c56adinoe9l8kng/artifacts/dist/M2Crypto-0.37.1-cp38-cp38-win_amd64.whl

NB! The artifacts may expire in AppVeyor, see this bug for updates.

mrts
  • 16,697
  • 8
  • 89
  • 72
1

It's late 2019 and installing M2Crypto is still a pain! After a ton of Googling, finally got it down to the steps below:

pip install wheel
pip install M2CryptoWin32

Using a fresh Python 2.7.17 32bit install on Windows 10. You might need install http://aka.ms/vcpython27 first.

I'd imagine one should use M2CryptoWin64 instead if you've installed 64-bit Python.

stevetu21
  • 160
  • 1
  • 8
  • M2CryptoWin32 & M2CryptoWin64 havent been updated since 2014, which will make them unsuitable for most. When I tried M2CryptoWin64 on Python 3.7, the result was `ModuleNotFoundError: No module named '__m2crypto'`. Still, the repos https://github.com/dsoprea/M2CryptoWin32 and https://github.com/dsoprea/M2CryptoWin64 might be a useful starting point for someone. – John Vandenberg Oct 18 '21 at 04:41
0

in windows, (python versions 3.7 | 3.8 | 3.9 | 3.10) you can download whl file from here and install it with this command:

python install M2Crypto-0.38.0-cp310-cp310-win_amd64.whl

replace current whl file name.

Ali Fallah
  • 138
  • 8
-1

1~11: https://stackoverflow.com/a/59817750

12: install M2Crypto.whl and adb in one command

pip install M2Crypto-0.38.0-cp310-cp310-win_amd64.whl adb

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 30 '21 at 19:45