M2Crypto installation - m2crypto

I am struggling to get my M2Crypto installation to work
C:\Python27>python
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from M2Crypto import RSA
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\M2Crypto\__init__.py", line 22, in <module>
import __m2crypto
ImportError: No module named __m2crypto
>>>
Not really surprising as there is no __m2crypto module anywhere, but where should it be and where should I get it from?
I have installed M2Crypto from https://pypi.python.org/pypi/M2Crypto by downloading M2Crypto-master and copying the unziped M2Crypto folder to c:\Python27\lib
From M2Crypto I only need the RSA functionality so suggestions involving alternatives to M2Crypto would also be helpful.
Any help highly appreciated

There pretty good instruction on building M2Crypto, I've using myself, here:
http://www.gooli.org/blog/building-m2crypto-on-windows/
Building M2Crypto for Windows
M2Crypto uses a tool called SWIG to help write the Python code that
wraps the OpenSSL library that is written in C, so we’ll have to
download and install it.
Let’s go.
Download the latest SWIG Windows binaries from
http://www.swig.org/download.html .
Unzip and untar the SWIG package to some directory and add that
directory to your PATH.
Download the latest M2Crypto sources from
http://chandlerproject.org/bin/view/Projects/MeTooCrypto.
Unzip and untar the M2Crypto source somewhere and open a command
prompt there.
> python setup.py build_ext –openssl c:/openssl
> python setup.py bdist_wininst
That last command will create a nice M2Crypto-0.18.win32-py2.4.exe
file in the dist subdirectory which you can run to install M2Crypto in
the Python site-packages directory.
To test your build, run python and do import M2Crypto. If you get an
error that says ‘ImportError: DLL load failed with error code 182′,
it’s because the M2Crypto library can’t find the OpenSSL DLLs. You’ll
need to place the libeay32.dll and ssleay32.dll files somewhere python
can find them. The directory in which your script resides is a good
bet.
If you still have problems with building, I'd recently compiled M2Crypto for my needs on Windows 7 x64 - Python 2.7 You can download binary here (M2Crypto-0.22.3.win32-py2.7.exe): https://drive.google.com/file/d/0ByAiJQIq8icYOUNiZEJQQzVhdVU/view?usp=sharing
Good Luck

In Windows, you can install M2Crypto from the project AppVeyor builds, see detailed overview here.
For example, to install M2Crypto 0.37.1 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.

Related

Tensorflow installed can't be imported

I'm trying to import tensorflow. But even after installing it, it doesn't seem to be recognized.
>conda create -n tf tensorflow
>conda activate tf
(tf)>pip install --ignore-installed --upgrade tensorflow==1.15 --user
...
Successfully installed absl-py-0.9.0 astor-0.8.1 gast-0.2.2 google-pasta-0.2.0 grpcio-1.28.1 h5py-2.10.0 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.2.1 numpy-1.18.2 opt-einsum-3.2.0 protobuf-3.11.3 setuptools-46.1.3 six-1.14.0 tensorboard-1.15.0 tensorflow-1.15.0 tensorflow-estimator-1.15.1 termcolor-1.1.0 werkzeug-1.0.1 wheel-0.34.2 wrapt-1.12.1
(tf) C:\Users\antoi\Documents\Programming\Covent Garden\covent_garden_ds>python3 app.py
Traceback (most recent call last):
File "app.py", line 4, in <module>
from tensorflow.keras.callbacks import ModelCheckpoint
ModuleNotFoundError: No module named 'tensorflow'
Python3 is there:
(tf) C:\Users\antoi\Documents\Programming\Covent Garden\covent_garden_ds>where python3
C:\Users\antoi\AppData\Local\Microsoft\WindowsApps\python3.exe
It's not the one I should be using, isn't it?
What version of Python are you running? In order to both successfully import and run the Tensorflow module, you must have the 64 bit version of Python installed. If you are using the latest version of Python, which to the best of my knowledge is 3.8.2, completely uninstall that version of Python, and downgrade to the latest Python version with 64 bit support.
If you follow the output of pip --version to find where your anaconda files are located, you can find the anaconda python executable, usually about two directory levels higher (if pip is in C:\example\anaconda\lib\site-packages, then python is probably in C:\example\anaconda) and use a full path to that python executable to run the file like C:\example\anaconda\python app.py. Or you could update your path environment variable to replace C:\Users\antoi\AppData\Local\Microsoft\WindowsApps\ with the directory containing the anaconda python executable
I've had this same exact issue (but on macOS) several times before I realized what was wrong, and I've seen several others have this issue too. I wish there was a way Python could somehow better regulate this to make sure the default executables for pip and python are always in sync

