How to get pylibnet installed on a Mac - python

In example.py file I have:
import libnet
but when I execute it via:
/opt/local/bin/python2.5 example.py
I'm getting "ImportError: No module named libnet"
How I tried to install it:
went to http://pylibnet.sourceforge.net/ and downloaded it
read the README file which said: compiling on Mac doesn't work, load it with Macports and use python 2.5
installed and used python 2.5
installed libnet via: sudo port install libnet11
everything seems to be fine
Just the error stays, it doesn't seem to be installed. What can i do now?
Thanks for any kind of help!
/Edit:
with: "sudo /opt/local/bin/python2.5 setup.py install", i'm getting:
Searching for libnet...
running install
running build
running build_ext
building 'libnet' extension
/Developer/usr/bin/llvm-gcc-4.2 -fno-strict-aliasing -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DLIBNET_MAJOR_VERSION=1 -DLIBNET_MINOR_VERSION=1 -DLIBNET_RELEASE=5 -DMAJOR_VERSION=2 -DMINOR_VERSION=0 -I/opt/local/include -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c src/libnetmodule.c -o build/temp.macosx-10.7-x86_64-2.5/src/libnetmodule.o
In file included from src/context.c:110,
from src/libnetmodule.c:37:
src/builders.c: In function 'context_build_icmpv4_timestamp':
src/builders.c:726: error: 'n_time' undeclared (first use in this function)
src/builders.c:726: error: (Each undeclared identifier is reported only once
src/builders.c:726: error: for each function it appears in.)
src/builders.c:726: error: expected ';' before 'otime'
src/builders.c:727: error: expected ';' before 'rtime'
src/builders.c:728: error: expected ';' before 'ttime'
src/builders.c:735: error: 'otime' undeclared (first use in this function)
src/builders.c:735: error: 'rtime' undeclared (first use in this function)
src/builders.c:735: error: 'ttime' undeclared (first use in this function)
error: command '/Developer/usr/bin/llvm-gcc-4.2' failed with exit status 1

After you installed the C libraries with MacPorts, did you then install the python libnet wrapper you downloaded? If not, cd to the de-tarred pylibnet directory and try:
sudo /opt/local/bin/python2.5 setup.py install
Update: From your updated question, it now appears you have another version of the libnet C libraries installed in /sw which is the default location for packages installed by Fink. You should not attempt to mix package managers. Pick one - MacPorts, Fink, or Homebrew are the most popular on OS X - and stick with it. As a short term fix, you could probably edit the setup.py file to remove the search for /sw. You should at some point evaluate what packages you have installed with Fink and MacPorts, pick one, install any missing ports/packages in it, and entirely delete the other package system.

Related

fatal error: 'arrayobject.h' file not found when using pyenv

I am trying to use the following package: https://github.com/vBaiCai/python-pesq and I am also using Pipenv and pyenv. I have installed 3.6-dev with pyenv and am using that with pipenv --python ~/.pyenv/versions/3.6-dev/bin/python3.
When I do pipenv install pypesq, I get a ton of errors, including:
file numpy.py (for module numpy) not found
warning: build_py: byte-compiling is disabled, skipping.
running build_ext
building 'pesq_core' extension
creating build/temp.macosx-10.15-x86_64-3.6
creating build/temp.macosx-10.15-x86_64-3.6/pypesq
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Users/shamoon/.pyenv/versions/3.6-dev/include/python3.6m -I/Users/shamoon/.pyenv/versions/3.6-dev/lib/python3.6/site-packages/numpy/core/include -c pypesq/pesq.c -o build/temp.macosx-10.15-x86_64-3.6/pypesq/pesq.o
pypesq/pesq.c:2:10: fatal error: 'arrayobject.h' file not found
#include "arrayobject.h"
^~~~~~~~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
I am on OS X if that matters. Any help.
I used pyenv to install Python 3.6-dev on Linux Mint 19.2 and I found two problems during installation pypesq:
1. It couldn't find arrayobject.h from module numpy
I used answer from Ubuntu forum fatal error: numpy/arrayobject.h: No such file or directory
I had to find folder with arrayobject.h and add it to environment variable CFLAGS so later C/C++ compiler will use it to find arrayobject.h- ie. (directly in terminal)
export CFLAGS="-I /usr/local/lib/python3.7/dist-packages/numpy/core/include/numpy/ $CFLAGS"
I was installing pypesq for Python 3.6-dev but I used path to numpy installed in Python 3.7 and there was no problem.
BTW: To find it I used shell command locate which is not standard command but it works much faster then find
2. It couldn't find pesq.h
Instead of using module from pip server I used code from GitHub which was updated yesterday
pipenv install https://github.com/vBaiCai/python-pesq/archive/master.zip
After that I could import it in Python 3.6-dev but I didn't test if it works correctly.

Pythai on Mac OS

Dose anyone have experience installing pythai on mac OS.
I get the following error when I try and install it with "pip install pythai"
gcc -fno-strict-aliasing -I/Users/roopal/anaconda/include -arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/roopal/anaconda/include/python2.7 -c pythai/libthai.c -o build/temp.macosx-10.6-x86_64-2.7/pythai/libthai.o
pythai/libthai.c:3:10: fatal error: 'thai/thbrk.h' file not found
#include <thai/thbrk.h>
^
1 error generated.
error: command 'gcc' failed with exit status 1
Not sure where to get and put the thai/thbrk.h file
If you Google pythai, the first result that comes up is the project's Github page. If you click on it, then scroll down to the readme, it says in the Installation section
PyThai requires libthai-dev to work.
and gives installation instructions for Debian/Ubuntu. Since you're on OS X, you'll need to build the source from scratch. Going back to Google, a search for libthai leads you to the LibThai website. Reading that page, you'll find that the code is hosted on Github. Click on Releases and download the tar.gz of the latest version, 0.1.25. Unpack the archive, enter its base folder, and run ./autogen.sh. If you get an error about an undefined macro, do what it says and rerun autogen.sh with the m4_pattern_allow argument. Once that completes, do the usual for building a package from source - run ./configure --help to see if there are any particular options you want to set, then run ./configure plus any desired flags, then run make, then run sudo make install and you should be all set.
Obviously, this requires you to have XCode and the XCode command-line tools installed and activated.

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

