Packaging Bokeh with py2exe - matplotlib

I've got an python application that generates charts using BOKEH (0.12), the charts are all standalone (i.e BOKEHJS gets inlined) so that there's no need for the browser to go onto the web to find the CDN or make any external connections.
It all works fine when I am running it from Eclipse, chart displays no problem. But when I try to package it with py2exe, the html file is created but no chart is shown when I open it in browser. This is what my setup.py looks like
from distutils.core import setup
import py2exe
import os
import psutil
import pkg_resources
import inspect
import matplotlib
import sys
import bokeh.core
import zipfile
sys.setrecursionlimit(5000)
includes=["sqlite3","PyQt4","decimal","bokeh.core","jinja2","matplotlib","mpl_toolkits","matplotlib.backends.backend_wx","bokeh"]
excludes=[]
packages=["pkg_resources"]
dll_excludes=['libgdk-win32-1.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll', 'msvcp90.dll','msvcr71.dll', 'IPHLPAPI.DLL', 'NSI.dll', 'WINNSI.DLL', 'WTSAPI32.dll']
dir_name = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # script directory
parent_dir_name=os.path.abspath(os.path.join(dir_name,os.pardir))
iconfile_config_location = "my_icon.ico"
configuration_location = "my_configuration.ini"
database_location = "localDB"
datafiles = [('', [configuration_location,database_location])]
datafiles.extend(matplotlib.get_py2exe_datafiles())
current_dir = os.path.dirname(os.path.realpath(__file__))
dist_dir = os.path.join(current_dir, "release")
setup(
options={"py2exe": {"compressed": 2,
"optimize": 0,#string or int of optimization level (0, 1, or 2) 0 = do not optimize (generate .pyc) 1 = normal optimization (like python -O) 2 = extra optimization (like python -OO)
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
"bundle_files": 2,
"dist_dir": "release",
"xref": False,
"skip_archive": False,
"ascii": False,
"custom_boot_script": '',
}
},
windows=[{"script":"main.py","icon_resources": [(1, iconfile_config_location)],}],
data_files= datafiles
)
# Add boke/core/_templates files to the library.zip file
bokeh_path = sys.modules['bokeh.core'].__path__[0]
zipfile_path = os.path.join(dist_dir, "library.zip")
z = zipfile.ZipFile(zipfile_path, 'a')
for dirpath,dirs,files in os.walk(os.path.join(bokeh_path, '_templates')):
for f in files:
fn = os.path.join(dirpath, f)
z.write(fn, os.path.join(dirpath[dirpath.index('bokeh'):], f))
z.close()
Can anyone guide me on how to package Bokeh so that the resulting executable can make use of it. (i.e everything gets bundled in together) is it possible?
I also noticed that when I set the optimize option to 2, it doesn't work, I get the error
File "zipextimporter.pyo", line 82, in load_module
File "bokeh\plotting\__init__.pyo", line 2, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "bokeh\document.pyo", line 36, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "bokeh\model.pyo", line 12, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "bokeh\core\properties.pyo", line 73, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "bokeh\core\enums.pyo", line 25, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "bokeh\icons.pyo", line 78, in <module>
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'
Any ideas

Related

yolov7 ImportError: DLL load failed while importing _fblas: %1 is not a Win32 application

When I start the tutorial it shows an error. I am using windows 11 64 bit. I installed all the packages through anaconda, and I can’t understand what the problem could be. (Python 3.9)
Traceback (most recent call last):
File "C:\Users\iirof\PycharmProjects\rf_detect_mob\yolov7-custom\train.py", line 24, in <module>
import test # import test.py to get mAP after each epoch
File "C:\Users\iirof\PycharmProjects\rf_detect_mob\yolov7-custom\test.py", line 12, in <module>
from models.experimental import attempt_load
File "C:\Users\iirof\PycharmProjects\rf_detect_mob\yolov7-custom\models\experimental.py", line 6, in <module>
from models.common import Conv, DWConv
File "C:\Users\iirof\PycharmProjects\rf_detect_mob\yolov7-custom\models\common.py", line 17, in <module>
from utils.plots import color_list, plot_one_box
File "C:\Users\iirof\PycharmProjects\rf_detect_mob\yolov7-custom\utils\plots.py", line 19, in <module>
from scipy.signal import butter, filtfilt
File "C:\Users\iirof\anaconda3\envs\rf\lib\site-packages\scipy\signal\__init__.py", line 309, in <module>
from . import _sigtools, windows
File "C:\Users\iirof\anaconda3\envs\rf\lib\site-packages\scipy\signal\windows\__init__.py", line 41, in <module>
from ._windows import *
File "C:\Users\iirof\anaconda3\envs\rf\lib\site-packages\scipy\signal\windows\_windows.py", line 7, in <module>
from scipy import linalg, special, fft as sp_fft
File "C:\Users\iirof\anaconda3\envs\rf\lib\site-packages\scipy\__init__.py", line 233, in __getattr__
return _importlib.import_module(f'scipy.{name}')
File "C:\Users\iirof\anaconda3\envs\rf\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\iirof\anaconda3\envs\rf\lib\site-packages\scipy\linalg\__init__.py", line 197, in <module>
from ._misc import *
File "C:\Users\iirof\anaconda3\envs\rf\lib\site-packages\scipy\linalg\_misc.py", line 3, in <module>
from .blas import get_blas_funcs
File "C:\Users\iirof\anaconda3\envs\rf\lib\site-packages\scipy\linalg\blas.py", line 213, in <module>
from scipy.linalg import _fblas
ImportError: DLL load failed while importing _fblas: %1 не является приложением Win32.
Tried to install different versions of python, but nothing new.

