How to Install M2crypto on Windows
Question:
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)gfortranbingcc.exe -mno-cygwin -mdll -O -Wall -IC:Pyth
on27include -IC:Python27PC -Ic:pkginclude -Ic:usersevboappdatalocaltem
ppip_build_evbom2cryptoSWIG -c SWIG/_m2crypto_wrap.c -o buildtemp.win32-2.7
Releaseswig_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?
Answers:
I got lucky – there’s an unofficial binary installer in lieu of chandlerproject.org/bin/view/Projects/MeTooCrypto being down:
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/m2crypto →
https://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.
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.
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:
- 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
- In the installer, select "C++ Build Tools", install, and reboot if necessary.
- 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
- 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'))
- Install
swig
with Chocolatey
(in PowerShell
). choco install -r -y swig
- 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.
- 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
- Use
cd
to change into the directory m2crypto
was cloned/extracted to.
- Assuming
python
launches your desired Python interpreter version, run python setup.py build --openssl="C:Program FilesOpenSSL-Win64" --bundledlls
, replacing C:Program FilesOpenSSL-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.)
- Generate the installable files.
python.exe setup.py bdist_wheel bdist_wininst bdist_msi
.
- 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.
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
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.
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)gfortranbingcc.exe -mno-cygwin -mdll -O -Wall -IC:Pyth
on27include -IC:Python27PC -Ic:pkginclude -Ic:usersevboappdatalocaltem
ppip_build_evbom2cryptoSWIG -c SWIG/_m2crypto_wrap.c -o buildtemp.win32-2.7
Releaseswig_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?
I got lucky – there’s an unofficial binary installer in lieu of chandlerproject.org/bin/view/Projects/MeTooCrypto being down:
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/m2crypto →
https://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.
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.
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:
- 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 - In the installer, select "C++ Build Tools", install, and reboot if necessary.
- Install the latest full (not
Light
)OpenSSL
for your architecture (Win64
/Win32
). Current version as of this writing is1.1.1d
. Make note of the directory to which you installOpenSSL
. https://slproweb.com/products/Win32OpenSSL.html - In
PowerShell
, install theChocolatey
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'))
- Install
swig
withChocolatey
(inPowerShell
).choco install -r -y swig
- Install the
pywin32
dependency. Runpip install pywin32
. If you have problems, try first runningpip install wheel
. To getpip
to target a specific Python installation, try launching it usingpy -[version] -m pip install [module]
. Note: you may need to use an elevated (administrator)PowerShell
to install Python modules. - Get the latest
m2crypto
code. If you havegit
installed, rungit clone https://gitlab.com/m2crypto/m2crypto
. Otherwise, download and extract the code from GitLab: https://gitlab.com/m2crypto/m2crypto/-/archive/master/m2crypto-master.zip - Use
cd
to change into the directorym2crypto
was cloned/extracted to. - Assuming
python
launches your desired Python interpreter version, runpython setup.py build --openssl="C:Program FilesOpenSSL-Win64" --bundledlls
, replacingC:Program FilesOpenSSL-Win64
with the directory to which you installedOpenSSL
. (On some systems you can use thepy
launcher to specify a Python version to use, runpy -h
for more information.) - Generate the installable files.
python.exe setup.py bdist_wheel bdist_wininst bdist_msi
. - Install the module.
cd
into thedist
directory and runpip install M2Crypto-0.35.2-cp38-cp38-win_amd64.whl
, replacing the filename with the generated.whl
file. If you have problems, try first runningpip install wheel
. To getpip
to target a specific Python installation, try launching it usingpy -[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.
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
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.