How to have virtualbox python bindings working with chosen Python version?

I'm using Python3 bindings for virtualbox (pyvbox). It works with the initial python3 version of my system which is 3.7. Now, I would like to use the very same bindings with python3.8. I have installed all needed python3.8 packages, but i get this error:
$ python3
Python 3.8.0 (default, Oct 28 2019, 16:14:01)
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import virtualbox
>>> _vbox = virtualbox.VirtualBox()
m=VBoxPython3_8 x=No module named 'VBoxPython3_8'
m=VBoxPython3 x=No module named 'VBoxPython3'
m=VBoxPython x=/usr/lib/virtualbox/VBoxPython.so: undefined symbol: _Py_ZeroStruct
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home//.local/lib/python3.8/site-packages/virtualbox/library_ext/vbox.py", line 22, in __init__
manager = virtualbox.Manager()
File "/home//.local/lib/python3.8/site-packages/virtualbox/__init__.py", line 145, in __init__
self.manager = vboxapi.VirtualBoxManager(mtype, mparams)
File "/usr/local/lib/python3.8/dist-packages/vboxapi/__init__.py", line 989, in __init__
self.platform = PlatformXPCOM(dPlatformParams)
File "/usr/local/lib/python3.8/dist-packages/vboxapi/__init__.py", line 750, in __init__
import xpcom.vboxxpcom
File "/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/vboxxpcom.py", line 78, in <module>
raise Exception('Cannot find VBoxPython module (tried: %s)' % (', '.join(_asVBoxPythons),))
Exception: Cannot find VBoxPython module (tried: VBoxPython3_8, VBoxPython3, VBoxPython)
I have found that these modules have to be in /usr/lib/virtualbox, which currently contains only these files:
$ ls /usr/lib/virtualbox/ | grep VBoxPython
VBoxPython2_7.so
VBoxPython3_7m.so
VBoxPython.so
These .so files are installed via the virtualbox package. However, I cannot manage to have neither VBoxPython3.so nor VBoxPython3.8.so by reinstalling. I have looked at the virtualbox code and it seems that the c macro PY_VERSION_HEX indicates 3.7 instead of 3.8, which would be caused by the wrong Python.h header being included.
How can I force virtualbox package to include /usr/include/python3.8/Python.h instead of /usr/include/python3.7/Python.h ?
Uninstalling python3.7 is not an option.
The pyvbox package docs (redirected from pyvbox) imply that the .so files aren't installed by it. But, they do note that the Python package is dependent on the VirtualBox SDK. Which, in turn, recommend installing the SDK to the system Python manually. That latest seems irky, especially when done outside a package manager but maybe they know better.
Digging around, I found the .so files are owned by the OS package virtualbox. In other words, virtualbox must be installed with Python3.8 support.
# Who owns/provides this file (use your dist equivalent or duckduckgo)
$ yay -Fy /usr/lib/virtualbox/VBoxPython3_8.so
...
usr/lib/virtualbox/VBoxPython3_8.so is owned by community/virtualbox 6.1.6-1
I suggest you reinstall the virtualbox package for your distribution. Installing the latest version will provide the latest .so library files Virtualbox supports.
Let's test the theory
# Install Virtualbox and the Virtualbox SDK
yay -S virtualbox virtualbox-sdk python-virtualbox
# Assert we aren't getting an error
$ python -c "import virtualbox; _vbox = virtualbox.VirtualBox(); print('Success!')"
Success!
Otherwise, if the package doesn't include 3.8 support, you'll have to compile it yourself while making sure LD_LIBRARY_PATH points to your Python 3.8 dev libraries. But, I strongly recommend against this. It is infinitely better to work along with your package manager and benefit from upstream work.
Good luck!

How to link openCv with Python3 in mac Os

