Installing M2Crypto on CentOS - python

I am trying to install M2Crypto on CentOS by compiling from the source.
i am doing a python setup.py build
But I get the following error,
/usr/local/lib/python2.6/distutils/dist.py:266: UserWarning: Unknown distribution option: 'test_suite'
warnings.warn(msg)
running build
running build_py
running build_ext
building 'M2Crypto.__m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/usr/local/include/python2.6 -I/usr/include -includeall -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
SWIG/_m2crypto.i:28: Error: Unable to find 'openssl/opensslv.h'
SWIG/_evp.i:9: Error: Unable to find 'openssl/opensslconf.h'
SWIG/_ec.i:7: Error: Unable to find 'openssl/opensslconf.h'
error: command 'swig' failed with exit status 1
Please advise ...
Prasanna

The following should work:
env SWIG_FEATURES="-cpperraswarn -includeall -D__`uname -m`__ -I/usr/include/openssl" python setup.py build
Edit: and openssl-devel package is of course also required.

I just had this problem. In M2Crypto's INSTALL file:
Note about Fedora Core -based Distributions
----------------------------------------------------
Fedora Core (and RedHat, CentOS etc.) have made changes to OpenSSL
configuration compared to many other Linux distributions. If you can not
build M2Crypto normally, try the fedora_setup.sh script included with
M2Crypto sources.
My solution was to get the sources from PyPI or from the source. Then in the M2Crypto directory:
$ chmod +x fedora_setup.py
$ ./fedora_setup.py install
If you're using a virtualenv, change the path of the python interpreter in that file, or activate your environment before building.
The only dependency that I had that wasn't satisfied on my system was openssl-devel.

Install openssl-devel.

Follow Brian's instruction, and make sure you have install openssl-devel. if you experience error like this:
./fedora_setup.sh build
running build
running build_py
running build_ext
building 'M2Crypto.__m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/usr/include/python2.6 -I/usr/include -includeall -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
SWIG/_evp.i:12: Error: Unable to find 'openssl/opensslconf-i686.h'
SWIG/_ec.i:7: Error: Unable to find 'openssl/opensslconf-i686.h'
error: command 'swig' failed with exit status 1
You are running i386 operating system on 64 bit hardware. arch =´uname -m´ will yields i686. The easiest way is to work around this is to create a symbolic link.
sudo ln -s /usr/include/openssl/opensslconf-i386.h /usr/include/openssl/opensslconf-i686.h
Or if you experience errors like:
./fedora_setup.sh build
running build
running build_py
running build_ext
SWIG/_m2crypto_wrap.c:27555: error: ‘Swig_var__evp_err_set’ undeclared (first use in this function)
SWIG/_m2crypto_wrap.c:27564: error: ‘Swig_var__dh_err_get’ undeclared (first use in this function)
SWIG/_m2crypto_wrap.c:27564: error: ‘Swig_var__dh_err_set’ undeclared (first use in this function)
SWIG/_m2crypto_wrap.c:27576: error: ‘Swig_var__rsa_err_get’ undeclared (first use in this function)
...
Some headers are missing, just issue the following command and try again:
sudo yum install python-devel

I had this problem now (in 2018), I solved it by installing openssl-devel, gcc and make
yum install gcc gcc-c++ make openssl-devel

Related

How to provide include path to SWIG?

