py2app invalid link to zlib - python

I'm trying to package a python program to an app with py2app 0.7.3.
I have one (Mountain Lion) Mac on which I installed the python.org version of Python 2.7.3 and all required modules by using the distributables that were available for them.
However, I also needed a 32-bit version of the app, so on another (Mountain Lion) machine I have set up the same environment (i.e. python + modules) using macports (with i386 for build_arch).
From source, my program runs fine on both machines. However, only the app that is generated on the 64-bit machine works. When trying to run the 32-bit app generated on the macports machine, I get the error:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/py2app/apptemplate/lib/site.py", line 20, in <module>
import os
zipimport.ZipImportError: can't decompress data; zlib not available
For both apps the same setup.py file was used.
It seems as if the app generated on the macports machine still tries to use the external Python instead of the one that is packaged with it (though it should not be semi-standalone as the system's python was not used). zlib is present in the .app file (and, of course, also outside).
Most other posts I have found about this problem, recommend to alter the sys.path variable in the __boot__.py file that can be found inside the package, but it seems as if my app doesn't even reach that module and crashes beforehand.

I found a, maybe not so elegant, but working solution:
In py2app/__init__.py I set the variable 'Compression' to False. This prevents the compression of the site-packages folder to a zipfile. This partly solved the problem as there were still some invalid mach-o error messages afterwards, but by invoking py2app like
python setup-mac.py py2app --arch i386
the generated app ran fine

Related

Error in using PyQt4 with python 3.5.2 for running a PyMoskito example

I'm trying to get an example of PyMoskito running under Python 3.5.2 Win7 64 bit
This library needs PyQt4 which in turn needs SIP.
1- I installed SIP using pip3 install SIP which ended up successfully (with a notice to update my pip).
2- I even barely know Python. So I tried installing PyQt4 with a binary executable. The binaries provided at riverbankcomputing.com/software/pyqt/download are for python 3.4 so I downloaded an unofficial wheel from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4 with a name PyQt4-4.11.4-cp35-none-win_amd64.whl. Then I cd'ed into the respective directory and installed it with pip which ended up successfully.
Now, I don't know what is the standard procedure for testing if a library is working. So I ran setup.py from the main directory of library and I assumed it set things up. Then I ran an example from examples folder and I get this error
Traceback (most recent call last):
File "C:\Users\****\Documents\Python Libraries\pymoskito-master\pymoskito-master\examples\ballbeam\main.py", line 3, in <module>
from PyQt4 import QtGui, QtCore
ImportError: DLL load failed: The specified module could not be found.
I assume python could NOT find the PyQt4 dependencies. I searched stackoverflow and non of the solutions worked. Here is what I tried so far:
There is NO /bin directory in C:\Python35\Lib\site-packages\PyQt4. So all dlls are already in the \PyQt4 directory
I added this directory to System PATH env. var. Same error occurs
I appended this directory to sys.path and tested it. Same error occurs
I created a \bin directory and copied all \PyQt4 into it. Then added it to PATH. Same error occurs
After that, I installed python 2.7 and PyQt4 from riverbankcomputing but not SIP. I still have the same problem
I really don't know what else should I do. I'm actually frustrated by all the mentioning of whether OP is using Python 2 or Python 3 or QT4 or QT5 or x86 or x64. I believe backward compatibility should be the minimum of a programming language and this is definitely a mess for Python
The short answer, I believe is that you have pyqt4 (a python interface to the qt4 library), sip (an automated c++-to-python communication library) but not qt4 itself (the UI library). qt4 is it's own monolithic c++ project with its own build and dependency problems.
You may be able to find the various pieces at http://www.lfd.uci.edu/~gohlke , but I would recommend installing the Anaconda distribution of python ( https://www.continuum.io/downloads ), which provides binary packages for things like qt4 and pyqtgraph, the former of which is installed by default, the latter requiring a command like
conda install pyqtgraph
After this, pip install of pymoskito should work.
There is also mention in the readme of vtk, but it is not in the requirememnts. vtk is also a monolithic c++ library and hard to build, but conda has that too, albeit not in the default channel for py35:
conda install vtk -c menpo

Illegal instruction: 4 when importing python pandas

Since my Macbook with an i7 CPU is currently with AppleCare, I am now working on an older Mac mini with a core duo CPU. I simply connected the Macbook's internal disk via USB to the Mac mini.
Now back at my Python scripts, I ran into a problem which I don't fully understand and do not know how to debug. When I import pandas in Python 2.7.9, Python crashes completely and I get the error Illegal instruction: 4. After some googling I assume, that some packages are compiled for the wrong architecture. But I don't know which ones.
I installed Python, numpy and scipy with homebrew and pandas, etc. with pip into a virtual environment. My system is OS X 10.10.5.
The output of python -vc "import pandas" is very long and given here.
I tried re-installing Python, pandas, numpy, and scipy.
How can I find out which package is causing the error?
Do I need to set an architecture flag or something?
How can I fix this?
Removing the .pyc files might work too.
Since it happens right after the call to
dlopen("/usr/local/lib/python2.7/site-packages/matplotlib/_pabc.so", 2);,
you can try checking the arch type that file was built for with:
file /usr/local/lib/python2.7/site-packages/matplotlib/_pabc.so
then check the arch type of your hardward:
uname -a
If the shared object file (_pabc.so) was not built for that machine you may need to re compile/install/whatever, matplotlib or one of its dependancies.
In my recent experience, this was indeed caused by a linked library being of the wrong architecture as the module's library (as chown suggested).
In particular, a C-compiled python library as part of the python module you're importing (the _mymodule.so file in the module directory) calling a linked system library (eg. libgfortran.dylib), and there being an architecture mismatch between the two.
As aforementioned, you can check the architecture of your system with uname -a and check the arch of an offending dylib via the file /path/to/lib.dylib command.

Problems setting up Python

I recently installed python 3.3.2
Im trying to install NumPy, when I call import NumPy from the command line I get the following error:
import numpy
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named 'numpy'
From what I've read it may have to do with having multiple version of Python installed.
The only problem is when I try run the Which Python command I get another error?
which python
File "<console>", line 1
which python
^
SyntaxError: invalid syntax
Any Ideas?
Thanks
What you have to do depends on the operating system you are using. I'me assuming you are using Linux. If you are using Linux with some kind of package manager, you should use a numpy package that is expressly for the python version you want to us it with. The same goes if you are using windows.
Note that you can have different versions of python installed, but in general only one is symlinked to python. Running ls -l /usr/local/bin/python should tell you what is the default version on your machine. If you have multiple versions, there should also be programs named python2 and python3. Using ls -l /usr/local/bin/python2 and ls -l /usr/local/bin/python3 will show you the which versions you really have.
On linux and other UNIX-like systems, you can usually find Python's files in a subdirectory of /usr/local/lib. For python 2.7 this will be /usr/local/lib/python2.7, for 3.2 it will be /usr/local/lib/python3.3. These directories will have a subdirectory site-packages. In those site-packages you should look for a subdirectory numpy. If you find /usr/local/lib/python2.7/site-packages/numpy but not /usr/local/lib/python3.3/site-packages/numpy, then numpy was not installed for 3.2.
Edit: In Windows, Python usually installs itself in the root of the C: drive, like C:\Python27 or C:\Python33. I don't have a windows machine handy, but there should be a site-packages subdirectory in both of them as well. Look for the numpy subdirectory in there.
For windows, you can find precompiled binaries for mumpy here. You just need to know is you have a 32 bit (win32) or 64 bit version (amd64) of windows. E.g. for python 3.3 and 2 32-bit windows I would suggest numpy-MKL-1.7.1.win32-py3.3.‌exe.
Type open a command prompt and type python It will then tell you what version you are running as it opens the interactive python editor.
Otherwise get your numpy from here These are compiled binaries and should be the most straightforward to install for a windows user

Can't get cx_Oracle to work with Python version 2.7 / mac os 10.7.2 (Lion) - missing_OCIAttrGet

Can't get cx_Oracle to work with Python version 2.7 / mac os 10.7.2 (Lion)
One other thing: I have installed oracle 32 bit, not sure if that was correct.
Traceback (most recent call last):
File "reader.py", line 9, in <module>
import cx_Oracle
File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 7, in <module>
File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/me/.python-eggs/cx_Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_Oracle.so, 2): Symbol not found: _OCIAttrGet
Referenced from: /Users/me/.python-eggs/cx_Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_Oracle.so
Expected in: flat namespace
in /Users/me/.python-eggs/cx_Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_Oracle.so
They key problem seems to be not being able to locate _OCIAttGet, and I think this means that it cant find a lib file or something.
Found on the web, someone talking about DYLD_LIBRARY_PATH, but mine is set, however he mentioned it in cxoracle.cfg file, that I can not locate, is this my problem?
EDIT
After trying to run it with 32 bit mode python, I see a different error.
Traceback (most recent call last):
File "reader.py", line 9, in <module>
import cx_Oracle
File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 7, in <module>
File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 3, in __bootstrap__
ImportError: No module named pkg_resources
I could not get the oracle 64 bit versions to run on my computer, kept getting segmentation faults when i ran sqlplus, so thats why I am using the 32.
SECOND EDIT
Actually no matter what i install, it is not the right version.. 32 bit version
ld: warning: ignoring file /opt/oracle/instantclient10_2/libclntsh.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
64 bit version:
ld: warning: ignoring file /opt/oracle/instantclient10_2/libclntsh.dylib, file was built for unsupported file format which is not the architecture being linked (x86_64)
I am going to try 11g, but that only has a 64 bit version.
To compile cx_Oracle so it'll work on OS X needs a couple of things configured. The important bits are:
Create a virtualenv with a python interpreter stripped to 32-bit only. In the virtualenv bin directory ($WORKON_HOME/*name_of_virtualenv*/bin):
% mv python python.fat
% lipo python.fat -remove x86_64 -output python
Even though Python is now thin its configuration is not so we need to force things using an obscure environment variable that distutils will pick up:
ARCHFLAGS="-arch i386" pip install cx_Oracle
If you are using the Apple-supplied Python 2.7, it will prefer to run in 64-bit mode and that will be a problem if you did install 32-bit-only Oracle libraries. You can try forcing that Python to run in 32-bit mode by starting it this way:
arch -i386 python2.7
If you are careful to always launch python via /usr/bin/python, you could also use either of the methods described in Apple's man page for Python, i.e. setting a VERSIONER_PYTHON_PREFER_32_BIT environment variable or setting a permanent default via defaults.
Steps to install to oracle client on mac ox 10.8.5 for connecting oracle from python. (There is bug due to it 64 bit doesn't work for mac ox 10.8.5 )
Go to http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
Download instantclient-basic-macos.x32-11.2.0.3.0.zip
Download instantclient-sdk-macos.x32-11.2.0.3.0.zip
Create new folder under /Users/< your username>/ora_32(you can name what you want )
Move the zip files instantclient-sdk-macos.x32-11.2.0.3.0.zip and
instantclient-basic-macos.x32-11.2.0.3.0.zip to
/Users/< your username>/ora_32 Command below
mv insta*32* /Users/< your username>/ora_32/
Unzip instantclient-basic-macos.x32-11.2.0.3.0.zip and
instantclient-sdk-macos.x32-11.2.0.3.0.zip
Command below
cd /Users/< your username>/ora_32/
unzip instantclient-basic-macos.x32-11.2.0.3.0.zip
unzip instantclient-sdk-macos.x32-11.2.0.3.0.zip
it will create a folder instantclient_11_2 under
/Users//ora_32/
cd to /Users/< your username>/ora_32/instantclient_11_2
and Create the below symbolic link which
will be used in the installation of cx_Oracle.( Mentioned below )
ln -s libclntsh.dylib.11.1 libclntsh.dylib
ln -s libocci.dylib.11.1 libocci.dylib
Export the environment variables for the current session
or you can add them in bash profile to invoke every time you open
a new terminal.
export ORACLE_HOME=/Users/<your username>/ora_32/instantclient_11_2
export LD_LIBRARY_PATH=$ORACLE_HOME
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export VERSIONER_PYTHON_PREFER_32_BIT=yes
export PATH=$PATH:/Users/<your username>/ora_32/instantclient_11_2
Download cx_Oracle (option source code only)
at the link http://cx-oracle.sourceforge.net
Untar the cx_Oracle tar file and it will create a cx_Oracle-5.1.2 folder
cd to that folder cx_Oracle-5.1.2
Run the below command it will install cx_Oracle and then
sudo easy_install cx_Oracle
You can check by going to python prompt and typing import cx_Oracle
Not certain if you're still having problems with this, but here is how I got it to work.
I followed the instructions listed here (using the 32-bit downloads from Oracle):
http://www.xairon.net/2011/05/guide-installing-cx_oracle-on-mac-os-x/
I then had the same error you listed:
ImportError: dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2): Symbol not found: _OCIAttrGet
Referenced from: /Library/Python/2.7/site-packages/cx_Oracle.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/cx_Oracle.so
The problem was from Apple's Python distribution running in 64-bit mode by default.
Once I forced the Apple supplied Python to use 32-bit (from Ned's recommendation), it worked!
To do that:
$export VERSIONER_PYTHON_PREFER_32_BIT=Yes
To make it permanent:
$defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
I had this same problem. I'm using Mac OS X 10.8.3.
After 4 hours of trying various solutions, I finally realized that this was the result of having installed the 32-bit version of Oracle InstantClient, which conflicted with the 64-bit version of python.
To resolve: I uninstalled python (and some dependencies), then reinstalled the universal version. I followed the directions in this post to strip the x86_64 from the python binary in my virtualenv. This allowed the 32-bit Oracle InstantClient to work with the 32-bit python binary.
I am hesitant to use the 64-bit Oracle InstantClient, due to some other posts I saw while researching this issue.

Understanding concepts of Python installation on Mac OS for Cocoa development

I want to try to develop Cocoa application using Python. I'm new to Mac and I need some help to understand how it works.
First of all I found that I need to install py2app and py2objc. I used easy_install as documented here. There were a few errors with setup tools but eventually py2app was installed. Then I launch "easy_install pyobjc==2.2" and it ended with many errors:
Processing pyobjc-2.2-py2.7.egg
...
Running pyobjc-framework-SystemConfiguration-2.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ipMzFU/pyobjc-framework-SystemConfiguration-2.2/egg-dist-tmp-odfVol
In file included from Modules/_manual.m:1:
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:19:20: error: limits.h: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:22:2: error: #error "Something's broken. UCHAR_MAX should be defined in limits.h."
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:26:2: error: #error "Python's source code assumes C's unsigned char is an 8-bit type."
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:33:19: error: stdio.h: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:35:5: error: #error "Python.h requires that stdio.h define NULL."
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:38:20: error: string.h: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:40:19: error: errno.h: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:42:20: error: stdlib.h: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:44:20: error: unistd.h: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:56:20: error: assert.h: No such file or directory
...
etc
My questions:
What I need to do to install
py2objc? Unfortunately, I haven't
found a solution for errors, which I
posted previously.
As I understand
there are two kinds of python. One I
installed into Applications folder
(IDLE, launcher), another is the
current Python version supplied with
OS. Can you describe the
difference?
How can I select the
current version of Python used by
Mac OS? And what is the Current
folder in
/Library/Frameworks/Python.framework?
Probably it looks confusing, but this is my first steps! :)
Thank you
Cannot give a definitive answer to that. See comment.
You can install multiple versions of python on your machine (OSX includes a defualt one as you already mentioned). In the applications folder there are some apps to open an interactive interpreter in which you can enter python commands, such as IDLE. These applications use one of the python versions you've got installed. Which brings us to
python_select is the command you want. e.g. python_select -l to list all the python versions you've got installed and python_select python27 to select your own 2.7 version. The Current folder links to the version currently selected via python_select

Categories