during typing a code on the python shell for an optimization problem i got this error for unknown reasons GurobiError: Variable has not yet been added to the modeland this is the part of the code:
from gurobipy import *
>>> m=Model("scanning")
>>> from sympy import *
>>> v=zeros(3,1)
>>> ub=zeros(3,1)
>>> lb=zeros(3,1)
>>> x=m.addVar(lb=0,ub=3,vtype='I',name='x')
>>> m.addConstr(Array([[1,2,3],[2,1,0],[2,3,1]])*x>=0,"c0")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/midow/anaconda3/lib/python3.6/site-packages/sympy/tensor/array/ndim_array.py", line 346, in __mul__
other = sympify(other)
File "/Users/midow/anaconda3/lib/python3.6/site-packages/sympy/core/sympify.py", line 266, in sympify
if a in sympy_classes:
File "var.pxi", line 39, in gurobipy.Var.__hash__
gurobipy.GurobiError: Variable has not yet been added to the model
i don't know why am i getting this error despite that syntax is right i guess, i don't know if there's something missing.
i am using Python 3.6.8on macOS high sierra.
Related
So I am trying to run and learn all about the vishnubob/kinet api.
After I download it I try to run the example script (also after fixing a couple syntax errors) I get this error:
Traceback (most recent call last):
File "example.py", line 31, in <module>
pds = PowerSupply("192.168.1.121")
NameError: name 'PowerSupply' is not defined
I have no clue why this is happening, as the imports look good (to me at least).
If someone knows why or can point me to the right direction then I would be grateful.
The clue here is "fixing syntax errors". That code has been written for Python 2, and it uses a thing called implicit relative import which was removed in Python 3. Namely the line in kinet/__init__.py
from kinet import *
is trying to import from the top-level package in Python 3, when Python 2 defaulted to importing from a local module first (kinet/kinet.py). The fix is to change this to
from .kinet import *
However this leads down the rabbit hole, as kinet.py has more syntax errors, after which it just fails spectacularly with
Traceback (most recent call last):
File "example.py", line 31, in <module>
pds = PowerSupply("192.168.1.121")
File "./kinet/kinet.py", line 227, in __init__
self.header = Header()
File "./kinet/kinet.py", line 22, in __init__
self._struct = struct.Struct(self.struct_format)
File "./kinet/kinet.py", line 61, in __setattr__
if key not in self.Keys:
File "./kinet/kinet.py", line 56, in __getattr__
if key not in self.Keys:
File "./kinet/kinet.py", line 56, in __getattr__
if key not in self.Keys:
File "./kinet/kinet.py", line 56, in __getattr__
if key not in self.Keys:
[Previous line repeated 325 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object
It is a bad piece of code written using all the syntax that was deprecated already in Python 2.6. I'd look for a Python 3 rewrite instead of trying to fix that.
when importing ethjsonrpc It throws an error as below:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/ethjsonrpc/__init__.py", line 1, in <module>
from ethjsonrpc.client import (EthJsonRpc, ParityEthJsonRpc,
File "/usr/local/lib/python3.6/site-packages/ethjsonrpc/client.py", line 7, in <module>
from ethereum import utils
File "/usr/local/lib/python3.6/site-packages/ethereum/utils.py", line 103, in <module>
assert sha3('').encode('hex') == 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
AttributeError: 'bytes' object has no attribute 'encode'
This is an issue with ethjsonrpc as can be seen on the github issue page. The proposed fix is to just comment the line 103 in /usr/local/lib/python3.6/site-packages/ethereum/utils.py
Might be a good idea to switch to using this module with python2 instead in case more errors appear that are caused by version differences.
I'm using MacOs with the PyCharm environment, and my project is set to use Python 2.7.10. Now, I have on the first line of my module the line:
import numpy as np
When I try to run my code, I get the following error:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /{path to file}/numpy_exercise.py
Traceback (most recent call last):
File "/{path to file}/numpy_exercise.py", line 1, in module>
import numpy as np
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/__init__.py", line 169, in module>
from . import polynomial
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/polynomial/__init__.py", line 20, in module>
from .polynomial import Polynomial
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/polynomial/polynomial.py", line 68, in module>
from .polytemplate import polytemplate
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/polynomial/polytemplate.py", line 17, in module>
polytemplate = string.Template(''' AttributeError: 'module' object has no attribute 'Template'
(note that "module>" was actually in brackets from both sides but because it gets omitted that way I daleted the first bracket so you can see it)
Though in Python 3 it does not happens to me. I looked on the web but couldn't find anything. I have no clue of why this is happening. I'd be glad to get some of your help!
Thank you guys!
I'm trying to automate tasks for teamcenter using pywinauto python module.But I was not able to work properly with TreeViews. When ever I'm trying to use GetItem(),SubElements(),Item() and many other function under _treeview_element giving error.Please look into below errors.
I'm using python 2.7 and i also have pywin32 module installed
for i in range(tr.ItemCount()):
print tr.GetItem(i)
Traceback (most recent call last):
File "<pyshell#61>", line 2, in <module>
print tr.GetItem(i) File "C:\Users\patibj\Desktop\pywinauto-
master\pywinauto\controls\common_controls.py", line 1010, in GetItem
if isinstance(path[0], int):
TypeError: 'int' object has no attribute '__getitem__'
This is when i'm trying to use GetChild()
a[0] is <pywinauto.controls.common_controls._treeview_element object at 0x02EC11B0> a[0].GetChild((1))
Traceback (most recent call last):
File "<pyshell#49>", line 1, in <module>
a[0].GetChild((1))
File "C:\Users\patibj\Desktop\pywinauto- master\pywinauto\controls\common_controls.py", line 840, in GetChild
return self.Children()[index]
File "C:\Users\patibj\Desktop\pywinauto-master\pywinauto\controls\common_controls.py", line 739, in Children
if self.Item().cChildren not in (0, 1):
File "C:\Users\patibj\Desktop\pywinauto-master\pywinauto\controls\common_controls.py", line 539, in Item
return self._readitem()[0]
File "C:\Users\patibj\Desktop\pywinauto-master\pywinauto\controls\common_controls.py", line 904, in _readitem
raise ctypes.WinError() WindowsError: [Error 0] The operation completed successfully.
Please help me out .Thanks in advance.
TreeViewWrapper.GetItem() method gets path argument which should be the string starting with back-slash \\ symbol. Example:
app.Dialog.TreeView.GetItem('\\1st_level_item_name\\2ndlevelitem').Click()
For access by index use a list of integers:
app.Dialog.TreeView.GetItem([1, 0])
GetChild() works with explorer.exe TreeView:
>>> tree.GetItem([1]).GetChild(2).Text()
u'Computer'
I'm trying to connect to wiimote via Python on mac osx 10.7.2.
For that I'm trying to use lightblue. When running: import lightblue Python gives me this error.
>>> import lightblue
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lightblue/__init__.py", line 160, in <module>
from _lightblue import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lightblue/_lightblue.py", line 27, in <module>
import _IOBluetooth
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lightblue/_IOBluetooth.py", line 47, in <module>
globals=globals())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/objc/_bridgesupport.py", line 142, in initFrameworkWrapper
_parseBridgeSupport(data, globals, frameworkName)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/objc/_bridgesupport.py", line 42, in _parseBridgeSupport
objc.parseBridgeSupport(data, globals, frameworkName, *args, **kwds)
ValueError: cftype for 'IOBluetoothDeviceInquiryRef' must include gettypeid_func, tollfree or both
I found one with a similar problem here: http://python.6.n6.nabble.com/Python-bridgesupport-issue-on-Lion-td2161049.html#a32196961 but the answer doesn't help me much, since it seems to me that it is already using lightblue's files. Any suggestions?
Seems like a bug with Apple's gen_bridge_metadata script. You can make the error go away by editing the generated file by hand.
Open up /System/Library/Frameworks/IOBluetooth.framework/Versions/Current/Resources/BridgeSupport/IOBluetooth.bridgesupport and delete the lines that start with <cftype.