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

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

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.

Installing pycrypto on raspbian for python 3.2.3

Im trying to crate a cryptosystem on the raspbian OS. Chose python and pycrypto because the OS comes with python 3.2.3 pre-installed. Moved the "pycrypto-2.6.1.tar.gz" to the folder where python files are located and extracted there. Suposed to build using the command "python setup.py build" and then install.
But during the build phase, keep getting the error:
"pi#raspberrypi /usr/lib/python3.2/pycrypto-2.6.1 $ python setup.py buildrunning build
running build_py
running build_ext
running build_configure
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
building 'Crypto.Hash._MD2' extension
gcc -pthread -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes -fPIC -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python2.7 -c src/MD2.c -o build/temp.linux-armv6l-2.7/src/MD2.o
src/MD2.c:31:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
"
Not able to figure out whether I am supposed to change the pathing. Could somebody give an insight in to this?
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
The libgmp-dev package provides the necessary files to support building the optimized module here:
apt-get install libgmp-dev
src/MD2.c:31:20: fatal error: Python.h: No such file or directory
compilation terminated.
If you search for fatal error: Python.h: No such file or directory, the very first Google result is for this StackOverflow question, which tells you that you need to install the python-dev package:
apt-get install python-dev
In general, if you are building software from source you will need the corresponding -dev package for any required libraries; these packages provide header files (foo.h) and the unversioned shared libraries necessary for linking.

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

Python.h not found using swig and Anaconda Python

