I am getting an unexpected error. I realize that there are posts with similar errors but either could not understand the answer or could not relate it to my case (dictionary).
I am trying to calculate a similarity score for each line of an input file and at every iteration (i.e for each line of input file) store the top 20 values of the score in a dictionary.
Following is my code:
import sys
from cx_Freeze import setup, Executable
includefiles = ['Arcade Funk.mp3', 'game over.wav', 'FrogTown.wav','pixel ufo.png','introBackground.png','pixel playButton.png','pixel instructionButton.png','pixel playButtonHighlighted.png','pixel instructionButtonHighlighted.png','instructionPage.png','crashBackground.png','space background long.png','pixel earth.png','pixel asteroid.png', 'pixel icon.png','Montserrat-ExtraBold.otf','Montserrat-Bold.otf','arial.ttf']
includes = []
excludes = ['Tkinter']
packages = ['pygame']
build_exe_options = {'includes':[includes],'packages':[packages], 'excludes':[excludes], 'include_files':[includefiles]}
base = None
if sys.platform == 'win64':
base = 'Win64GUI'
elif sys.platform == 'win32':
base = 'Win32GUI'
setup( name = 'Earth Invaders',
version = '0.1',
author = 'redacted',
description = 'Slider Game: Space',
options = {'build_exe': [build_exe_options]},
executables = [Executable('EarthInvaders.py', base=base)]
)
This is the error
Traceback (most recent call last):
File "C:/Users/Vix_Ox/Desktop/Earth Invaders/setup.py", line 21, in <module>
executables = [Executable('EarthInvaders.py', base=base)]
File "C:\Users\----\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\cx_Freeze\dist.py", line 349, in setup
distutils.core.setup(**attrs)
File "C:\Users\----\AppData\Local\Programs\Python\Python36-32\lib\distutils\core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "C:\Users\----\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\dist.py", line 24, in __init__
distutils.dist.Distribution.__init__(self, attrs)
File "C:\Users\----\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 237, in __init__
for (opt, val) in cmd_options.items():
AttributeError: 'list' object has no attribute 'items'
It looks like you've been following the documentation fine.
I think the issue is some extra square braces on line 20: [build_exe_options] should be build_exe_options. That variable is expected to be a dictionary, but it's getting a list, thus the error.
setup( name = 'Earth Invaders',
version = '0.1',
author = 'redacted',
description = 'Slider Game: Space',
options = {'build_exe': build_exe_options},
executables = [Executable('EarthInvaders.py', base=base)]
)
You may also find that you have to apply this retroactively to an earlier line, as they are already encapsulated in lists when they are declared:
build_exe_options = {'includes':includes,'packages':packages, 'excludes':excludes, 'include_files':includefiles}
Related
I am using python version 3.7 , I used this external library named treectrl and it works perfectly fine when I run my .py file but when I converted into exe file using cx_freeze it is giving me error NomodulleFound named tkinter. I have tried other small programs which does not use this library and I converted them in to exe file they work perfectly fine. So the idea which I got is that there is problem with this library. So I can't figure out what part this. I provided all codes , all downnload links and also error which I am getting.
https://sourceforge.net/projects/tkintertreectrl/files/
https://sourceforge.net/projects/tktreectrl/files/
Here is my code which I am converting python to exe
######################################################################
import tkinter
from TkTreectrl import *
# define some data to insert into the list:
data = {
'Joe': 1000.00,
'Jill': 738.39,
'Jack': 625.11,
'Jane': 99.99
}
root = tkinter.Tk()
# create list with scrollbars
slistbox = ScrolledMultiListbox(root)
slistbox.pack(fill='both', expand=1)
listbox = slistbox.listbox
# create columns
listbox.configure(columns=('Paid', 'Customer', 'Debt'))
#### add checkbox support to the listbox ####
# checkbox icons:
checked = tkinter.PhotoImage(data=('R0lGODlhDQANABEAACwAAAAADQANAIEAAAB/f3/f3'
'9////8CJ4yPNgHtLxYYtNbIbJ146jZ0gzeCIuhQ53NJVNpmryZqsYDnemT3BQA7'))
unchecked = tkinter.PhotoImage(data=('R0lGODlhDQANABEAACwAAAAADQANAIEAAAB/f3'
'/f39////8CIYyPNgHtLxYYtNbIrMZTX+l9WThwZAmSppqGmADHcnRaBQA7'))
# create treectrl state, element and style for the checkboxes:
listbox.state_define('Checked')
imgCheck = listbox.element_create(
type='image', image=(checked, 'Checked', unchecked, ()))
icon_style = listbox.style_create()
listbox.style_elements(icon_style,
listbox.element('select'), imgCheck, listbox.element('text'))
listbox.style_layout(icon_style, imgCheck, padx=3, pady=2)
listbox.style(0, icon_style)
# define checkbox callback that will be bound to mouse-button-1 events:
def cmd(event):
# check which element was clicked
identify = listbox.identify(event.x, event.y)
# identify might be None or look like:
# ('item', '2', 'column', '0') or
# ('item', '3', 'column', '0', 'elem', 'pyelement3')
if identify:
try:
item, column, element = identify[1], identify[3], identify[5]
if element == imgCheck:
# toggle the "checked" state
listbox.itemstate_forcolumn(item, column, '~Checked')
# do something, dependent on the current state of the checkbox
new = listbox.itemstate_forcolumn(item, column)
if new and 'Checked' in new:
# the checkbox was newly checked
print('Checked item', item, 'in column', column)
# example: debts are paid, set "Debt" to 0.00
listbox.itemelement_configure(item, listbox.column(2),
listbox.element('text'), text='0.00')
else:
# example: no payment received, set debt to stored value
print('Unchecked item', item, 'in column', column)
customer = listbox.itemelement_cget(
item, listbox.column(1),
listbox.element('text'), 'text')
debt = data[customer]
listbox.itemelement_configure(item, listbox.column(2),
listbox.element('text'), text=debt)
except IndexError:
# we did not hit the checkbox, never mind
pass
# bind the callback to button 1 events
listbox.bind('<1>', cmd)
# insert data into the list to see if this works:
for customer in data:
listbox.insert('end', '', customer, data[customer])
root.mainloop()
Here is my setup.py file
import cx_Freeze
import sys
import os
base = None
if sys.platform == 'win32':
base = "Win32GUI"
os.environ['TCL_LIBRARY'] = r"C:\Users\osama shakeel\AppData\Local\Programs\Python\Python37-32\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = r"C:\Users\osama shakeel\AppData\Local\Programs\Python\Python37-32\tcl\tk8.6"
executables = [cx_Freeze.Executable("working.py", base=base, icon="icon.ico")]
cx_Freeze.setup(
name = "test",
options = {"build_exe": {"packages":["tkinter","os"], "include_files":["icon.ico",'tcl86t.dll','tk86t.dll']}},
version = "0.01",
description = "Tkinter Application",
executables = executables
)
here is my error
cx_Freeze: Python error in main script
Traceback (most recent call last):
File "C:\Users\osama
shakeel AppData\Local\Programs\Python Python37-32\lib \site
-packages\cx_Freeze\initscripts _startup_.py", line 40, in run
module.runo
File "C:\Users\osama
shakeel AppData\Local\Programs\Python Python37-32\lib\site
-packages\cx_Freeze\initscripts\Console.py", line 37, in run
exec(code, [name__ main__'})
File "working.py", line 5, in <module>
ModuleNotFoundError: No module named 'tkinter
ок
I have made a python file and I want to convert it to an MSI file. Here is my code:
from cx_Freeze import *
includefiles=[]
excludes=[]
packages=["tkinter", "openpyxl"]
base = None
if sys.platform == "win32":
base = "Win32GUI"
shortcut_table = []
company_name = 'Bills Programs'
product_name = 'BananaCell'
msi_data = {"Shortcut": shortcut_table}
bdist_msi_options = { 'upgrade_code': '{Banana-rama-30403344939493}',
'add_to_path': False, 'initial_target_dir': r'[ProgramFilesFolder]\%s\%s' %
(company_name, product_name), }
setup(
version = "0.1",
description = "Lightweight excel comparing program",
author = "Bill",
name = "BananaCell",
options = {'build_exe': {'include_files':includefiles}, "bdist_msi": bdist_msi_options,},
executables = [
Executable(
script="comparing.py",
base=base,
shortcutName="BananaCell",
shortcutDir="DesktopFolder",
icon='icon.ico',
)
]
)
But when I run the following code, the installation completes but I get the following error message
What am I doing wrong? I have full access ti the directory. Any help would be greatly appreciated.
I am converting to Python an application I had earlier written in C#. It's a GUI application to manage unknown words while learning a new language. When the application starts, I have to load the words from the XML file which has a pretty simple structure:
<Words>
<Word>
<Word>test</Word>
<Explanation>test</Explanation>
<Translation>test</Translation>
<Examples>test</Examples>
</Word>
</Words>
Nevertheless, I am getting:
/usr/bin/python3.5 /home/cali/PycharmProjects/Vocabulary/Vocabulary.py
Traceback (most recent call last): File
"/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 203, in
main() File "/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 198, in
main
gui = Vocabulary(root) File "/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 28, in
init
self.load_words() File "/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 168, in
load_words
w = Word(node('Word').text, node('Explanation').text, node('Translation').text, node('Example').text) TypeError:
'xml.etree.ElementTree.Element' object is not callable
This is the original LoadWords() method:
void LoadWords()
{
words.Clear();
listView1.Items.Clear();
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string vocabulary_path = path + "\\Vocabulary\\Words.xml";
if (!Directory.Exists(path + "\\Vocabulary"))
Directory.CreateDirectory(path + "\\Vocabulary");
if (!File.Exists(vocabulary_path))
{
XmlTextWriter xW = new XmlTextWriter(vocabulary_path, Encoding.UTF8);
xW.WriteStartElement("Words");
xW.WriteEndElement();
xW.Close();
}
XmlDocument xDoc = new XmlDocument();
xDoc.Load(vocabulary_path);
foreach (XmlNode xNode in xDoc.SelectNodes("Words/Word"))
{
Word w = new Word();
w.WordOrPhrase = xNode.SelectSingleNode("Word").InnerText;
w.Explanation = xNode.SelectSingleNode("Explanation").InnerText;
w.Translation = xNode.SelectSingleNode("Translation").InnerText;
w.Examples = xNode.SelectSingleNode("Examples").InnerText;
words.Add(w);
listView1.Items.Add(w.WordOrPhrase);
WordCount();
}
}
I don't know how to access each node's inner text.
Here is my load_words function:
def load_words(self):
self.listBox.delete(0, END)
self.words.clear()
path = os.path.expanduser('~/Desktop')
vocabulary = os.path.join(path, 'Vocabulary', 'Words.xml')
if not os.path.exists(vocabulary):
if not os.path.exists(os.path.dirname(vocabulary)):
os.mkdir(os.path.dirname(vocabulary))
doc = ET.Element('Words')
tree = ET.ElementTree(doc)
tree.write(vocabulary)
else:
tree = ET.ElementTree(file=vocabulary)
for node in tree.findall('Word'):
w = Word(node('Word').text, node('Explanation').text, node('Translation').text, node('Example').text)
self.words.append(w)
self.listBox.insert(w.wordorphrase)
TypeError: 'xml.etree.ElementTree.Element' object is not callable
As the error message mentioned, node is an Element, not a method which you can call/invoke like method_name(parameters) as you did in this part :
w = Word(node('Word').text, node('Explanation').text, node('Translation').text, node('Example').text)
Method that is closer to SelectSingleNode() in your C# would be Element.find(), for example, to get the first child element named Word from node and then extract the inner text :
inner_text = node.find('Word').text
And the implementation in your context code would be as follows :
w = Word(node.find('Word').text, node.find('Explanation').text, node.find('Translation').text, node.find('Example').text)
I have been trying to add different images to nodes in a phylogenetic tree using the ete2 software in Python, but have no success.
from ete2 import Tree, TreeStyle, NodeStyle, TextFace, faces, add_face_to_node, AttrFace
ts.show_leaf_name = True
ts.show_branch_support = True
nw = """
(((Dre:0.008339,Dme:0.300613)1.000000:0.596401,
(Cfa:0.640858,Hsa:0.753230)1.000000:0.182035)1.000000:0.106234,
((Dre:0.271621,Cfa:0.046042)1.000000:0.953250,
(Hsa:0.061813,Mms:0.110769)1.000000:0.204419)1.000000:0.973467);
"""
t = Tree(nw)
img_path = "/home/leonard/Desktop/img_faces/"
humanFace = faces.ImgFace(img_path+"human.png")
mouseFace = faces.ImgFace(img_path+"mouse.png")
def my_layout(node):
if name.startswith("Dre"):
faces.add_face_to_node(humanface, node, column=1)
t.show(my_layout)
ts = TreeStyle()
t.render("img_faces.png", w=600, tree_style = ts)
These are error messages that I have been getting:
File "abc1.py", line 34, in <module>
t.show(my_layout)
File "/usr/local/lib/python2.7/dist-packages/ete2-2.1rev544-py2.7.egg/ete2/coretype/tree.py", line 1283, in show
drawer.show_tree(self, layout=layout, tree_style=tree_style)
File "/usr/local/lib/python2.7/dist-packages/ete2-2.1rev544-py2.7.egg/ete2/treeview/drawer.py", line 84, in show_tree
tree_item, n2i, n2f = render(t, img)
File "/usr/local/lib/python2.7/dist-packages/ete2-2.1rev544-py2.7.egg/ete2/treeview/qt4_render.py", line 258, in render
set_style(n, layout_fn)
File "/usr/local/lib/python2.7/dist-packages/ete2-2.1rev544-py2.7.egg/ete2/treeview/qt4_render.py", line 746, in set_style
layout_func(n)
File "abc1.py", line 29, in my_layout
if name.startswith("Dre"):
NameError: global name 'name' is not defined
Any help is much appreciated!
This is the solution from Jaime Huerta Cepas in google group, and I quote:
"There is a general Python programming error in your script ("name" variable does not exist). I guess that what you meant is "node.name.startswith()" instead of "name.startswith()""
It worked.
According to the documentation (ete2) you need to create a faces ready to read the name attribute of nodes.
Try to add the following to your code:
#nameFace = faces.TextFace(open("text").readline().strip(), fsize=20, fgcolor="#009000")
nameFace = faces.AttrFace("name", fsize=20, fgcolor="#009000")
The question is based on the thread, since I observed that Storm allows me reuse my SQL-schemas.
How can you solve the following error message in Storm?
The code is based on Jason's answer and on Storm's manual.
import os, pg, sys, re, psycopg2, storm
from storm.locals import *
from storm import *
class Courses():
subject = Unicode()
database = create_database("postgres://naa:123#localhost:5432/tk")
store = Store(database)
course = Courses()
course.subject = 'abcd'
store.add(course)
It gives you
Traceback (most recent call last):
File "<stdin>", line 13, in <module>
File "/usr/lib/python2.6/dist-packages/storm/store.py", line 245, in add
obj_info = get_obj_info(obj)
File "/usr/lib/python2.6/dist-packages/storm/info.py", line 40, in get_obj_info
obj_info = ObjectInfo(obj)
File "/usr/lib/python2.6/dist-packages/storm/info.py", line 162, in __init__
self.cls_info = get_cls_info(type(obj))
File "/usr/lib/python2.6/dist-packages/storm/info.py", line 51, in get_cls_info
cls.__storm_class_info__ = ClassInfo(cls)
File "/usr/lib/python2.6/dist-packages/storm/info.py", line 69, in __init__
raise ClassInfoError("%s.__storm_table__ missing" % repr(cls))
storm.exceptions.ClassInfoError: <type 'instance'>.__storm_table__ missing
This suggests to me that some module is missing. There is no module instance in Storm.
I'll leave out the connection details because I'm not terribly familiar with Postgres.
from storm.locals import *
class Courses(object):
__storm_table__ = 'courses'
pkey = Int(primary=True)
course_nro = Unicode()
course = Courses()
course.course_nro = 'abcd'
store.add(course)
store.commit()
Of course, if you want to do the constructor and initialization on one line, you can use pysistence's expandos:
from storm.locals import *
from pysistence import Expando
class Courses(Expando):
__storm_table__ = 'courses'
pkey = Int(primary=True)
course_nro = Unicode()
course = Courses(course_nro='abcd')
store.add(course)
store.commit()