_tkinter.TclError: invalid command name "table" - python-2.7

I tried to use tktable package to create table and show my data.
However, I could not make it work.
import Tkinter
import tktable
root = Tkinter.Tk()
table = tktable.Table(root, rows=10, cols=4)
table.pack(side="top", fill="both", expand=True)
root.mainloop()
I got error like:
Traceback (most recent call last):
File "C:/Users/jgou/PycharmProjects/mmt-autobench/autobench/test/test.py",
line 520, in <module> table = Table(root, rows=10, cols=4)
File "C:\Users\jgou\PycharmProjects\mmtautobench\autobench\inst\tktable.py",
line 135, in __init__tkinter.Widget.__init__(self, master, 'table', kw)
File "C:\Users\jgou\AppData\Local\Continuum\Anaconda2\lib\libtk\Tkinter.py",
line 2096, in __init__(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: invalid command name "table"
I searched online and could you solve the issue, please suggest and help. It made me crazy. It should be very easy. Thank you very much.

Related

ERAlchemy cannot connect to database

I don't understand the syntax to call the render feature of ERAlchemy (https://pypi.org/project/ERAlchemy see "Usage for Python"). I am using Python 2.7, sqlite3, and PyCharm. I have ERAlchemy, GraphViz, and PyGraphViz installed.
I am trying the following, but it cannot connect to the database:
from eralchemy import render_er
render_er("sqlite:///C:\\Users\\myname\\Documents\\Work\\pythonsqlite.db", 'erd_from_sqlite.png')
And this is the error:
Traceback (most recent call last):
File "C:/Users/myname/Documents/Work/_sql_functions_rev0.py", line 81, in <module>
render_er("sqlite:///C:\\Users\\myname\\Documents\\Work\\pythonsqlite.db", 'erd_from_sqlite.png')
File "C:\Python27\ArcGISx6410.6\lib\site-packages\eralchemy\main.py", line 236, in render_er
intermediary_to_output(tables, relationships, output)
File "C:\Python27\ArcGISx6410.6\lib\site-packages\eralchemy\main.py", line 75, in intermediary_to_schema
graph.draw(path=output, prog='dot', format=extension)
File "C:\Python27\ArcGISx6410.6\lib\site-packages\pygraphviz\agraph.py", line 1474, in draw
data = self._run_prog(prog, args)
File "C:\Python27\ArcGISx6410.6\lib\site-packages\pygraphviz\agraph.py", line 1308, in _run_prog
runprog = r'"%s"' % self._get_prog(prog)
File "C:\Python27\ArcGISx6410.6\lib\site-packages\pygraphviz\agraph.py", line 1295, in _get_prog
raise ValueError("Program %s not found in path." % prog)
ValueError: Program dot not found in path.
Ah! Found the answer here
had to find the folder with "dot.exe" and add it to the environment variables -> system variables -> path

Google Vision Python 2.7 TypeError: construct_settings() got an unexpected keyword argument 'metrics_headers'

After installing the required packages using pip, downloading a Json key and setting the enviroment variable in the cmd window with: set GOOGLE_APPLICATION_CREDENTIALS = 'C:\Users\ xxx .json' and following the instructions to use the Google Vision API on https://googlecloudplatform.github.io/google-cloud-python/stable/vision-usage.html#authentication-and-configuration
I tried the following and got the following error without any idea how to solve the error, so all suggestions are much appreciated
>>> from google.cloud import vision
>>> client =vision.Client()
>>> print client
<google.cloud.vision.client.Client object at 0x08D414F0>
>>> image = client.image(filename='test2.jpg')
>>> print image
<google.cloud.vision.image.Image object at 0x0CBF68F0>
>>> text = image.detect_text()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\google\cloud\vision\image.py", line 289, in detect_text
annotations = self.detect(features)
File "C:\Python27\lib\site-packages\google\cloud\vision\image.py", line 143, in detect
return self._detect_annotation(images)
File "C:\Python27\lib\site-packages\google\cloud\vision\image.py", line 117, in _detect_annotation
return self.client._vision_api.annotate(images)
File "C:\Python27\lib\site-packages\google\cloud\vision\client.py", line 114, in _vision_api
self._vision_api_internal = _GAPICVisionAPI(self)
File "C:\Python27\lib\site-packages\google\cloud\vision\_gax.py", line 34, in __init__
lib_version=__version__)
File "C:\Python27\lib\site-packages\google\cloud\gapic\vision\v1\image_annotator_client.py", line 140, in __init__
metrics_headers=metrics_headers, )
TypeError: construct_settings() got an unexpected keyword argument 'metrics_headers'