Error when installing Pandas on Solaris 10

Currently we are on Python 2.7.17, and we are getting the following error:
sbdsvrwm261# ./pip install pandas
Traceback (most recent call last):
File "./pip", line 9, in <module>
load_entry_point('pip==8.1.2', 'console_scripts', 'pip')()
File "/opt/csw/lib/python2.7/site-packages/pkg_resources/__init__.py", line 565, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/opt/csw/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
return ep.load()
File "/opt/csw/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2291, in load
return self.resolve()
File "/opt/csw/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2297, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/opt/csw/lib/python2.7/site-packages/pip/__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/opt/csw/lib/python2.7/site-packages/pip/vcs/subversion.py", line 9, in <module>
from pip.index import Link
File "/opt/csw/lib/python2.7/site-packages/pip/index.py", line 30, in <module>
from pip.wheel import Wheel, wheel_ext
File "/opt/csw/lib/python2.7/site-packages/pip/wheel.py", line 39, in <module>
from pip._vendor.distlib.scripts import ScriptMaker
File "/opt/csw/lib/python2.7/site-packages/pip/_vendor/distlib/scripts.py", line 14, in <module>
from .compat import sysconfig, detect_encoding, ZipFile
File "/opt/csw/lib/python2.7/site-packages/pip/_vendor/distlib/compat.py", line 31, in <module>
from urllib2 import (Request, urlopen, URLError, HTTPError,
ImportError: cannot import name HTTPSHandler
If you require further information from me, please let me know.
Thanks
Pandas officially supports Python ^3.5.3.
Have you tried using virtualenv or docker to get Python 3.*?

Tensorflow error - tensorflow.python.framework.errors_impl.NotFoundError: /home/paperspace/nmt-chatbot/data/tst2012.from; No such file or directory

I have been following the sentdex tutorial on a tensorflow chatbot, and on coming t train the chatbot using nmt, tensorflow repeatedly spits out -
tensorflow.python.framework.errors_impl.NotFoundError: /home/paperspace/nmt-chatbot/data/tst2012.from; No such file or directory
I have tried uninstalling and reinstalling tensorflow, but nothing is working
The following is all the error messages I receive:
Traceback (most recent call last):
File "train.py", line 18, in <module>
tf.app.run(main=nmt.main, argv=[os.getcwd() + '\nmt\nmt\nmt.py'] + unparsed)
File "/home/paperspace/.local/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "/home/paperspace/nmt-chatbot/nmt/nmt/nmt.py", line 539, in main
run_main(FLAGS, default_hparams, train_fn, inference_fn)
File "/home/paperspace/nmt-chatbot/nmt/nmt/nmt.py", line 532, in run_main
train_fn(hparams, target_session=target_session)
File "/home/paperspace/nmt-chatbot/nmt/nmt/train.py", line 229, in train
sample_src_data = inference.load_data(dev_src_file)
File "/home/paperspace/nmt-chatbot/nmt/nmt/inference.py", line 75, in load_data
inference_data = f.read().splitlines()
File "/usr/lib/python3.6/codecs.py", line 495, in read
newdata = self.stream.read()
File "/home/paperspace/.local/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py", line 119, in read
self._preread_check()
File "/home/paperspace/.local/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py", line 79, in _preread_check
compat.as_bytes(self.__name), 1024 * 512, status)
File "/home/paperspace/.local/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 473, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.NotFoundError: /home/paperspace/nmt-chatbot/data/tst2012.from; No such file or directory
The code in the train.py file is...
import sys
import os
import argparse
from setup.settings import hparams
sys.path.append(os.path.realpath(os.path.dirname(__file__)))
sys.path.append(os.path.realpath(os.path.dirname(__file__)) + "/nmt")
from nmt import nmt
import tensorflow as tf
# Modified autorun from nmt.py (bottom of the file)
# We want to use original argument parser (for validation, etc)
nmt_parser = argparse.ArgumentParser()
nmt.add_arguments(nmt_parser)
# But we have to hack settings from our config in there instead of commandline options
nmt.FLAGS, unparsed = nmt_parser.parse_known_args(['--'+k+'='+str(v) for k,v in hparams.items()])
# And now we can run TF with modified arguments
tf.app.run(main=nmt.main, argv=[os.getcwd() + '\nmt\nmt\nmt.py'] + unparsed)
Any help would be really appreciated