I'm trying to compile a simple python/C example following this tutorial:
http://www.swig.org/tutorial.html
I'm on MacOS using Anaconda python.
however, when I run
gcc -c example.c example_wrap.c -I/Users/myuser/anaconda/include/
I get:
example_wrap.c:130:11: fatal error: 'Python.h' file not found
# include <Python.h>
^
It seems that this problem is reported in a number of questions:
Missing Python.h while trying to compile a C extension module
Missing Python.h and impossible to find
Python.h: No such file or directory
but none seem to provide an answer specific to Anaconda on MacOS
Anyone solved this?
Use the option -I/Users/myuser/anaconda/include/python2.7 in the gcc command. (That's assuming you are using python 2.7. Change the name to match the version of python that you are using.) You can use the command python-config --cflags to get the full set of recommended compilation flags:
$ python-config --cflags
-I/Users/myuser/anaconda/include/python2.7 -I/Users/myuser/anaconda/include/python2.7 -fno-strict-aliasing -I/Users/myuser/anaconda/include -arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
However, to build the extension module, I recommend using a simple setup script, such as the following setup.py, and let distutils figure out all the compiling and linking options for you.
# setup.py
from distutils.core import setup, Extension
example_module = Extension('_example', sources=['example_wrap.c', 'example.c'])
setup(name='example', ext_modules=[example_module], py_modules=["example"])
Then you can run:
$ swig -python example.i
$ python setup.py build_ext --inplace
(Take a look at the compiler commands that are echoed to the terminal when setup.py is run.)
distutils knows about SWIG, so instead of including example_wrap.c in the list of source files, you can include example.i, and swig will be run automatically by the setup script:
# setup.py
from distutils.core import setup, Extension
example_module = Extension('_example', sources=['example.c', 'example.i'])
setup(name='example', ext_modules=[example_module], py_modules=["example"])
With the above version of setup.py, you can build the extension module with the single command
$ python setup.py build_ext --inplace
Once you've built the extension module, you should be able to use it in python:
>>> import example
>>> example.fact(5)
120
If you'd rather not use the script setup.py, here's a set of commands that worked for me:
$ swig -python example.i
$ gcc -c -I/Users/myuser/anaconda/include/python2.7 example.c example_wrap.c
$ gcc -bundle -undefined dynamic_lookup -L/Users/myuser/anaconda/lib example.o example_wrap.o -o _example.so
Note: I'm using Mac OS X 10.9.4:
$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix

Error installing pymssql on Mac OS X Lion

I have XCode installed and also FreeTDS. I tried to connect to my SQL Server and it works perfect.
Now I have to develop an aplication on python that works with this SQL Server and I´m trying to install pymsql, but I got this error when I launche sudo python setup.py command:
==> sudo python setup.py install
running install
running bdist_egg
running egg_info
writing pymssql.egg-info/PKG-INFO
writing top-level names to pymssql.egg-info/top_level.txt
writing dependency_links to pymssql.egg-info/dependency_links.txt
reading manifest file 'pymssql.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'pymssql.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.7-intel/egg
running install_lib
running build_ext
skipping '_mssql.c' Cython extension (up-to-date)
building '_mssql' extension
llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -I/sw/include -Ifreetds/nix_64/include -I/opt/local/include -I/opt/local/include/freetds -I/opt/local/freetds/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mssql.c -o build/temp.macosx-10.7-intel-2.7/_mssql.o -DMSDBLIB
_mssql.c: In function ‘__pyx_f_6_mssql_15MSSQLConnection_convert_python_value’:
_mssql.c:7322: warning: implicit conversion shortens 64-bit value into a 32-bit value
_mssql.c: In function ‘__pyx_f_6_mssql_15MSSQLConnection_get_result’:
_mssql.c:9554: warning: implicit conversion shortens 64-bit value into a 32-bit value
_mssql.c:9566: warning: implicit conversion shortens 64-bit value into a 32-bit value
_mssql.c: In function ‘__pyx_pf_6_mssql_20MSSQLStoredProcedure_2bind’:
_mssql.c:11146: warning: implicit conversion shortens 64-bit value into a 32-bit value
llvm-gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -Wl,-F. -arch i386 -arch x86_64 build/temp.macosx-10.7-intel-2.7/_mssql.o -L/sw/lib -Lfreetds/nix_64/lib -L/opt/local/lib -L/opt/local/lib/freetds -L/opt/local/freetds/lib -lsybdb -lrt -o build/lib.macosx-10.7-intel-2.7/_mssql.so
ld: warning: directory not found for option '-L/sw/lib'
ld: warning: directory not found for option '-L/opt/local/lib'
ld: warning: directory not found for option '-L/opt/local/lib/freetds'
ld: warning: directory not found for option '-L/opt/local/freetds/lib'
ld: library not found for -lrt
collect2: ld returned 1 exit status
ld: warning: directory not found for option '-L/sw/lib'
ld: warning: directory not found for option '-L/opt/local/lib'
ld: warning: directory not found for option '-L/opt/local/lib/freetds'
ld: warning: directory not found for option '-L/opt/local/freetds/lib'
ld: library not found for -lrt
collect2: ld returned 1 exit status
lipo: can't open input file: /var/tmp//cc6eQsIN.out (No such file or directory)
error: command 'llvm-gcc-4.2' failed with exit status 1
Any help or clue?
Unfortunately, pymssql's setup.py (as of version pymssql-2.0.0b1-dev-20111019) needs a bit of help to work properly on OSX Lion. The current setup.py tries to compile/link against some pre-built Linux FreeTDS libraries, and also tries to link against librt, which doesn't exist on OSX. Additionally, it only explicitly looks for FreeTDS libraries from Fink or MacPorts, so if you've installed Homebrew (if you use if) or FreeTDS itself in a non-standard location, it may not be located by compiler/linker.
I created a repaired version of setup.py here. It worked well enough for me with the Homebrew build of FreeTDS using the standard locations (/usr/local/{lib, include}), but as always YMMV. You may need to adjust setup.py further if you've installed FreeTDS in a different location. You can generally ignore the warnings from the linker about missing directories that may not exist on your system:
ld: warning: directory not found for option '-L/usr/local/lib/freetds'
One other note: You will probably have built FreeTDS for a single architecture, likely x86_64. By default, pymssl will be a multi-architecture build (assuming you're using the system Python 2.7.1), so even with a patched setup.py you will see a linker warning something like:
ld: warning: ignoring file /usr/local/lib/libsybdb.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
That warning just indicates that the FreeTDS libraries only have single architecture version to link against. You can avoid the warning by using ARCHFLAGS to make a x86_64-only build:
ARCHFLAGS="-arch x86_64" python setup.py install
Or, try this fork, it installs without issues:
https://github.com/blackbass1988/pymssql-macos-lion
To install on OS X Mavericks, you need
OS X Command Line Tools
FreeTDS
brew install freetds
Cython
pip install cython
and then finally you can install the pymssql-macoslion
pip install git+git://github.com/blackbass1988/pymssql-macos-lion.git#master
Just incase anyone is reading this the following worked for me:
brew install freetds
sudo pip install pymssql

Categories