How to resolve "_tkinter.TclError: unknown option"?

I am learning python tkinter but I have an error whenever I tried to compile it:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/
widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/home/jason/.spyder2/.temp.py", line 14, in <module>
menu.config(menu=menu)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1274,
inconfigure
return self._configure('configure', cnf, kw)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1265,
in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown option "-menu").
My code is:
from tkinter import *
def hello():
print "hello"
root = Tk()
menu = Menu(root)
menu.config(menu=menu)
menu.add_command(label ="new",command = hello)
root.mainloop()
You have an issue with your code a little bit. Instead of menu.config, use root.config, you will not get any such errors.
For more information and detailed tutorial, kindly visit Tkinter Menu Widget.

xlwings unicode error when called from excel using Workbook.caller()

I am trying to call python code from excel using xlwings. The name of the workbook is "wingsTest". If the first line in my called code is wb = Workbook("wingsTest") it runs fine but when wb = Workbook.caller() I get the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\rbn\Documents\PythonScripts\apnlookupXL.py", line 74, in main
wb = Workbook.caller()
File "F:\Anaconda3\lib\site-packages\xlwings\main.py", line 182, in caller
xl_workbook = xlplatform.get_xl_workbook_from_xl(fullname)
File "F:\Anaconda3\lib\site-packages\xlwings\_xlwindows.py", line 429, in get_xl_workbook_from_xl
if not is_file_open(unicode(fullname)):
NameError: name 'unicode' is not defined
Thnks for any help.
This should have been fixed with yesterday's 0.3.5 release, see release notes.
Upgrade like so: pip install --upgrade xlwings

IndexError: too many indices on Python

Using PyDev with an eclipse environment for Python 2.7 on OSX. Trying to count the element in the array and sum up the elements in the array. Getting an error on the index.
import numpy as np
import os
import sys
csv_file_object = fileName = os.path.join('train.csv')
print('Directory separator on your platform ({}): {}'.format(sys.platform, os.sep))
data=[]
for row in csv_file_object:
data.append(row)
data = np.array(data)
number_passengers = np.size(data[0::,0].astype(np.float))
number_survived = np.sum(data[0::,0].astype(np.float))
proportion_survivors = number_survived / number_passengers
Traceback (most recent call last):
File "/Users/scdavis6/Documents/Kaggle/Titanic1.py", line 14, in <module>
number_passengers = np.size(data[0::,0].astype(np.float))
IndexError: too many indices
Let me know if I can provide additional information.
Thank you.
Update:
I made the edits, but got another error about the module not being callable:
Traceback (most recent call last):
File "/Users/scdavis6/Documents/Kaggle/Titanic1.py", line 5, in <module>
csv_file_object = fileName = os.path('train.csv')
TypeError: 'module' object is not callable
Update:
I changed os.path('train.csv') to os.path.join('train.csv'), but got another error about not finding the .csv file.
Traceback (most recent call last):
File "/Users/scdavis6/Documents/Kaggle/Titanic1.py", line 9, in <module>
with open(fileName) as f:
IOError: [Errno 2] No such file or directory: 'train.csv'
Here's the absolute path for the .csv file and the python scripts.
import os
os.path.abspath("/Users/scdavis6/Desktop/train.csv")
'/Users/scdavis6/Desktop/train.csv'
import os
os.path.abspath("/Users/scdavis6/Documents/Kaggle/Titanic1.py")
'/Users/scdavis6/Documents/Kaggle/Titanic1.py'
Assuming that this is your actual code, the problem is that you never open the file. Your csv_file_object is still just the fileName, and thus your data is made up of the characters of that file name, resulting in a 1D numpy array.
Instead, you should open the file and create a csv.reader for it.
import csv
with open(fileName) as f:
reader = csv.reader(f)
data=[]
for row in reader:
data.append(row)
data = np.array(data)
Or shorter: data = np.array([row for row in csv.reader(f)])
Update: The new error you are getting is probably due to you accidentally changing
os.path.join('train.csv') to os.path('train.csv'), i.e., instead of calling the join function from the os.path module, you are (trying to) call the module itself.
Update: It seems your train.csv file is not in the same directory as your Python script, thus the script won't find the file if you just use the filename. You have to use the absolute path together with the filename:
fileName = os.path.join('/Users/scdavis6/Desktop', 'train.csv')
Or just fileName = '/Users/scdavis6/Desktop/train.csv'. Alternatively, move your train.csv file to the same directory as your Python script. This might indeed be the better and more robust option, unless you are using this file in multiple scripts in different directories.