I have two versions of python in my mac os, the first python2.7 which is the default that came with the system. Later I installed python3.7 that I use most of the time.
I have recently installed openCV using homebrew.
When I'm using openCV with python2.7, it's working normally.
But the problem is when I try to use it with python3. Importing cv2 in python3 gives error: ModuleNotFoundError: No module named 'cv2'
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 03:03:55)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable.
Visit http://www.python.org/download/mac/tcltk/ for current
information.
>>> import cv2
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
>>>
Is there anything I can do so that I can link the installed openCV with python3 ??
Thanks for the help
Sorry I cannot give you specifics because your setup is not identical to mine, but I am sure we can get you sorted out.
Firstly, when you install packages, such as OpenCV, they tend to create a directory somewhere called lib which contains the C/C++ functions you can call from that package. Inside that directory, you normally find "shared object libraries" which traditionally end in "XXX.so" on macOS. More interestingly, they also contain a sub-directory called site-packages which contains the Python bindings (links). So, on my system, which is likely different from yours, I can find all those site-packages directories with:
find / -type d -name site-packages 2>/dev/null
Sample Output
/usr/local/lib/python3.7/site-packages
/usr/local/lib/python2.7/site-packages
...
...
/usr/local/Cellar/tbb/2018_U5/lib/python2.7/site-packages
/usr/local/Cellar/vips/8.6.5/lib/python3.7/site-packages
Hopefully, you can see that /usr/local/lib/python3.7/site-packages is looking a very likely candidate for where all the Python v3.7 bindings for OpenCV should be.
Good, so now we know how to find the Python bindings, we need to tell Python that information. How? Well, not unreasonably, Python looks at an environment variable called PYTHONPATH to find its stuff. So, using our skill and judgement we need to marry up what we found in the first step with what we now know from the second step. So we do:
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages
And everything should work. All we need to do is put that in our login profile (probably $HOME/.profile) and we will be ready to go every time we log in.

Can't install lxml with Python3.5, Windows 10, 32 bit