I'm trying to build M2Crypto library, but swig does not find header files:
M2Crypto#(master=)$ python setup.py build
running build
running build_py
running build_ext
building 'M2Crypto.__m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/usr/include/python2.7 -I/usr/include -includeall -modern -builtin -outdir build/lib.linux-i686-2.7/M2Crypto -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
SWIG/_evp.i:12: Error: Unable to find 'openssl/opensslconf.h'
SWIG/_ec.i:7: Error: Unable to find 'openssl/opensslconf.h'
error: command 'swig' failed with exit status 1
I have OpenSSL headers, including openssl/opensslconf.h, in /usr/include/i386-linux-gnu - that is where openssl-dev package installs them to. This path is not passed to swig; setup.py seems to know nothing about it.
Does this look like a bug (or a problem) with the package, i.e. M2Crypto? What is the proper fix?
The reason is that libssl-dev moved opensslconf.h into an architecture dependent subtree /usr/include/x86_64-linux-gnu. Dependent on your architecture, the directory may be different.
There are two possible workarounds (either will work):
Option 1: Softlink the file to where it had been before the change:
sudo ln -s /usr/include/x86_64-linux-gnu/openssl/opensslconf.h /usr/include/openssl/opensslconf.h
This is also described in this article
Option 2: In setup.py of M2Crypto, add the architecture specific directory to the include path used by the swig command:
-I/usr/include/x86_64-linux-gnu
This is also described in this article
There is also issue 69 open for this, in the M2Crypto project.
Andy

Why do I get unrecognized command line error when building C extension with distutils

I am trying to build a source using python's distutils. I have created a simple setup.py following an example, and building it as suggested works fine:
python setup.py build
Now it is possible to build a source with a desired compiler; a list of compilers can be found as
python setup.py build_ext --inplace --help-compiler
List of available compilers:
--compiler=bcpp Borland C++ Compiler
--compiler=cygwin Cygwin port of GNU C Compiler for Win32
--compiler=emx EMX port of GNU C Compiler for OS/2
--compiler=mingw32 Mingw32 port of GNU C Compiler for Win32
--compiler=msvc Microsoft Visual C++
--compiler=unix standard UNIX-style compiler
However, if I try to use, for example, the mingw32 compiler as follows
python setup.py build --compiler=mingw32
I get the following error output:
building 'demo' extension
creating build
creating build/temp.linux-i686-2.7
gcc -mno-cygwin -mdll -O -Wall -DMAJOR_VERSION=1 -DMINOR_VERSION=0 -I/usr/local/include -I/usr/include/python2.7 -c demo.c -o build/temp.linux-i686-2.7/demo.o
cc1: error: unrecognized command line option ‘-mno-cygwin’
cc1: error: unrecognized command line option ‘-mdll’
error: command 'gcc' failed with exit status 1
What is the cause for this problem? Am I doing something wrong? Do I need to specify something else? Am I using wrong versions (Ubuntu 12.04, python 2.7.3, Distutils 1.0a4)?Do I need to 'remove' the offending options?
I don't think you really have MinGW on Ubuntu.
As you already quote,
--compiler=mingw32 Mingw32 port of GNU C Compiler for Win32
You should try --compiler=unix instead.
could you try installing python development headers and then run your command .
sudo apt-get install python-dev
sudo apt-get install libevent-dev

Installing lxml with pip in virtualenv Ubuntu 12.10 error: command 'gcc' failed with exit status 4

