pyinstaller: _libcouchbase module not found after building the executable - ubuntu-14.04

I have a simple python script that imports couchbase module on Ubuntu 14.04:
$ cat test.py
from couchbase import Couchbase
print 'module _libcouchbase found'
Running from interpreter works fine:
$ python test.py
module _libcouchbase found
Created an executable:
$ pyinstaller test.py
Running the executable throws an error of unable to import _libcouchbase module:
$ ./dist/test/test
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/subba/cb/build/cb/out00-PYZ.pyz/mycouch", line 28, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/subba/cb/build/cb/out00-PYZ.pyz/couchbase", line 28, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/subba/cb/build/cb/out00-PYZ.pyz/couchbase.user_constants", line 21, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/subba/cb/build/cb/out00-PYZ.pyz/couchbase._bootstrap", line 34, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/subba/cb/build/cb/out00-PYZ.pyz/couchbase.exceptions", line 18, in <module>
ImportError: No module named _libcouchbase
It seems very mysterious. Thanks for any thoughts on why this happens!

Try creating a file called hook-couchbase.py with the following content:
import os
import glob
import itertools
try:
# PY_EXTENSION_SUFFIXES is unavailable in older versions
from PyInstaller.hooks.hookutils import PY_EXTENSION_SUFFIXES
except ImportError:
try:
from importlib.machinery import EXTENSION_SUFFIXES as PY_EXTENSION_SUFFIXES
except ImportError:
import imp
PY_EXTENSION_SUFFIXES = set([f[0] for f in imp.get_suffixes()
if f[2] == imp.C_EXTENSION])
def hook(mod):
module_directory = os.path.dirname(mod.__file__)
bundled = []
for libname, ext in itertools.product(('libcouchbase', '_libcouchbase'),
PY_EXTENSION_SUFFIXES):
bundled.extend(glob.glob(os.path.join(module_directory, libname + ext)))
for f in bundled:
name = os.path.join('couchbase', os.path.basename(f))
if hasattr(mod, 'pyinstaller_binaries'):
mod.pyinstaller_binaries.append((name, f, 'BINARY'))
else: # mod.pyinstaller_binaries is unavailable in older versions
mod.binaries.append((name, f, 'BINARY'))
return mod
When building, supply the path to the directory in which you placed the file as a value to the --additional-hooks-dir argument, as follows:
--additional-hooks-dir=<path_to_directory_of_hook_file>

Related

Cannot import pyrebase GAE