Python 3.5 on Windows 10, 32-bit box; all I want to do is run this:
import quandl
import pandas as pd
import html5lib
import lxml
# retrieve web page with list of 50 states
fiddy_states = pd.read_html('https://simple.wikipedia.or /wiki/List_of_U.S._states')
But for the life of me I can't seem to get a properly installed lxml, which is required by pd.read_html. Following advice from several online sources I have MinGW installed in my system and I have also added the following to C:\Python35-32\Lib\distutils\distutils.cfg:
[build]
compiler=mingw32
I have MinGW installed and included in PATH. I have tried installing lxml using both pip3 as well as the binaries found at Unofficial Windows Binaries for Python Extension Packages.
Here's all installed packages:
['beautifulsoup4==4.4.1', 'cffi==1.6.0', 'cryptography==1.3.2', 'cycler==0.10.0', 'cython==0.24', 'html5lib==0.9999999', 'idna==2.1', 'inflection==0.3.1', 'lxml==3.4.4', 'matplotlib==1.5.1', 'more-itertools==2.2', 'ndg-httpsclient==0.4.0', 'numpy==1.11.0', 'pandas-datareader==0.2.1', 'pandas==0.18.1', 'pip==8.1.2', 'pyasn1==0.1.9', 'pycparser==2.14', 'pyopenssl==16.0.0', 'pyparsing==2.1.4', 'python-dateutil==2.5.3', 'pytz==2016.4', 'quandl==3.0.1', 'requests-file==1.4', 'requests==2.10.0', 'scikit-learn==0.17.1', 'setuptools==18.2', 'six==1.10.0']
As shown above, lxml==3.4.4 appears to be installed, however when I try to run the line containing pd.read_html I get the following error message:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\Jose Manuel\AppData\Local\Programs\Python\Python35-32 \lib\site-packages\pandas\io\html.py", line 874, in read_html
parse_dates, tupleize_cols, thousands, attrs, encoding)
File "C:\Users\Jose Manuel\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pandas\io\html.py", line 726, in _parse
parser = _parser_dispatch(flav)
File "C:\Users\Jose Manuel\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pandas\io\html.py", line 685, in _parser_dispatch
raise ImportError("lxml not found, please install it")
ImportError: lxml not found, please install itenter code here
Your help is very much appreciated
I have been struggling with this today. I found, elsewhere on stackoverflow.com, this two-part and quick solution, which resulted in python no longer complaining when I tried to use lxml:
go to this repository and download a version which matches your Python installation (the version number, and 32- vs 64-bit. I use Python 3.5.1 64-bit, installed on Windows 10, so on that page, I chose lxml-3.6.0-cp35-cp35m-win_amd64.whl. You say you have 32-bit Python, so use a version that matches that (like lxml-3.6.0-cp35-cp35m-win32.whl.
My download directory is d:\Downloads. Python must be in your PATH environment variable for the next step to work. Use a command like the following, changing "D:\Downloads" to the pathname to your download directory. Then, at a DOS prompt, type:
python -m pip install "D:\Downloads\lxml-3.6.0-cp35-cp35m-win_amd64.whl" lxml-3.6.0-cp35-cp35m-win_amd64.whl

Cannot install NumPy from a wheel format

I am trying to install NumPy from a wheel (.whl) file. I get the error:
numpy-1.9.1%2Bmkl-cp34-none-win_amd64.whl is not a supported wheel on this platform.
Details:
Windows 8.1 pro x64, elevated command prompt
Python 3.4.2
Package NumPy from Gohlke's site
File numpy-1.9.1%2Bmkl-cp34-none-win_amd64.whl copied in the pip.exe folder
The log file shows:
d:\Program Files\WinPython-64bit-3.4.2.4\python-3.4.2.amd64\Scripts\pip run on 01/23/15 11:55:21
numpy-1.9.1%2Bmkl-cp34-none-win_amd64.whl is not a supported wheel on this platform.
Exception information:
Traceback (most recent call last):
File "D:\Python34\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "D:\Python34\lib\site-packages\pip\commands\install.py", line 257, in run
InstallRequirement.from_line(name, None))
File "D:\Python34\lib\site-packages\pip\req.py", line 167, in from_line
raise UnsupportedWheel("%s is not a supported wheel on this platform." % wheel.filename)
pip.exceptions.UnsupportedWheel: numpy-1.9.1%2Bmkl-cp34-none-win_amd64.whl is not a supported wheel on this platform.
What is wrong?
Short answer: rename the file to numpy-1.9.1%2Bmkl-cp34-none-win32.whl to install it.
You can check what tags your pip tool accepts for installation by running:
import pip; print(pip.pep425tags.get_supported())
In this case pip is incorrectly detecting your operating system to be 32-bits and the file you're trying to install was win_amd64 in its filename.
If you rename the file to numpy-1.9.1%2Bmkl-cp34-none-win32.whl (which now contains the tags that are considered supported) then you can install the package. It's a trick because the file is still built for 64-bits but this allows you to install the package as intended.
After several tests I think the problem is "win32" or "amd64" itself. I tried replacing those two with "any" and it worked.
In my case, the workaround to install gohlke packages on Python (3.4.4 (AMD64)) was to change the "cp34m" part rather than the "win*" parts in previous answers:
python -c "import pip; print(pip.pep425tags.get_supported())":
[('cp34', 'none', 'win_amd64'), ('py3', 'none', 'win_amd64'),
('cp34', 'none', 'any'), ...
ls -ld *:
matplotlib-2.0.0b3-cp34-cp34m-win_amd64.whl
numpy-1.11.1+mkl-cp34-cp34m-win_amd64.whl
pandas-0.18.1-cp34-cp34m-win_amd64.whl
Change the above names to:
matplotlib-2.0.0b3-cp34-none-win_amd64.whl
numpy-1.11.1+mkl-cp34-none-win_amd64.whl
pandas-0.18.1-cp34-none-win_amd64.whl
For example, pip install matplotlib-2.0.0b3-cp34-none-win_amd64.whl
Processing ...
...Successfully installed matplotlib-2.0.0b3
To add to the list of other possible solutions, I had to upgrade pip itself. The latest binary from Gholke's site had the "cp27m" tag, which didn't show up when I checked the pip tags using:
import pip; print(pip.pep425tags.get_supported())
After I upgraded pip, the wheel didn't work, but just doing a regular pip install numpy worked.
If you have, say, Python 3.4 installed, make sure to install the -cp34- version of the wheel and not -cp35-.
The current WinPython package manager need a two-characters fix to accept to recognize the new NumPy + mkl 'wheel'.
https://github.com/stonebig/winpython/commit/5e13230609a2e9f4d66d98c3776207ce4b4dd050
As a workaround, uninstall the NumPy package:
pip uninstall numpy
Then install it again from cache:
pip install numpy
I had the same problem with several packages after upgrading from 3.4.1 to 3.4.2.
Navigate to the directory where your 'pip.py' sits and then type following on the Windows command line:
..\python.exe pip.py install name_of_package.whl
This should work.
I had the same problem and tried to work it out with the suggested solutions.
I changed win64 to win32 and it didn't work either. But then I changed the name to original and this time it worked! The only extra thing I did was to go offline. That's so strange.
This has nothing to do with your operating system. Uninstall Python 32-bit and install Python 64-bit rather or alternatively find a 32-bit wheel file.

Resources