Creating executable with Py2exe and matplotlib errors - matplotlib

I have been searching this forum and many others and cannot seem to get a good method of creating an executable. I have tried several different methods (py2exe, pyinstaller and cx_freeze) and all seem to give me some kind of error.
When i tried pyinstaller, I received the error that "no _imaging C module is installed". Everything I search says that it has to do with PIL, but my code is not using PIL.
When I tried py2exe, I keep receiving the following error:
File "Scout_Tool.py", line 18, in <module>
File "matplotlib\pyplot.pyc", line 95, in <module>
File "matplotlib\backends\__init__.pyc", line 25, in pylab_setup
ImportError: No module named backend_qt4agg
I am at a loss of what to do. My code contains the following imports:
import os
import csv
import wx
import time
import math
from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.pyplot import figure,show
from mpl_toolkits.basemap import Basemap
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from numpy.random import rand
from datetime import datetime
import wx.calendar as cal
import numpy as npy
from pylab import *
import numpy as np
import matplotlib
import adodbapi
import sqlparse
import pylab
import annote_new
import cPickle as pickle
Does anyone have any suggestions on how to do a build of the executable using py2exe? What i have tried...
from distutils.core import setup
import py2exe
import matplotlib
setup(
windows=[{'script': r'Scout_Tool.py'}],
data_files=matplotlib.get_py2exe_datafiles(),
options={
r'py2exe': {
r'includes': r'ElementConfig',
r'includes': r'ColorConv',
r'includes': r'Tkinter',
r'includes': r're',
r'includes': r'math',
r'includes': r'sys',
r'includes': r'matplotlib',
r'includes': r'mpl_toolkits',
r'includes': r'matplotlib.backends.backend_wx',
r'dll_excludes': [r'MSVCP90.dll'],
}
},
)
Thanks for any help!

I am not fully sure this will fix your problem, but you should start by correcting that faulty options dictionary entry. In python, when you define a dictionary with the same key over and over, you are only going to get the last value. A key can only exist once:
options={
r'py2exe': {
r'includes': r'ElementConfig',
...
r'includes': r'mpl_toolkits',
r'includes': r'matplotlib.backends.backend_wx',
...
}
}
print options
#{'py2exe': {'includes': 'matplotlib.backends.backend_wx'}}
I suspect the result of this usage is py2exe not really finding any of your intended includes. includes should be a list:
options={
'py2exe':{
'includes': [
'ElementConfig',
'ColorConv',
'Tkinter',
're',
'math',
'sys',
'matplotlib',
'mpl_toolkits',
'matplotlib.backends.backend_wx'
],
'dll_excludes': ['MSVCP90.dll'],
}
},
If after this, it still complains about the backend missing, you can add another explicit entry:
'includes': [
...
'matplotlib.backends.backend_qt4agg'
],

Related

'CRF' object has no attribute 'keep_tempfiles'

I have imported `
from itertools import chain
import nltk
import sklearn
import scipy.stats
import sklearn_crfsuite
from sklearn_crfsuite import scorers,CRF
from sklearn_crfsuite.metrics import flat_classification_report
from sklearn_crfsuite import metrics`
Is there any way we can fix this on google colab?
Try this:
!pip install scikit-learn==0.22.2 --user
source: https://github.com/TeamHG-Memex/sklearn-crfsuite/issues/60

ModuleNotFoundError for .vision and .utils , download_url, VisionDataset

I am trying to create a custom dataset in google colab, but imports give me errors.
from PIL import Image
from six.moves import zip
import os
from .vision import VisionDataset ------------------------(1)
from .utils import download_url, check_integrity --------------(2)
class datasetName(VisionDataset):
...
(1) error :
ModuleNotFoundError: No module named 'main.vision'; 'main' is
not a package
(2) error :
ModuleNotFoundError: No module named 'main.utils'; 'main' is
not a package
I have tried to add from torchvision import utils but it does not solve the error.
If I change to from torch.utils import download_url, check_integrity
then the error becomes:
ImportError: cannot import name 'download_url'
Please try the following import lines.
from torchvision.datasets.vision import VisionDataset
from torchvision.datasets.utils import download_url, check_integrity
Hope it helps!

Zipline - How to pass bundle DataPortal to TradeAlgorithm.run()?