I have an application which works perfectly locally. But, for some reason, in GAE (standard python37) it seems to have an issue importing pyrebase (pyrebase==3.0.27 in requirements.txt). Any idea how to fix this?
Thanks in advance!
Traceback (most recent call last):
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
File "/workspace/main.py", line 8, in <module>
import pyrebase
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/pyrebase/__init__.py", line 1, in <module>
from .pyrebase import initialize_app
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/pyrebase/pyrebase.py", line 17, in <module>
from oauth2client.service_account import ServiceAccountCredentials
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/oauth2client/service_account.py", line 25, in <module>
from oauth2client import client
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/oauth2client/client.py", line 47, in <module>
from oauth2client import crypt
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/oauth2client/crypt.py", line 55, in <module>
from oauth2client import _pycrypto_crypt
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/oauth2client/_pycrypto_crypt.py", line 17, in <module>
from Crypto.PublicKey import RSA
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/Crypto/PublicKey/__init__.py", line 29, in <module>
from Crypto.Util.asn1 import (DerSequence, DerInteger, DerBitString,
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/Crypto/Util/asn1.py", line 33, in <module>
from Crypto.Util.number import long_to_bytes, bytes_to_long
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/Crypto/Util/number.py", line 398
s = pack('>I', n & 0xffffffffL) + s
SyntaxError: invalid syntax
Pyrebase 3.0.27 is having compatibility issue with Python version 3. Instead, use the latest version of Pyrebase: Pyrebase4.
The OP solved the problem by changing Pyrebase version in requirements.txt:
From pyrebase==3.0.27 to Pyrebase4==4.5.0

error in running exe made by using pyinstaller having sklearn packages and xgboost

i have made a exe file from a python file which have multiple import from our own files and have package sklearn, xgboost, pandas and other sklaern packages. during exe preparation thier is no error while running it it throw error
Traceback (most recent call last):
File "probability_score_engine.py", line 16, in <module>
import sklearn.ensemble
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\__init__.py", line 76, in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\base.py", line 16, in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\utils\__init__.py", line 20, in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\utils\validation.py", line 21, in
<module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\utils\fixes.py", line 18, in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\scipy\sparse\linalg\__init__.py", line 113, in
<module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6,
in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 10,
in <module>
ImportError: DLL load failed: The specified module could not be found.
[10668] Failed to execute script probability_score_engine
i have use add data for xgboost when it throw error in not finding dll files for xgboost but it throw error for sklearn. i have made a exe of one file but that file call other other python files function by using import.
Both sklearn and xgboost needs special care when using with Pyinstaller. I'm skipping importing xgboost but here is a useful answer about using it with Pyinstaller.
It seems that when you add xgboostPyinstaller can't handle some modules like scipy. A simple approach is to add the whole scipy in Python's sit-package to your executable as data. So edit your spec file and add this after Analysis:
# -*- mode: python -*-
block_cipher = None
a = Analysis(
datas=[('./env/xgboost/*', 'xgboost/'), ('./env/Lib/site-packages/xgboost/VERSION', 'xgboost/')],
...
)
# add here
a.datas += Tree('<path_to_scipy_in_python_dir>', prefix='scipy')
...
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
And finally, generate your executable with pyinstaller script.spec.

PIP3 exceptions on Rasperry Pi

I have installed pip3 on my raspberry pi but when I run it the following error pops up. I already tried reinstalling it. Anyone knows this error?
pi#henriette ~/servokit $ pip3
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 9, in <module>
load_entry_point('pip==19.0.3', 'console_scripts', 'pip3')()
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 337, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2280, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 1990, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/__init__.py", line 40, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/cli/cmdoptions.py", line 19, in <module>
from pip._internal.locations import USER_CACHE_DIR, src_prefix
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/locations.py", line 13, in <module>
from pip._internal.utils import appdirs
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/utils/appdirs.py", line 12, in <module>
from pip._internal.utils.compat import WINDOWS, expanduser
File "/usr/local/lib/python3.2/dist-packages/pip/_internal/utils/compat.py", line 67
return u"".join(u"\\x%x" % c for c in raw_bytes), err.end
^
SyntaxError: invalid syntax
Python 3.2 doesn't support u"" unicode strings. Upgrade to Python 3.4+.

pyramid pserve pviews P* re.compile syntax error

I used to launch the command pserve --reload development.ini in my vagrant box to launch a pyramid server locally. The command was working until the last few days.
However, I now have a syntax error preventing me from launching pserve with or without conf file.
(py32)vagrant.vm bin # pserve
Traceback (most recent call last):
File "/var/virtualenv/py32/bin/pserve", line 9, in <module>
load_entry_point('pyramid==1.5.1', 'console_scripts', 'pserve')()
File "/var/virtualenv/py32/lib/python3.2/site-packages/pkg_resources/__init__.py", line 519, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/var/virtualenv/py32/lib/python3.2/site-packages/pkg_resources/__init__.py", line 2630, in load_entry_point
return ep.load()
File "/var/virtualenv/py32/lib/python3.2/site-packages/pkg_resources/__init__.py", line 2310, in load
return self.resolve()
File "/var/virtualenv/py32/lib/python3.2/site-packages/pkg_resources/__init__.py", line 2316, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid/scripts/pserve.py", line 31, in <module>
from pyramid.paster import setup_logging
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid/paster.py", line 10, in <module>
from pyramid.scripting import prepare
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid/scripting.py", line 1, in <module>
from pyramid.config import global_registries
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid/config/__init__.py", line 9, in <module>
from webob.exc import WSGIHTTPException as WebobWSGIHTTPException
File "/var/virtualenv/py32/lib/python3.2/site-packages/webob/__init__.py", line 2, in <module>
from webob.request import *
File "/var/virtualenv/py32/lib/python3.2/site-packages/webob/request.py", line 10, in <module>
import simplejson as json
File "/var/virtualenv/py32/lib/python3.2/site-packages/simplejson/__init__.py", line 113, in <module>
from .encoder import JSONEncoder, JSONEncoderForHTML
File "/var/virtualenv/py32/lib/python3.2/site-packages/simplejson/encoder.py", line 22
ESCAPE = re.compile(u'[\\x00-\\x1f\\\\"\\b\\f\\n\\r\\t\u2028\u2029]')
^
SyntaxError: invalid syntax
I use python 3.2.3 in this virtualenv
pviews and proutes give the same error
Any help appreciated :)
Regards
==========================
Thanks to Steve Piercy I uninstalled simplejson and pserve now works launched alone! Thanks again.
However, when I launch pserve development.ini, I now have another error:
(py32)vagrant.vm app # pserve --reload development.ini
Starting subprocess with file monitor
Traceback (most recent call last):
File "/var/virtualenv/py32/bin/pserve", line 9, in <module>
load_entry_point('pyramid==1.5.1', 'console_scripts', 'pserve')()
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid/scripts/pserve.py", line 51, in main
return command.run()
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid/scripts/pserve.py", line 316, in run
global_conf=vars)
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid/scripts/pserve.py", line 340, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
File "/var/virtualenv/py32/lib/python3.2/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/var/virtualenv/py32/lib/python3.2/site-packages/paste/deploy/loadwsgi.py", line 272, in loadobj
return context.create()
File "/var/virtualenv/py32/lib/python3.2/site-packages/paste/deploy/loadwsgi.py", line 710, in create
return self.object_type.invoke(self)
File "/var/virtualenv/py32/lib/python3.2/site-packages/paste/deploy/loadwsgi.py", line 146, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/var/virtualenv/py32/lib/python3.2/site-packages/paste/deploy/util.py", line 56, in fix_call
val = callable(*args, **kw)
File "/var/www/app/app/__init__.py", line 63, in main
request_factory=RequestFactory,
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid/config/__init__.py", line 301, in __init__
exceptionresponse_view=exceptionresponse_view,
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid/config/__init__.py", line 412, in setup_registry
self.include(inc)
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid/config/__init__.py", line 755, in include
c(configurator)
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid_jinja2/__init__.py", line 468, in includeme
_get_or_build_default_environment(config.registry)
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid_jinja2/__init__.py", line 309, in _get_or_build_default_environment
filters = parse_config(settings.get('jinja2.filters', ''))
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid_jinja2/__init__.py", line 62, in parse_config
result[name.strip()] = maybe_import_string(impl)
File "/var/virtualenv/py32/lib/python3.2/site-packages/pyramid_jinja2/__init__.py", line 44, in maybe_import_string
return import_string(val.strip())
File "/var/virtualenv/py32/lib/python3.2/site-packages/jinja2/utils.py", line 213, in import_string
return getattr(__import__(module, None, None, [obj]), obj)
File "/var/www/app/app/views/filters.py", line 1, in <module>
from babel.dates import format_datetime, get_timezone, format_timedelta, format_date, UTC
File "/usr/lib/python3.2/importlib/_bootstrap.py", line 436, in load_module
return self._load_module(fullname)
File "/usr/lib/python3.2/importlib/_bootstrap.py", line 141, in decorated
return fxn(self, module, *args, **kwargs)
File "/usr/lib/python3.2/importlib/_bootstrap.py", line 342, in _load_module
exec(code_object, module.__dict__)
File "/tmp/pip-build-z2s2e9/babel/babel/__init__.py", line 20, in <module>
File "/var/virtualenv/py32/lib/python3.2/site-packages/babel/core.py", line 394
retval += ' (%s)' % u', '.join(details)
^
SyntaxError: invalid syntax
I tried to uninstall-reinstall babel with no luck.
Thanks for your help!
Did you recently install simplejson? It was and never will be compatible with Python 3.0 - 3.2. See https://github.com/simplejson/simplejson/issues/66#issuecomment-15360824

