How to provide include path to SWIG? - python

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

Related

Cython: fatal error: 'ios' file not found [duplicate]

When I try to install python-pcl(PCL is the point cloud library for presentation like laser radar data. I followed the instruction on https://github.com/strawlab/python-pcl ,and I have already copied travis/pcl-2d-1.8.pc file to /usr/local/lib/pkgconfig folder) in my computer. I typed AppledeMacBook-Pro-3:python-pcl-0.3.0rc1 apple$ python setup.py install in my terminal.Then I encountered a problem below:
running install
running bdist_egg
running egg_info
writing requirements to python_pcl.egg-info/requires.txt
writing python_pcl.egg-info/PKG-INFO
writing top-level names to python_pcl.egg-info/top_level.txt
writing dependency_links to python_pcl.egg-info/dependency_links.txt
reading manifest file 'python_pcl.egg-info/SOURCES.txt'
writing manifest file 'python_pcl.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.6-x86_64/egg
running install_lib
running build_py
running build_ext
skipping 'pcl/_pcl_180.cpp' Cython extension (up-to-date)
building 'pcl._pcl' extension
/usr/bin/clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/apple/miniconda3/include -I/Users/apple/miniconda3/include -DEIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET=1 -I/Users/apple/miniconda3/pkgs/python-3.5.4-h8f450c2_22/lib/python3.5/site-packages/numpy/core/include -I/usr/local/include/pcl-1.8 -I/usr/local/Cellar/openni/1.5.7.10/include/ni -I/usr/local/include/pcl-1.8 -I/usr/local/Cellar/flann/1.9.1_6/include -I/usr/local/include/pcl-1.8 -I/opt/local/include/eigen3 -I/usr/include/ni -I/usr/include/vtk-5.8 -I/usr/local/include/vtk-8.0 -I/usr/local/Cellar/vtk/8.0.1/include -I/Users/apple/miniconda3/pkgs/python-3.5.4-h8f450c2_22/include/python3.5m -c pcl/_pcl_180.cpp -o build/temp.macosx-10.6-x86_64-3.5/pcl/_pcl_180.o
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the
command line to use the libc++ standard library instead
[-Wstdlibcxx-not-found]
pcl/_pcl_180.cpp:447:10: fatal error: 'vector' file not found
#include <vector>
^~~~~~~~
Somebody says it has something to do with my Cython version. But I have already switched Cython to version 0.25.2, still not working. Does anyone have the same problem? Many thanks. By the way, my python version is 3.5.4 and my Mac Version is macOS Mojave 10.14.1
This is a special issue with current MacOS-installations. You could tweak setup.py and add, as the warning suggest, -std=libc++ to the compile-options, i.e.
from distutils.core import setup
from Cython.Build import cythonize
... some stuff
#passing `-stdlib=libc++` to compiler and linker:
ext_modules = [Extension(...,
language='c++',
extra_compile_args=["-stdlib=libc++"], # + anything else you need
extra_link_args= ["-stdlib=libc++"] # + anything else you need]
... some more stuff
I have also added -stdlib=libc++ to the linker options, because it will be probably the next problem you will run into.
More background: In the MacOS world, for long time, there where two different implementations of c++'s standard library: -libstdc++ associated with gcc and libc++ associated with clang. At the beginning-libstdc++ was also used per default with clang-compiler. However, this is no longer the case - it is not even installed now and that is the reason why the headers cannot be found. I'm not sure why your clang-version doesn't take libc++ per default - so you have to pass it manually to compiler/linker.

Stanford CoreNLP python interface installation errors

I'm trying to build the python interface of the stanford NLP on Ubuntu 12.04.5 LTS.
There are two steps required, the first of which is:
compile Jpype by running "rake setup" in 3rdParty/jpype
When doing so I get the following error:
In file included from src/native/common/jp_monitor.cpp:17:0:
src/native/common/include/jpype.h:45:17: fatal error: jni.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
rake aborted!
Command failed with status (1): [cd JPype-0.5.4.1 && python setup.py build...]
The error messages says I'm missing jni.h, so as suggested here if I ran the command dpkg-query -L openjdk-7-jdk | grep "jni.h" getting /usr/lib/jvm/java-7-openjdk-amd64/include/jni.h.
I believe that means I do have jni.h on my system, so I'm very confused right now. What is causing the error? Can you suggest any fix?
Thanks for your help!
A FEW MORE INSIGHTS
Here is the instruction causing the error:
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.08/include -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.08/include/linux -Isrc/native/common/include -Isrc/native/python/include -I/usr/include/python2.7 -c src/native/common/jp_class.cpp -o build/temp.linux-x86_64-2.7/src/native/common/jp_class.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
In file included from src/native/common/jp_class.cpp:17:0:src/native/common/include/jpype.h:45:17: fatal error: jni.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
It's coming from the compilation of JPype needed for the python interface. I do not know why but it includes paths that I don't have in my filesystem (i.e. -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.08/include/linux).
How can I configure these paths correctly?
The include paths specified do not include the path where jni.h is located.
From your grep, jni.h is located here: /usr/lib/jvm/java-7-openjdk-amd64/include/jni.h
The include paths specified in the gcc args are: -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.08/include -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.08/include/linux -Isrc/native/common/include -Isrc/native/python/include -I/usr/include/python2.7
Sounds to me that you are building with the wrong java? You have a java-1.5.0 install and a java-7-openjdk install - this one has the missing jni.h file.
Based on the following question, it seems like you can fix this by setting JAVA_HOME.
JPype compile problems
So before building use:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
This problem is a path problem (as said in the question and correctly answered by #vikramls).
Apparently when running the script for installing the python interface of the StanfordNLP if JPype is missing it will get installed with the following command:
python setup.py install
Now if you open the file setup.py you can see the following part which sets the java paths for a linux machine (I'm running on ubuntu):
def setupLinux(self):
self.javaHome = os.getenv("JAVA_HOME")
if self.javaHome is None :
self.javaHome = '/usr/lib/jvm/java-1.5.0-sun-1.5.0.08' # Ubuntu linux
# self.javaHome = '/usr/java/jdk1.5.0_05'
self.jdkInclude = "linux"
self.libraries = ["dl"]
self.libraryDir = [self.javaHome+"/lib"]
Clearly this path will not work on every machine, so there are 2 possible solutions:
Before running the installation script export a variable called JAVA_HOME with the location of your java installation. I.e. export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64 in my case.
As this page says you can set an automatic include variable for gcc with the following command export C_INCLUDE_PATH=some_path and that path should be set to where you java libraries are on your machine

install a python library, specifically pycurl, on my heroku box (Rails application)

So I built this rails application locally and deployed it via Heroku. There is this important python script I rely on that heavily uses the pycurl library. My script is able to run locally because I was able to easily download and install pycurl on my local machine. The problem is pycurl is not installed remotely on Heroku, and I cannot seem to figure out how to install pycurl so that Heroku can run my python script. I downloaded setuptools, as well as the pycurl tar file in my rails app and tried to ssh into heroku and run something like python setyp.py install, or pip install pycurl, however, none of these commands will run because I do not and cannot have write access to this directory: /usr/local/lib/python2.7/site-packages/ on heroku (you also cannot run these commands as root because Heroku will not allow you too). After trying everything, it seems like I should follow these instructions from Heroku, which gets printed to my terminal after running python setup.py install:
".....If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable."
I am not sure how to go about this. Any help wold be much appreciated.
Also, I have come across a few stack overflow posts but none have been able to help so far. Let me know if you need any more info from me.
TL;DR - Installing a python module/library on Heroku.
add a requirements.txt file to your python deployment.
Write your python dependencies in it (add any other dependencies you have not only pycurl).
check this doc from heroku guys
I use pycurl on my heroku app and have found no problem uploading to heroku..
Installing dependencies using Pip (1.3.1)
Downloading/unpacking pycurl==7.19.0 (from -r requirements.txt (line 11))
Running setup.py egg_info for package pycurl
Using curl-config (libcurl 7.19.7)
Installing collected packages: pycurl
Running setup.py install for pycurl
Using curl-config (libcurl 7.19.7)
building 'pycurl' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_CURL_OPENSSL=1 -DHAVE_CURL_OPENSSL=1 -DHAVE_CURL_SSL=1 -I/app/.heroku/python/include/python2.7 -c src/pycurl.c -o build/temp.linux-x86_64-2.7/src/pycurl.o
src/pycurl.c: In function ‘do_multi_info_read’:
src/pycurl.c:2843: warning: call to ‘_curl_easy_getinfo_err_string’ declared with attribute warning: curl_easy_getinfo expects a pointer to char * for this info
src/pycurl.c: In function ‘multi_socket_callback’:
src/pycurl.c:2355: warning: call to ‘_curl_easy_getinfo_err_string’ declared with attribute warning: curl_easy_getinfo expects a pointer to char * for this info
In function ‘util_curl_unsetopt’,
inlined from ‘do_curl_unsetopt’ at src/pycurl.c:1551:
src/pycurl.c:1476: warning: call to ‘_curl_easy_setopt_err_CURLSH’ declared with attribute warning: curl_easy_setopt expects a CURLSH* argument for this option
gcc -pthread -shared build/temp.linux-x86_64-2.7/src/pycurl.o -lcurl -lidn -lssl -lcrypto -llber -lldap -lrt -lgssapi_krb5 -lgssapi_krb5 -lssl -lcrypto -lz -o build/lib.linux-x86_64-2.7/pycurl.so /usr/lib/libcurl.a
Successfully installed pycurl

Cannot get Cython to find the MinGW gcc compiler even after editing PATH, making a file in distutils, removing all instances of -mno-cygwin

I am trying to get cython to realize I have a c compiler in MinGW 32-bit and I've tried everything I can find on the web but it's still not working. I am running Windows 7 Professional 64-bit. Here is what I have tried:
(1) I have Python 2.7 and I just installed MinGW with options gcc and g++ and some other options
(2) I edited the PATH environmental variable so it includes
C:\MinGW\bin;C:\MinGW\MSYS\1.0\local\bin;C:\MinGW\MSYS\1.0\bin
(3) I told Python to use MinGW as the default compiler by creating a file named
C:\Python27\Lib\distutils\distutils.cfg, containing
[build]
compiler = mingw32
(I do have MinGW32 by the way)
(4) I removed all instances of -mno-cygwin from the file C:\Python27\Lib\distutils\cygwincompiler.py
(5) I have a file called setup.py and a module called tryingcython.pyx that is written in python. My setup.py says
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
cmdclass = {'build_ext':build_ext},
ext_modules=[Extension("tryingcython",["tryingcython.pyx"])]
)
So then I open Command Prompt and get into the directory that contains setup.py and tryingcython.pyx, and I type
python setup.py build_ext --inplace --compiler=mingw32
Then it tells me:
running build_ext
skipping 'tryingcython.c' Cython extension (up-to-date)
building 'tryingcython.c' extension
gcc -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c tryingcython.c -o build\
temp.win32-2.7\Release\tryingcython.o
error: command 'gcc' failed: No such file or directory
So I guess Cython can't tell that I have gcc and it can't find it or what, even though I've tried about every single piece of advice I can find online for making it realize that I have MinGW which has gcc included.
Any help/additional ideas on how I can get cython to actually work would be much appreciated.
You are using exactly the same operational system and versions than me.
Try to cal gcc using:
SET input=intput.c
SET output=output.pyd
gcc -shared -IC:\Python27\include -LC:\Python27\libs -O2 -o %output% %input% -lpython27
Usually I put this call in a cythongcc.bat file, in a directory recognized by the PATH environment variable as:
gcc -shared -IC:\Python27\include -LC:\Python27\libs -O3 -mtune=native -o %1.pyd %2.c -lpython27
So that I can , from where my cython .pyx files are, just do:
cython input.pyx
cythongcc input input
To get the compiled .pyd working!

Installing M2Crypto on CentOS

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

Categories