I am trying to run a Zipline back test by calling the run() method of zipline.algorithm.TradeAlgorithm:
algo = TradingAlgorithm(initialize= CandlestickStrategy.initialize,
handle_data= CandlestickStrategy.handle_data,
analyze= CandlestickStrategy.analyze,
data=None,
bundle='quandl')
results = algo.run()
But I'm not sure what or how to pass the data parameter. I have already ingested the data bundle which is called 'quandl'. According to the docs, that parameter should receive a DataPortal instance, but I don't know how to create one of those based on the data I have ingested. What is the best way of doing this/is this necessary?
Essentially my goal is to create a top level 'dashboard' style class which can run multiple back tests using different strategies which exist in separate modules.
Full code (dashboard.py):
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from mpl_finance import candlestick_ohlc
from datetime import datetime, date, tzinfo, timedelta
from dateutil import parser
import pytz
import numpy as np
import talib
import warnings
import logbook
from logbook import Logger
log = Logger('Algorithm')
from zipline.algorithm import TradingAlgorithm
from zipline.api import order_target_percent, order_target, cancel_order, get_open_orders, get_order, get_datetime, record, symbol
from zipline.data import bundles
from zipline.finance import execution
from CandlestickStrategy import CandlestickStrategy
warnings.filterwarnings("ignore")
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
# Choosing a security and a time horizon
logbook.StderrHandler().push_application()
start = datetime(2014, 9, 1, 0, 0, 0, 0, pytz.utc)
end = datetime(2016, 1, 1, 0, 0, 0, 0, pytz.utc)
#dataPortal = data_portal.DataPortal(asset_finder, trading_calendar, first_trading_day, e
#bundle = bundles.load('quandl',None,start)
algo = TradingAlgorithm(initialize= CandlestickStrategy.initialize,
handle_data= CandlestickStrategy.handle_data,
analyze= CandlestickStrategy.analyze,
data=None,
bundle='quandl')
results = algo.run()
CandleStickStrategy.py:
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from mpl_finance import candlestick_ohlc
from zipline.api import order_target_percent, order_target, cancel_order, get_open_orders, get_order, get_datetime, record, symbol
from zipline.finance import execution
from datetime import datetime, date, tzinfo, timedelta
from dateutil import parser
import pytz
import numpy as np
import talib
import warnings
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
class CandlestickStrategy:
def initialize(context):
print "initializing algorythm..."
context.i = 0
context.asset = symbol('AAL')
def handle_data(context, data):
try:
trailing_window = data.history(context.asset, ['open','high','low','close'], 28, '1d')
except:
return
def analyze(context=None, results=None):
print "Analyze"
Hopefully someone can point me in the right direction.
Thanks
I faced the same issue. When running the trading algorithm manually this way the bundle argument is not evaluated. You need to create the data portal yourself. I manually registered the bundle and created a data_portal to run it:
bundles.register('yahoo-xetra',
csvdir_equities(get_calendar("XETRA"), ["daily"],
'/data/yahoo'),
calendar_name='XETRA')
bundle_data = bundles.load(
'yahoo-xetra',
)
first_trading_day = bundle_data.equity_daily_bar_reader.first_trading_day
data = DataPortal(
bundle_data.asset_finder,
trading_calendar=get_calendar("XETRA"),
first_trading_day=first_trading_day,
equity_minute_reader=bundle_data.equity_minute_bar_reader,
equity_daily_reader=bundle_data.equity_daily_bar_reader,
adjustment_reader=bundle_data.adjustment_reader,
)
Strategy = SimpleAlgorithm(trading_calendar=get_calendar("XETRA"), data_frequency='daily',
start=pd.Timestamp('2017-1-1 08:00:00+0200', tz='Europe/Berlin'),
end=pd.Timestamp('2018-12-27 08:00:00+0200', tz='Europe/Berlin'),
capital_base=10000000,
data_portal=data)

Can't import QSound from PyQt5.QtGui

I'm trying to use QSound for my application, but whenever I try to import it I get the error:
ImportError: cannot import name 'QSound'
Using python console with no success, as:
from PyQt5 import QtGui
from PyQt5.QtGui import QSound
I tried to import it from PyQt5.QtCore and PyQt5 Same error.
As stated by #S. Nick , the correct import was
from PyQt5.QtMultimedia import QSound

ImportError: No module named 'svmutil'

i get stuck right now, my code:
import sys
import os
import itertools
import random
from PIL import Image
from svmutil import *
DIMENSION = 200
ROOT_DIR = "../train/"
NEGATIVE = "negative"
POSITIVE = "positive"
CLASSES = [NEGATIVE, POSITIVE]
....
and it says :
ImportError: No module named 'svmutil'
now I use python 3.5
What should I do now?