Using cx_freeze with PyQT5 and Python 3 on MacOSX - macos

I'm trying to use cx_freeze 4.3.3 on a MacOS running 10.9.2 on a very simple PyQt5 script with Python 3.3.
No errors are returned and the .app is output. However when running the .app from terminal I obtain the error:
LSOpenURLsWithRole() failed with error -10810
which according to Apple's documentation is "Unknown Error".
The very simple code I try to run (PyQt5app.py) is:
import sys
from PyQt5.QtWidgets import QApplication, QDialog
app = QApplication(sys.argv)
form = QDialog()
form.show()
app.exec_()
The file setup.py is:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
options = {
'build_exe': {
'excludes': ['Tkinter'] # Sometimes a little finetuning is needed
}
}
executables = [
Executable('PyQt5app.py', base=base)
]
setup(name='PyQt5app',
version='0.1',
description='Sample PyQt5 GUI',
executables=executables,
options=options
)
and when running I call:
sudo python cx_freeze bdist_mac
obtaining this log : http://pastebin.com/VBxyyBRn
with app returning error above.
So, reading around I see it might be a problem related to including qt files in the app (or at least this was the issue on PyQt4) so I try specifying the qt-menu-nib directory:
sudo python setup.py bdist_mac --qt-menu-nib=/Users/franco/Qt5.2.1/5.2.1/clang_64/plugins/platforms/
obtaining this log: http://pastebin.com/TpRdrSmT
and the same not working error.
If I run the app from PyQt5app.app/Contents/MacOS/PyQt5app I get a lot of bootstrap errors:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/cx_Freeze-4.3.3-py3.3-macosx-10.9-x86_64.egg/cx_Freeze/initscripts/Console.py", line 27, in <module>
exec(code, m.__dict__)
File "PyQt5app.py", line 5, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 1565, in _find_and_load
return _find_and_load_unlocked(name, import_)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 1532, in _find_and_load_unlocked
loader.load_module(name)
File "ExtensionLoader_PyQt5_QtWidgets.py", line 22, in <module>
File "ExtensionLoader_PyQt5_QtWidgets.py", line 14, in __bootstrap__
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 1565, in _find_and_load
return _find_and_load_unlocked(name, import_)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 1532, in _find_and_load_unlocked
loader.load_module(name)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 584, in _check_name_wrapper
return method(self, name, *args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 495, in set_package_wrapper
module = fxn(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 508, in set_loader_wrapper
module = fxn(self, *args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 1132, in load_module
fullname, self.path)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 313, in _call_with_frames_removed
return f(*args, **kwds)
SystemError: initialization of sip raised unreported exception
Needless to say the script works fine when launching from terminal:
python PyQt5app.py
I most certainly am doing something wrong, so please, can anybody help me?

So, after long fighting here is the issue: libzmq .
I installed libzmq and specified the --qt-menu-nib option and the simple example above runs in both:
sudo python setup.py build
and
sudo python setup.py bdist_mac
Step by step instructions:
I used mac ports for most of my python33 packages so I sticked to it for the rest.
Libzmq is not available on macports but its dependencies are.
So:
1) install libtool, autoconf, automake:
sudo port install libtool
sudo port install autoconf
sudo port install automake
2) grab the latest version of libzmq from https://github.com/zeromq/libzmq ( I downloaded the ZIP for sake of order ) and unzip/navigate to the folder
/libzmq-master
now the instructions provided in the INSTALL document in the folder are pretty clear, if you installed all the dependencies then you will be fine.
run:
sudo ./autogen.sh
sudo ./configure
sudo make
sudo make install
3) download the latest cx_freeze from https://bitbucket.org/anthony_tuininga/cx_freeze/downloads then unzip/untar navigate to folder and run:
sudo python setup.py build
sudo python setup.py install
now when compiling code for MacOSX that uses Python3.3 and PyQt5 you can run:
sudo python setup.py build
then navigate in the build folder and run the program as:
./nameoftheprogram
once you made sure this work then build the app or dmg (as you prefer) with:
sudo python setup.py bdist_mac --qt-menu-nib=/Users/username/Qt5.2.1/5.2.1/clang_64/plugins/platforms/
where the path is the path to your Qt5 installation. If I don't use the --qt-menu-nib option the app crashes on startup whereas the build works fine.
Hope this will help someone in the future.

