Installing M2Crypto Python Library on Windows Machine for Certificate Authentication
I'm running into a few errors trying to install M2Crypto on a windows machine. I've done a fair bit of research and it seems to be a common problem with the library.
Wondering if anyone here has experienced similar issues and resolved them? I'm using Win10(64 bit), Python 3.8 through Pycharm. Pip 20.1.1. I've tried to install both M2Crypto and M2CryptoWin64 but I've had no luck.
Some builds form2cryptofor 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.whlfile, see step 11 of my build tutorial below.
I have also attached them2cryptomodule 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.M2Crypto-0.35.2.win-amd64-py3.8.zip
However, if you are unable to find a build that matches your Python version and system type and architecture, you may need to manually buildm2crypto. 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:
InPowerShell, install theChocolateypackage 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 thepywin32dependency. Runpip install pywin32. If you have problems, try first runningpip install wheel. To getpipto target a specific Python installation, try launching it usingpy -[version] -m pip install [module]. Note: you may need to use an elevated (administrator)PowerShellto install Python modules.
Usecdto change into the directorym2cryptowas cloned/extracted to.
Assumingpythonlaunches your desired Python interpreter version, runpython setup.py build --openssl="C:\Program Files\OpenSSL-Win64" --bundledlls, replacingC:\Program Files\OpenSSL-Win64with the directory to which you installedOpenSSL. (On some systems you can use thepylauncher to specify a Python version to use, runpy -hfor more information.)
Generate the installable files.python.exe setup.py bdist_wheel bdist_wininst bdist_msi.
Install the module.cdinto thedistdirectory and runpip install M2Crypto-0.35.2-cp38-cp38-win_amd64.whl, replacing the filename with the generated.whlfile. If you have problems, try first runningpip install wheel. To getpipto target a specific Python installation, try launching it usingpy -[version] -m pip install [module]. Alternatively, you can run the generated.exeor.msiinstaller. Note: you may need to use an elevated (administrator)PowerShellto install Python modules.
I've installed M2Crypto successfully but am now getting an error:
File "C:\Users\USERNAME\Desktop\PATH\anaplan_auth.py", line 13, in <module> from M2Crypto import EVP, RSA File "C:\Users\USERNAME\Desktop\PATH\venv\lib\site-packages\M2Crypto\__init__.py", line 22, in <module> import __m2crypto ModuleNotFoundError: No module named '__m2crypto'
Have you ran into this error before? I've seen a few Google results with the same error for different things? Once I have this all setup I think I'll create a wiki article for setting up Certificate Authentication on Windows systems.
I tried to uninstall and re-install but that hasn't worked. I'm still getting the error:
File "C:\Users\PATH\TO\FILES\anaplan_auth.py", line 13, in <module> from M2Crypto import EVP, RSA File "C:\Users\PATH\TO\FILES\\venv\lib\site-packages\M2Crypto\__init__.py", line 22, in <module> import __m2crypto ModuleNotFoundError: No module named '__m2crypto'
File "C:\Users\Sam\Desktop\Data_Integration_Anaplan\anaplan_auth.py", line 13, in <module> from M2Crypto import EVP, RSA File "C:\Users\Sam\Desktop\Data_Integration_Anaplan\venv\lib\site-packages\M2Crypto\__init__.py", line 23, in <module> import m2 ModuleNotFoundError: No module named 'm2'