Tensorflow NotFoundError: data/mscoco_label_map.pbtxt; No such file or directory

I am trying to run this script from the YouTuber sentdex, but I get this error:
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
The backend was *originally* set to 'TkAgg' by the following code:
File "Desktop/object.py", line 11, in <module>
from matplotlib import pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 71, in <module>
from matplotlib.backends import pylab_setup
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/__init__.py", line 16, in <module>
line for line in traceback.format_stack()
import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements
Traceback (most recent call last):
File "Desktop/object.py", line 86, in <module>
label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
File "/home/wdjpng/.local/lib/python2.7/site-packages/tensorflow/models/research/object_detection/utils/label_map_util.py", line 132, in load_labelmap
label_map_string = fid.read()
File "/home/wdjpng/.local/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py", line 120, in read
self._preread_check()
File "/home/wdjpng/.local/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py", line 80, in _preread_check
compat.as_bytes(self.__name), 1024 * 512, status)
File "/home/wdjpng/.local/lib/python2.7/site-packages/tensorflow/python/framework/errors_impl.py", line 519, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.NotFoundError: data/mscoco_label_map.pbtxt; No such file or directory
OS: Ubuntu 18.04
Python: 2.7
Could you please help me ?
It would help immensly if you provided the file/function you called to produce the traceback. However, in absence of that and based on the below:
tensorflow.python.framework.errors_impl.NotFoundError: data/mscoco_label_map.pbtxt; No such file or directory
The *_label_map.pbtxt path is specified in two lines of the model.config file (exact line numbers depends on the model you chose). It appears one or both the training/test file paths are incorrect.

cannot import name _parse_proxy (urllib2)

I was trying to use Scrapy with Python 2 and I got this error,
File "/Library/Python/2.7/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
result = g.send(result)
File "/Library/Python/2.7/site-packages/scrapy/crawler.py", line 95, in crawl
six.reraise(*exc_info)
File "/Library/Python/2.7/site-packages/scrapy/crawler.py", line 77, in crawl
self.engine = self._create_engine()
File "/Library/Python/2.7/site-packages/scrapy/crawler.py", line 102, in _create_engine
return ExecutionEngine(self, lambda _: self.stop())
File "/Library/Python/2.7/site-packages/scrapy/core/engine.py", line 69, in __init__
self.downloader = downloader_cls(crawler)
File "/Library/Python/2.7/site-packages/scrapy/core/downloader/__init__.py", line 88, in __init__
self.middleware = DownloaderMiddlewareManager.from_crawler(crawler)
File "/Library/Python/2.7/site-packages/scrapy/middleware.py", line 58, in from_crawler
return cls.from_settings(crawler.settings, crawler)
File "/Library/Python/2.7/site-packages/scrapy/middleware.py", line 34, in from_settings
mwcls = load_object(clspath)
File "/Library/Python/2.7/site-packages/scrapy/utils/misc.py", line 44, in load_object
mod = import_module(module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/scrapy/downloadermiddlewares/httpproxy.py", line 4, in <module>
from urllib2 import _parse_proxy
ImportError: cannot import name _parse_proxy
I have urllib2 installed
Name: urllib2
Version: 1498656401.94
Summary: Checking out the typosquatting state of PyPi
Home-page: https://github.com/benjaoming
Author: Benjamin Bach
Author-email: benjamin#overtag.dk
License: MIT
Location: /usr/local/lib/python2.7/site-packages
Requires:
I have tried uninstalling and reinstalling urllib2 and requests.
You probably have two different Python environments. Scrapy seems to live in /Library/Python/2.7/site-packages/scrapy while your urllib2 lives in /usr/local/lib/python2.7/site-packages.