I got the same error and recompiling with the latest version of ZMQ (4.0.4) did not solve the issue.
However, by looking in the messages of the /Applications/Utilities/Console.app program, I could see that an extra command line option was given to my Python program. This command line option always started with -psn_0_ followed by a number. Apparently psn stands for Process Serial Number (see: http://hintsforums.macworld.com/showthread.php?t=11978).
My program uses the argparse package to parse the command line arguments and exited with an error because it didn't recognized the -psn option. I now filter it out before parsing with argparse and this solved my problem.

Related

OSX 10.14 script compiled as stand-alone executable using pyinstall if script include import scipy.stats

Under Mac OSX 10.14 (but not under OS 10.12) stand-alone executables compiled with pyinstaller fail if the script includes "import scipy.stats" or "from scipy import stats"
python 2.7.15. pyinstaller 3.4 scipy 1.2.1
macOS 10.14.4
Scripts run fine using python interpreter, but when compiled as a one-file executable using pyinstaller -F scriptName.py pyinstaller succeeds, but when the executable is run I get the error below.
This does not happen under either Windows or Linux, and does not happen if I compile the script on an older laptop run OS10.12.6.
I have updated to the most recent version of both pyinstaller and scipy.
The rest of the code does not seem to matter. Executable fails whenever scipy.stats is imported.
import scipy.stat
s
or
from scipy import stats
Traceback (most recent call last): File
"site-packages/PyInstaller/loader/rthooks/pyi_rth_pkgres.py", line 11,
in File
"lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py",
line 395, in load_module File
"site-packages/pkg_resources/init.py", line 959, in
File "site-packages/pkg_resources/init.py", line 963, in
Environment File "site-packages/pkg_resources/init.py", line
190, in get_supported_platform File
"site-packages/pkg_resources/init.py", line 395, in
get_build_platform File "sysconfig.py", line 618, in get_platform
File "sysconfig.py", line 482, in get_config_vars File
"sysconfig.py", line 365, in _init_posix ImportError: No module named
_sysconfigdata [18734] Failed to execute script pyi_rth_pkgres
`
When building with pyinstaller use:
pyinstaller -F scriptName.py --hiddenimport _sysconfigdata
Reference:
↳ https://github.com/pyinstaller/pyinstaller/issues/3198

How to debug pip install <package name>

If I want to debug the setup.py file of my package packagename getting installed via "pip install packagename" , is there a way to do so? I have tried downloading the source, adding set_trace() in setup.py and run:
pip install .
However, as soon I get pdb() prompt, the install fails with error:
processing /Users/skauser/python-ibmdb/IBM_DB/ibm_db
Complete output from command python setup.py egg_info:
> /private/var/folders/b6/pmddncpn77550p8_g9kkx9f40000gp/T/pip-req-build-_fg8s5a2/setup.py(31)<module>()
-> machine_bits = 8 * struct.calcsize("P")
(Pdb)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/b6/pmddncpn77550p8_g9kkx9f40000gp/T/pip-req-build-_fg8s5a2/setup.py", line 31, in <module>
machine_bits = 8 * struct.calcsize("P")
File "/private/var/folders/b6/pmddncpn77550p8_g9kkx9f40000gp/T/pip-req-build-_fg8s5a2/setup.py", line 31, in <module>
machine_bits = 8 * struct.calcsize("P")
File "/Library/anaconda3/lib/python3.7/bdb.py", line 88, in trace_dispatch
return self.dispatch_line(frame)
File "/Library/anaconda3/lib/python3.7/bdb.py", line 113, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/b6/pmddncpn77550p8_g9kkx9f40000gp/T/pip-req-build-_fg8s5a2/
Although I can debug the source via: python setup.py build, the behavior that I want to debug is applicable when installed through pip.
Pip is a python program. You can see it's content with cat $(which pip). Then you can copy it to a new file in your project's directory. For example, here is how it looks like for me:
File mypip.py:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Then you can add a breakpoint with pdb or use PyCharm as mentioned in the answer from Igor Yudnikov.
For reference, this is how it to looks like in my Pycharm
Oh! Just found a solution, its pretty easy. What is pip? It's a plain python file, which is I think somehow bound to run via python, and under the hood system makes something like
python pip install ...
so, at first we need to know where is pip
which pip
says
/Users/me/PycharmProjects/etlscripts/venv/bin/pip
So, we may go to Pycharm, create config like
then you'll be able to catch your exception. Cheers.

catch_config_error while trying to run ipython3

I'm getting the following error trying to run ipython3.
catch_config_error() missing 1 required positional argument: 'app'
I first got it on my Mac (python36). As my system has all sorts of customizations, I tried it again on a Linux system (Centos 7.4). I install ipython using pip3 and everything seemed to install cleanly. (On the same system, if i do this with python2, it seems to work.
Complete error log:
[scott] ipython3
Traceback (most recent call last):
File "/usr/bin/ipython3", line 7, in <module>
from IPython import start_ipython
File "/usr/lib/python3.4/site-packages/IPython/__init__.py", line 54, in <module>
from .core.application import Application
File "/usr/lib/python3.4/site-packages/IPython/core/application.py", line 23, in <module>
from traitlets.config.application import Application, catch_config_error
File "/usr/lib/python3.4/site-packages/traitlets/config/__init__.py", line 6, in <module>
from .application import *
File "/usr/lib/python3.4/site-packages/traitlets/config/application.py", line 120, in <module>
class Application(SingletonConfigurable):
File "/usr/lib/python3.4/site-packages/traitlets/config/application.py", line 291, in Application
def initialize(self, argv=None):
TypeError: catch_config_error() missing 1 required positional argument: 'app'
This is happening because traitlets relies on a package called 'decorator' that was just updated from 4.1.2 to 4.2.0 and broken its backward compatibility.
If you're using a requirements file or pip, install decorator==4.1.2 before installing IPython.
I tried in Ubuntu 16.04.
I also had the same problem (Python 3.6)
I tried again today.
$ sudo -H pip3 install --upgrade ipython
Then, decorator 4.2.1 is newly installed and the problem is solved.

pip install --user error under OS X (virtualenv doesn't fix it)

I used to install python (2.7.6) packages using sudo pip install [...] until I recently decided that this was a bad idea and I should use: pip install --user [...] instead.
Since I am using Mac OS X (10.10.3), my python modules had been installed into /Library/Python/2.7/site-packages. Now, with the --user option enabled, they are being installed into: /Users/USER/Library/Python/2.7/lib/python/site-packages
I have since moved all packages (including pip/setuptools) into this destination, adjusted my $PYTHONPATH and changed the file ownership to my local user. I expected that I would now be able to call pip install --user [..] and everything should go smoothly.
Unfortunately, this is not the case. For any pip install (or pip install --upgrade) command I receive the same error (below). The same is true when using a virtualenv - the same error shows up and I have no clue why.
However, everything does work "fine", when I use sudo pip install --user, which is why I assume that it is somehow related to a file-permission error I can not see. (It's not exactly fine, as the newly installed package will be in the right location, but all files are owned by root.)
Any idea what I am doing wrong or how to debug this?
pip install --upgrade --user tornado
Collecting tornado
Using cached tornado-4.1.tar.gz
Exception:
Traceback (most recent call last):
File "/Users/USER/Library/Python/2.7/lib/python/site-packages/pip/basecommand.py", line 223, in main
status = self.run(options, args)
File "/Users/USER/Library/Python/2.7/lib/python/site-packages/pip/commands/install.py", line 280, in run
requirement_set.prepare_files(finder)
File "/Users/USER/Library/Python/2.7/lib/python/site-packages/pip/req/req_set.py", line 317, in prepare_files
functools.partial(self._prepare_file, finder))
File "/Users/USER/Library/Python/2.7/lib/python/site-packages/pip/req/req_set.py", line 304, in _walk_req_to_install
more_reqs = handler(req_to_install)
File "/Users/USER/Library/Python/2.7/lib/python/site-packages/pip/req/req_set.py", line 483, in _prepare_file
abstract_dist.prep_for_dist()
File "/Users/USER/Library/Python/2.7/lib/python/site-packages/pip/req/req_set.py", line 123, in prep_for_dist
self.req_to_install.run_egg_info()
File "/Users/USER/Library/Python/2.7/lib/python/site-packages/pip/req/req_install.py", line 368, in run_egg_info
self.setup_py, self.name,
File "/Users/USER/Library/Python/2.7/lib/python/site-packages/pip/req/req_install.py", line 339, in setup_py
import setuptools # noqa
File "/Users/USER/Library/Python/2.7/lib/python/site-packages/setuptools/__init__.py", line 11, in <module>
from setuptools.extension import Extension
File "/Users/USER/Library/Python/2.7/lib/python/site-packages/setuptools/extension.py", line 8, in <module>
from .dist import _get_unpatched
File "/Users/USER/Library/Python/2.7/lib/python/site-packages/setuptools/dist.py", line 21, in <module>
packaging = pkg_resources.packaging
AttributeError: 'module' object has no attribute 'packaging'
I also checked the location of pkg_resources and deleted pkg_resources.pyc, which is located in /usr/local/lib/python2.7/site-packages for some reason, but it didn't change anything. (My local user also has full access rights in this location.)
[UPDATE:]
For some reason I was able to install virtualenv without root (pip install --user virtualenv), but all other packages I tried still fail. Also, if I switch to a new virtual environment, I still receive the same error. I am now thinking this is related to my $PYTHONPATH variable, which appears to not be updated for my virtualenv, but I haven't found the real solution, yet.
Alright, so I found the actual problem and solution. My $PYTHONPATH contained an invalid directory. I setup my $PYTHONPATH a long time ago and wrote it into a .bashrc (or more accurately .bash_profile) script.
pip was probably looking through all directories in $PYTHONPATH, although I don't know what it is doing in each of them that causes the above error, but removing the invalid directory fixed my problems.
I also now highly recommend to just use virtualenv instead of a static setup.

HTTPLIB2 Error installing python-twitter on mac osx

Hello I am trying to install python-twitter and one of the dependencies HTTPLIB2 is giving me a lot of problems. I have searched the internet up and down but maybe I do not know what the right key words are. Here is the problem.
I am installing python-twitter. I install the requirements either by "pip install -r requirements.txt" or doing them one by one through for example "pip install httplib2". Then I run "python setup.py install". It's happy but then "python setup.py test" fails as followed with an error on import HTTPLIB2.
python setup.py test
running test
running egg_info
writing requirements to python_twitter.egg-info/requires.txt
writing python_twitter.egg-info/PKG-INFO
writing top-level names to python_twitter.egg-info/top_level.txt
writing dependency_links to python_twitter.egg-info/dependency_links.txt
reading manifest file 'python_twitter.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching '.DS_Store'
writing manifest file 'python_twitter.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
File "setup.py", line 73, in <module>
Main()
File "setup.py", line 66, in Main
setuptools.setup(**METADATA)
File
....
<deleted these parts to save space>
module = __import__('.'.join(parts_copy))
File "/Users/ME/Downloads/python-twitter-1.0/twitter_test.py", line 30, in <module>
import twitter
File "/Users/ME/Downloads/python-twitter-1.0/twitter.py", line 65, in <module>
import oauth2 as oauth
File "/usr/local/lib/python2.7/site-packages/oauth2/__init__.py", line 32, in <module>
import httplib2
File "/usr/local/lib/python2.7/site-packages/httplib2/__init__.py", line 347
print('%s:' % h, end=' ', file=self._fp)
^
SyntaxError: invalid syntax
But I thought the print error was an incompatibility between python 2 and 3. Why am I getting this while I clearly have python 2.7 (I checked and uninstalled and reinstalled HTTPLIB2).
Thanks much for your help
i had a same issue. It seems to be python2.7 and 3.x version conflict issue and resolved by
python2.7 -m pip install -t lib/ -r requirements.txt
Just in case, this happens when you install httplib2 with a python3 version of pip and then execute it with python2.
This happens for example when creating manually an environment with:
pip install -t lib/ -r requirements
As it happens when creating an AppEngine standard environment vendor folder.
This happens because contrary to most of the libraries, httplib2 has completely different versions for python2 and python3.

Resources