PyInstaller statsmodels.stats.diagnostic import kstest_normal

I'm using pyinstaller on one of my scripts but I'm getting an error on the line of code I wrote:
from statsmodels.stats.diagnostic import kstest_normal
The command I used was
pyinstaller fitness_of_statistical_tests.py --hidden-import=scipy.linalg.cython_blas --hidden-import=scipy.linalg.cython_lapack
The full error I get is:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\pandas\__init__.py", line 7, in <module>
from pandas import hashtable, tslib, lib
ImportError: cannot import name 'lib'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 9, in <module>
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "D:\SEDS\gahndiwashingtonmethod\fitness_of_statistical_tests_view.py", line 11, in <module>
from statsmodels.stats.diagnostic import kstest_normal
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\__init__.py", line 8, in <module>
from .tools.sm_exceptions import (ConvergenceWarning, CacheWriteWarning,
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\tools\__init__.py", line 1, in <module>
from .tools import add_constant, categorical
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\tools\tools.py", line 11, in <module>
from statsmodels.datasets import webuse
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\datasets\__init__.py", line 5, in <module>
from . import (anes96, cancer, committee, ccard, copper, cpunish, elnino,
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\datasets\anes96\__init__.py", line 1, in <module>
from .data import *
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\datasets\anes96\data.py", line 90, in <module>
from statsmodels.datasets import utils as du
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\statsmodels\datasets\utils.py", line 13, in <module>
from pandas import read_csv, DataFrame, Index
File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 311, in load_module
exec(bytecode, module.__dict__)
File "C:\Python34\lib\site-packages\pandas\__init__.py", line 13, in <module>
"extensions first.".format(module))
ImportError: C extension: 'lib' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.
fitness_of_statistical_tests returned -1
All of these imports work in the python interpreter, but it's just when I run the exe from PyInstaller that all this stuff breaks.

Resources