I'm having the following error when trying to run "pip install lxml" into a virtualenv in Ubuntu 12.10 x64. I have Python 2.7.
I have seen other related questions here about the same problem and tried installing python-dev, libxml2-dev and libxslt1-dev.
Please take a look of the traceback from the moment I tip the command to the moment when the error occurs.
Downloading/unpacking lxml
Running setup.py egg_info for package lxml
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
Building lxml version 3.1.2.
Building without Cython.
Using build configuration of libxslt 1.1.26
Building against libxml2/libxslt in the following directory: /usr/lib
warning: no files found matching '*.txt' under directory 'src/lxml/tests'
Installing collected packages: lxml
Running setup.py install for lxml
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
Building lxml version 3.1.2.
Building without Cython.
Using build configuration of libxslt 1.1.26
Building against libxml2/libxslt in the following directory: /usr/lib
building 'lxml.etree' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/home/admin/.virtualenvs/dev.actualito.com/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o
src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__getFilenameForFile':
src/lxml/lxml.etree.c:26851:7: warning: variable '__pyx_clineno' set but not used [-Wunused-but-set-variable]
src/lxml/lxml.etree.c:26850:15: warning: variable '__pyx_filename' set but not used [-Wunused-but-set-variable]
src/lxml/lxml.etree.c:26849:7: warning: variable '__pyx_lineno' set but not used [-Wunused-but-set-variable]
src/lxml/lxml.etree.c: In function '__pyx_pf_4lxml_5etree_4XSLT_18__call__':
src/lxml/lxml.etree.c:138273:81: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [enabled by default]
src/lxml/lxml.etree.c:136229:52: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *'
src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__copyXSLT':
src/lxml/lxml.etree.c:139667:79: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [enabled by default]
src/lxml/lxml.etree.c:136229:52: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *'
src/lxml/lxml.etree.c: At top level:
src/lxml/lxml.etree.c:12384:13: warning: '__pyx_f_4lxml_5etree_displayNode' defined but not used [-Wunused-function]
gcc: internal compiler error: Killed (program cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See for instructions.
error: command 'gcc' failed with exit status 4
Complete output from command /home/admin/.virtualenvs/dev.actualito.com/bin/python -c "import setuptools;__file__='/home/admin/.virtualenvs/dev.actualito.com/build/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-asDtN5-record/install-record.txt --single-version-externally-managed --install-headers /home/admin/.virtualenvs/dev.actualito.com/include/site/python2.7:
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
Building lxml version 3.1.2.
Building without Cython.
Using build configuration of libxslt 1.1.26
Building against libxml2/libxslt in the following directory: /usr/lib
running install
running build
running build_py
copying src/lxml/includes/lxml-version.h -> build/lib.linux-x86_64-2.7/lxml/includes
running build_ext
building 'lxml.etree' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/home/admin/.virtualenvs/dev.actualito.com/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o
src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__getFilenameForFile':
src/lxml/lxml.etree.c:26851:7: warning: variable '__pyx_clineno' set but not used [-Wunused-but-set-variable]
src/lxml/lxml.etree.c:26850:15: warning: variable '__pyx_filename' set but not used [-Wunused-but-set-variable]
src/lxml/lxml.etree.c:26849:7: warning: variable '__pyx_lineno' set but not used [-Wunused-but-set-variable]
src/lxml/lxml.etree.c: In function '__pyx_pf_4lxml_5etree_4XSLT_18__call__':
src/lxml/lxml.etree.c:138273:81: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [enabled by default]
src/lxml/lxml.etree.c:136229:52: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *'
src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__copyXSLT':
src/lxml/lxml.etree.c:139667:79: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [enabled by default]
src/lxml/lxml.etree.c:136229:52: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *'
src/lxml/lxml.etree.c: At top level:
src/lxml/lxml.etree.c:12384:13: warning: '__pyx_f_4lxml_5etree_displayNode' defined but not used [-Wunused-function]
gcc: internal compiler error: Killed (program cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See for instructions.
error: command 'gcc' failed with exit status 4
----------------------------------------
Command /home/admin/.virtualenvs/dev.actualito.com/bin/python -c "import setuptools;__file__='/home/admin/.virtualenvs/dev.actualito.com/build/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-asDtN5-record/install-record.txt --single-version-externally-managed --install-headers /home/admin/.virtualenvs/dev.actualito.com/include/site/python2.7 failed with error code 1 in /home/admin/.virtualenvs/dev.actualito.com/build/lxml
Storing complete log in /home/admin/.pip/pip.log
Make sure you have enough memory. Try dmesg | tail to see if it outputs something like:
...
[3778136.277570] Out of memory: Kill process 21267 (cc1) score 557 or sacrifice child
[3778136.277587] Killed process 21267 (cc1) total-vm:365836kB, anon-rss:336228kB, file-rss:0kB
Here is the my saved note.
sudo apt-get install libxml2
sudo apt-get install libxslt1.1
sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev
sudo apt-get install python-libxml2
sudo apt-get install python-libxslt1
sudo apt-get install python-dev
sudo apt-get install python-setuptools
easy_install lxml
It has worked for my ubuntu 12.10
According to lxml site you could use such construction:
CFLAGS="-O0" pip install lxml
installation guide
Note for those installing globally: The proper way to pass environment variables with sudo is after sudo:
sudo CFLAGS="-O0" pip install lxml
I met the similar question(error: command 'gcc' failed with exit status 4) this morning. It seems you need check your machine's memory. If the memory is lower than 512M,that may be the cause.Try to close some services temporarily,like apache server,and try "pip install lxml" again.It maybe work!
I've stumbled with this trouble a couple of times.
Short answer
Python2: $ python2.7 setup.py clean build --with-cython install
Python3: $ pip-3.3 install lxml
Long answer
The hypothesis is that pip install lxml should work in every environment, regardless if you are using Python2 or Python3.
There's also Cython to be considered: You will certainly enjoy lxml compiled with Cython due to relevant performance gains.
For reasons unknown to me, the compilation on Python2 does not find Cython.
To be more precise and absolutely explicit about this matter, both commands below DO NOT employ Cython:
# DO NOT use these commands. I repeat: DO NOT use these commands.
$ pip-2.7 install lxml
$ easy_install-2.7 install lxml
So, when using Python2 you have only one alternative, as far as I know, which is: compile from sources, Luke!
# install build environment and dependencies
$ kernel_release=$( uname -r )
$ sudo apt-get install linux-headers-${kernel_release} build-essential -y
$ sudo apt-get install libxml2-dev libxslt1-dev -y
# Download from github and compile from sources
$ git clone --branch lxml-3.2.4 https://github.com/lxml/lxml
$ python2.7 setup.py clean build --with-cython install
For ubuntu 12.04 and virtual env:
sudo apt-get install libxml2-dev libxslt-dev
workon some-virt-env
pip install lxml
Try to disable the C compiler optimizations by setting the FLAGS environment variable
CFLAGS="-O0" pip install lxml
That solves for me without the need of more RAM

Errors when installing cython on windows

I was trying to install cython on windows 7 using python setup.py install. But it encountered an error:
C:\Cython-0.16>C:\Python27\python setup.py install
running install
running build
running build_py
running build_ext
building 'Cython.Plex.Scanners' extension
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python27\include -IC:\Pytho
n27\PC -c Cython\Plex\Scanners.c -o build\temp.win32-2.7\Release\cython\plex\sca
nners.o
cc1.exe: error: unrecognized command line option '-mno-cygwin'
error: command 'gcc' failed with exit status 1
I am using Python 2.7, I have MinGW and Cygwin installed on the system. I tried to google it. But there isn't a similar problem.
I used mingw-get-inst-20120426.exe to install the MinGW version 4.5.
-mno-cygwin in Python\Lib\distutils\cygwinccompiler.py causes this problem: see Compiling with cython and mingw produces gcc: error: unrecognized command line option '-mno-cygwin' or http://korbinin.blogspot.com/2013/03/cython-mno-cygwin-problems.html. My Python distribution (Anaconda)'s cygwinccompiler.py does not have that though. Anyway, after removing all -mno-cygwin in the definition of the Mingw32CCompiler class you should be able to compile.

Building QuantLib python bindings on windows 7: 'unrecognized command line option '-mno-cygwin''

I'm trying to build the QuantLib Python bindings. I managed to build QuantLib using these instructions (I found the libboost_serialization files here). When I try python setup.py build, I get the following error
python setup.py build
running build
running build_py
running build_ext
building 'QuantLib._QuantLib' extension
C:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python26\include -IC:\Python26\PC -c QuantLib/quantlib_wrap.cpp -o build\temp.win32-2.6\Release\quantlib\quantlib_wrap.o
cc1plus: error: unrecognized command line option '-mno-cygwin'
error: command 'gcc' failed with exit status 1
I've heard that the mno-cygwin option is no longer supported and I've seen it removed from numpy distutils, but as far as I can tell this is only using python distutils. Any hints on what I should look at?
windows 7
python 2.6
numpy 1.5.1
QuantLib 1.46.1
I've done a tutorial that builds Quantlib Python bindings on Windows (Vista and XP). This probably will work with Windows 7 as well and you don't need Visual Studio. here
The answer is that Python 2.6 distutils hasn't caught up with MinGW (source). I now get another error, but that's for another question.

Categories