Why am I missing git2.h and how do I get it back?

I am experiencing an odd problem every time I try the set-up of pygit2. Below is what I run and the error generated.
$ python3 setup.py install
running install
running build
running build_py
running build_ext
building '_pygit2' extension
/usr/bin/clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Os -w -pipe -march=native -Qunused-arguments -mmacosx-version-min=10.7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/lib -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include -I/usr/local/include -Iinclude -I/usr/local/Cellar/python3/3.2.3/include/python3.2m -c src/pygit2.c -o build/temp.macosx-10.7-x86_64-3.2/src/pygit2.o
In file included from src/pygit2.c:32:
include/pygit2/error.h:6:10: fatal error: 'git2.h' file not found
#include <git2.h>
^
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1
I think I have successfully installed libgit2 (the build and make finished fine). Maybe it is a path issue? I have set LIBGIT2 environment variable to the src directory in the libgit2 folder. Is that the right place?
I never installed libgit2, but the following might help:
If your distro's repository contains libgit2, I'll advice to remove what you have compiled before and install libgit2 (binaries) and libgit2-dev (headers etc.) packages from the repo. This will place binaries and sources to the right directories.
Otherwise, try symlinking git2.h to /usr/local/include
Following step worked for me:
brew install libgit2
It doesn't look like the LIBGIT2 variable took (could you show how you set the variable?) as the extra include directive uses /usr/local/include (which is the default).
The LIBGIT2 env var needs to be set to the prefix where the library was installed, typically /usr or /usr/local. It doesn't look like the library was installed to /usr/local as the compiler can't find it, so maybe you need export LIBGIT2=/usr before running setup.py.
You must be on macOS. Here is how I solved the problem:
brew install libgit2
If that isn't working because of Permission denied # dir_s_mkdir, just run the following command
sudo chown -R $(whoiam) $(brew --prefix)/*

How do I build and install P4Python for Mac OS X?

I've been unable to build P4Python for an Intel Mac OS X 10.5.5.
These are my steps:
I downloaded p4python.tgz (from
http://filehost.perforce.com/perforce/r07.3/tools/) and expanded
it into "P4Python-2007.3".
I downloaded p4api.tar (from
http://filehost.perforce.com/perforce/r07.3/bin.macosx104x86/)
and expanded it into "p4api-2007.3.143793".
I placed "p4api-2007.3.143793" into "P4Python-2007.3" and edited
setup.cfg to set "p4_api=./p4api-2007.3.143793".
I added the line 'extra_link_args = ["-framework", "Carbon"]' to
setup.py after:
elif unameOut[0] == "Darwin":
unix = "MACOSX"
release = "104"
platform = self.architecture(unameOut[4])
I ran python setup.py build and got:
$ python setup.py build
API Release 2007.3
running build
running build_py
running build_ext
building 'P4API' extension
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DID_OS="MACOSX104X86" -DID_REL="2007.3" -DID_PATCH="151416" -DID_API="2007.3" -DID_Y="2008" -DID_M="04" -DID_D="09" -I./p4api-2007.3.143793 -I./p4api-2007.3.143793/include/p4 -I/build/toolchain/mac32/python-2.4.3/include/python2.4 -c P4API.cpp -o build/temp.darwin-9.5.0-i386-2.4/P4API.o -DOS_MACOSX -DOS_MACOSX104 -DOS_MACOSXX86 -DOS_MACOSX104X86
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++
P4API.cpp: In function âint P4Adapter_init(P4Adapter*, PyObject*, PyObject*)â:
P4API.cpp:105: error: âPy_ssize_tâ was not declared in this scope
P4API.cpp:105: error: expected `;' before âposâ
P4API.cpp:107: error: âposâ was not declared in this scope
P4API.cpp: In function âPyObject* P4Adapter_run(P4Adapter*, PyObject*)â:
P4API.cpp:177: error: âPy_ssize_tâ was not declared in this scope
P4API.cpp:177: error: expected `;' before âiâ
P4API.cpp:177: error: âiâ was not declared in this scope
error: command 'gcc' failed with exit status 1
which gcc returns /usr/bin/gcc and gcc -v returns:
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5465~16/src/configure
--disable-checking -enable-werror --prefix=/usr --mandir=/share/man
--enable-languages=c,objc,c++,obj-c++
--program-transform-name=/^[cg][^.-]*$/s/$/-4.0/
--with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib
--build=i686-apple-darwin9 --with-arch=apple --with-tune=generic
--host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5465)
python -V returns Python 2.4.3.
The newer version 2008.1 will build with Python 2.4.
I had posted the minor changes required to do that on my P4Python page, but they were rolled in to the official version.
Robert
From http://bugs.mymediasystem.org/?do=details&task_id=676 suggests that Py_ssize_t was added in python 2.5, so it won't work (without some modifications) with python 2.4.
Either install/compile your own copy of python 2.5/2.6, or work out how to change P4Python, or look for an alternative python-perforce library.
Very outdated, but maybe you can use http://public.perforce.com:8080/#md=d&cd=//guest/miki_tebeka/p4py/&c=5Fm#//guest/miki_tebeka/p4py/main/?ac=83 for now

Categories