I'm trying to make a 3d model using pygame, OpenGL and numpy, while running this script I run into the following Errors
Traceback (most recent call last:
File "C:\Users\[I]Username[/I]\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGL\latebind.py", line 41, in __call__
return self._finalCall(*args,**named)
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\[I]Username[/I]\Desktop\Python-graphic-game\3d-game\model.py", line 60, in <module>
main()
File "C:\Users\[I]Username[/I]\Desktop\Python-graphic-game\3d-game\model.py", line 56, in main
m.draw()
File "C:\Users\[I]Username[/I]\Desktop\Python-graphic-game\3d-game\model.py", line 35, in draw
glVertex3fv(self.vertices[vertex])
File "C:\Users\[I]Username[/I]\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGL\latebind.py", line 45, in __call__
return self._finalCall(*args,**named)
File "C:\Users\[I]Username[/I]\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGL\wrapper.py", line 675, in wrapper call
pyArgs = tuple(calculate_pyArgs(args))
File "C:\Users\[I]Username[/I]\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGL\wrapper.py", line 436, in calculate_pyArgs
yield converter(args[index], self, args)
File "C:\Users\[I]Username[/I]\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGL\arrays\arrayhelpers.py", line 122, in asArraySize
incoming,
ValueError: ('Expected 12 byte array, got 8 byte array', (0,1), <function asArrayTypeSize.<locals>.asArraySize at 0x09212588>)
Here is the code in question:
import sys, pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import numpy
class threeDModel:
nodes = [
[0,0,0],
[1.1,1.1,0],
[0,-1.1,0],
[0,-1.1,-1.1]
]
vertices = [
(0,1),
(0,2),
(0,3),
(1,2),
(1,3),
(2,3)
]
surfaces = (
(0,1,2),
(0,2,3)
)
def __init__(self):
self.nodes = threeDModel.nodes
self.vertices = threeDModel.vertices
self.surfaces = threeDModel.surfaces
def draw(self):
glBegin(GL_TRIANGLES)
for surface in self.surfaces:
for vertex in surface:
glColor3f(1,0,0)
glVertex3fv(vertices[vertex])
glEnd()
So can anybody help me?
This is my first time using OpenGL, so please be nice to me.
I am also using the tutorials by Tech with Tim, that's why I'm using the from module import *, even though I know I'm not supposed to use it.
Thanks in advance!
vertices is an attribute of the class threeDModel. So it has to be self.vertices.
But content of the attribute .vertices is a list of pairs (tuples).
vertices = [(0,1), (0,2), (0,3), (1,2), (1,3), (2,3)]
Probably you want to draw .nodes rather than .vertices:
class threeDModel:
# [...]
def draw(self):
glColor3f(1,0,0)
glBegin(GL_TRIANGLES)
for surface in self.surfaces:
for i in surface:
glVertex3fv(self.nodes[i])
glEnd()
Or you want to draw the edges (wire frame):
class threeDModel:
# [...]
def drawEdges(self):
glColor3f(1,1,0)
glBegin(GL_LINES)
for edges in self.vertices:
for i in edges:
glVertex3fv(self.nodes[i])
glEnd()
Related
I'm trying to evaluate a theano TensorValue expression:
import pymc3
import numpy as np
with pymc3.Model():
growth = pymc3.Normal('growth_%s' % 'some_name', 0, 10)
x = np.arange(4)
(x * growth).eval()
but get the error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/gof/graph.py", line 522, in eval
self._fn_cache[inputs] = theano.function(inputs, self)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/function.py", line 317, in function
output_keys=output_keys)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/pfunc.py", line 486, in pfunc
output_keys=output_keys)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/function_module.py", line 1839, in orig_function
name=name)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/function_module.py", line 1487, in __init__
accept_inplace)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/compile/function_module.py", line 181, in std_fgraph
update_mapping=update_mapping)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/gof/fg.py", line 175, in __init__
self.__import_r__(output, reason="init")
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/gof/fg.py", line 346, in __import_r__
self.__import__(variable.owner, reason=reason)
File "/home/danna/.virtualenvs/lib/python2.7/site-packages/theano/gof/fg.py", line 391, in __import__
raise MissingInputError(error_msg, variable=r)
theano.gof.fg.MissingInputError: Input 0 of the graph (indices start from 0), used to compute InplaceDimShuffle{x}(growth_some_name), was not provided and not given a value. Use the Theano flag exception_verbosity='high', for more information on this error.
I tried
Can someone please help me see what the theano variables actually output?
Thank you!
I'm using Python 2.7 and theano 1.0.3
While PyMC3 distributions are TensorVariable objects, they don't technical have any values to be evaluated outside of sampling. If you want values, you have to at least run sampling on the model:
with pymc3.Model():
growth = pymc3.Normal('growth', 0, 10)
trace = pymc3.sample(10)
x = np.arange(4)
x[:, np.newaxis]*trace['growth']
If you want to view node values during sampling, you'd need to use theano.tensor.printing.Print objects. For more info, see the PyMC3 debugging tips.
I am getting this error again and again while running my code.
Exception in thread Thread-213:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/dist-packages/pyfirmata/util.py", line 47, in run
self.board.iterate()
File "/usr/local/lib/python2.7/dist-packages/pyfirmata/pyfirmata.py", line 264, in iterate
byte = self.sp.read()
File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 483, in read
ready, _, _ = select.select([self.fd, self.pipe_abort_read_r], [], [], timeout.time_left())
ValueError: filedescriptor out of range in select()
All i am trying to do is calculate power consumption in my project.
I am sharing part of my code as well. my counter was still counting but after
getting this error, my counter stopped.
Can i use it without iterator, or do i need to stop the iterator. This application should run continuously 24x7.
so there should be no chance of code error. Please help me get over it. please help me if i am wrong, i learned python from internet only.
Traceback (most recent call last):
File "/media/pi/abc/MYPythonGUI.py", line 127, in <lambda>
File "/media/pi/abc/MYPythonGUI.py", line 119, in updateLabel
IOError: [Errno 24] Too many open files: 'Memory'
here's my code
import sys
import logging
from PyQt4 import QtGui, QtCore
import datetime
import time
from pyfirmata import Arduino, util
logging.basicConfig(filename='test.ods',level=logging.INFO, format='%(asctime)s:%(message)s')
PowerAccumulated = [0,0]
Mem=open('Memory','r')
PowerAccumulated[0] = float(Mem.read())
Mem.close()
class Window(QtGui.QMainWindow):
def _Power_Calculations(Self):
Date_labe2 = QtGui.QLabel(((datetime.datetime.today()).strftime("%d/%m/%y %H:%M")), Self)
newfont = QtGui.QFont("Times", 20, QtGui.QFont.Bold)
Date_labe2.setFont(newfont)
Date_labe2.setStyleSheet("color: blue")
Date_labe2.resize(250,120)
Date_labe2.move(610,400)
power_label2 = QtGui.QLabel(str(PowerAccumulated[1]), Self)
newfont = QtGui.QFont("Times", 20, QtGui.QFont.Bold)
power_label2.setFont(newfont)
power_label2.setStyleSheet("color: blue")
power_label2.resize(270,120)
power_label2.move(440,75)
QtCore.QTimer.singleShot(500, lambda: Self.updateLabel(power_label2,Date_labe2))
power_label3 = QtGui.QLabel("KW", Self)
newfont = QtGui.QFont("Times", 20, QtGui.QFont.Bold)
power_label3.setFont(newfont)
power_label3.setStyleSheet("color: blue")
power_label3.resize(270,120)
power_label3.move(600,75)
Self.show()
def updateLabel(Self, power_label2,Date_labe2):
try:
board=Arduino('/dev/ttyACM0')
iterator=util.Iterator(board)
iterator.start()
V1=board.get_pin('a:0:i')
time.sleep(0.1)
Voltage=100*(V1.read())
I1=board.get_pin('a:1:i')
time.sleep(0.1)
Current=20*float(I1.read())
if Current < 0.0976 :
Current = 0.0976
except:
Voltage=0.0
Current=0.0
Power=round( ((Voltage * Current * 0.98 * 1.732)/1000),3)
PowerAccumulated[1] =round((Power + PowerAccumulated[0]),3)
Self.Voltage = Voltage
Self.Current = Current
Self.Power = Power
Self.PowerAccumulated=PowerAccumulated[1]
logging.info('Valotage:{} - Current:{} - Power:{} - Power Accumulation:{}'.format(Self.Voltage, Self.Current, Self.Power, Self.PowerAccumulated))
Mem1=open('Memory','w')
Mem1.write(str(PowerAccumulated[1]))
Mem1.close()
PowerAccumulated[0] = PowerAccumulated[1]
power_label2.setText(str(PowerAccumulated[1]))
Date_labe2.setText((datetime.datetime.today()).strftime("%d/%m/%y %H:%M"))
QtCore.QTimer.singleShot(500, lambda: Self.updateLabel(power_label2,Date_labe2))
def run():
app = QtGui.QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())
run()
I'm having problems reading an OpenStreetMap buildings (IMPOSM GEOJSON) file into a geopandas data frame object (Python 2.7). This is on MAC OS X 10.11.3. Here are the messages I'm getting:
>>> import geopandas as gpd
>>> df=gpd.read_file('san-francisco-bay_california_buildings.geojson')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ewang/anaconda/lib/python2.7/site-packages/geopandas/io/file.py", line 28, in read_file
gdf = GeoDataFrame.from_features(f, crs=crs)
File "/Users/ewang/anaconda/lib/python2.7/site-packages/geopandas/geodataframe.py", line 193, in from_features
d = {'geometry': shape(f['geometry']) if f['geometry'] else None}
File "/Users/ewang/anaconda/lib/python2.7/site-packages/shapely/geometry/geo.py", line 34, in shape
return Polygon(ob["coordinates"][0], ob["coordinates"][1:])
File "/Users/ewang/anaconda/lib/python2.7/site-packages/shapely/geometry/polygon.py", line 229, in __init__
self._geom, self._ndim = geos_polygon_from_py(shell, holes)
File "/Users/ewang/anaconda/lib/python2.7/site-packages/shapely/geometry/polygon.py", line 508, in geos_polygon_from_py
geos_shell, ndim = geos_linearring_from_py(shell)
File "/Users/ewang/anaconda/lib/python2.7/site-packages/shapely/geometry/polygon.py", line 450, in geos_linearring_from_py
n = len(ob[0])
IndexError: list index out of range
The odd thing is that I can load OSM roads data IMPOSM GEOJSON files with geopandas. Am I missing something obvious here? Thanks very much.
EDIT - link to the data below:
OSM data from mapzen
I am trying to render an SVG map using Kartograph.py. It throws me the TypeError. Here is the python code:
import kartograph
from kartograph import Kartograph
import sys
from kartograph.options import read_map_config
css = open("stylesheet.css").read()
K = Kartograph()
cfg = read_map_config(open("config.json"))
K.generate(cfg, outfile='dd.svg', format='svg', stylesheet=css)
Here is the error it throws
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
K.generate(cfg, outfile='dd.svg', format='svg', stylesheet=css)
File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\kartograph.py", line 46, in generate
_map = Map(opts, self.layerCache, format=format)
File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\map.py", line 61, in __init__
layer.get_features()
File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\maplayer.py", line 81, in get_features
charset=layer.options['charset']
File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\layersource\shplayer.py", line 121, in get_features
geom = shape2geometry(shp, ignore_holes=ignore_holes, min_area=min_area, bbox=bbox, proj=self.proj)
File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\layersource\shplayer.py", line 153, in shape2geometry
geom = shape2polygon(shp, ignore_holes=ignore_holes, min_area=min_area, proj=proj)
File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\layersource\shplayer.py", line 217, in shape2polygon
poly = MultiPolygon(polygons)
File "C:\Python27\lib\site-packages\shapely\geometry\multipolygon.py", line 74, in __init__
self._geom, self._ndim = geos_multipolygon_from_polygons(polygons)
File "C:\Python27\lib\site-packages\shapely\geometry\multipolygon.py", line 30, in geos_multipolygon_from_polygons
N = len(ob[0][0][0])
TypeError: 'Polygon' object does not support indexing
I had a look at shapely and it seems like you are using an outdated version.
Update your current install:
pip install -U shapely
I created my very first Python program for work and I have it running in PyCharm.
The program has a GUI, it basically pops up a window, has a directory tree so the user can select a jpg file, it then binarizes the image then lets the user select the binary threshold with a slider. It also displays two other images that I perform image transformations on.
SO, my problem is that I cannot build it to an .exe at all. I've tried Py2Exe, PyInstaller, and CX_freeze. I've tried building my own .spec files in Pyinstaller, but all have no success.
I'm running 2.7.6. I initially had 64 bit Python installed so I uninstalled everything Python related and installed 32 bit Python.
Initially when I was using pyinstaller I would just get ImportError: %1 is not a valid Win32 application, however since building a .spec file now I get actual errors. I've tried using hooks (hiddenimports=["wx", "scipy", "skimage", "matplotlib", "numpy"]) to make sure all the right files are included, but still no luck.
The main error that I'm receiving right now is: File "_ufuncs.pyx", line 1, in init scipy.special._ufuncs(scipy\special_ufuncs.c:19992) ImportError: No module named _ufuncs_cxx
I also created a smaller code below that just pops up a Wx window with a plot inside, but I receive the same error there.
Like I mentioned, I'm new to Python, and I've done a lot of reading and haven't been able to figure this out. I've spent probably 10-20 hours just trying to get it to compile correctly.
Below isn't my actual program, but a small snippet using wxPython and MatPlotLib that produces the same error.
This is the sample code:
import wx
from PIL import Image
import matplotlib
matplotlib.use("WXAgg")
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas#,NavigationToolbar2WxAgg as NavigationToolbar
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy
from scipy import interpolate
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from skimage.filter.rank import entropy
from skimage.morphology import disk
from skimage.util import img_as_ubyte
from skimage import color
from skimage import io
import skimage
from numpy import arange, sin, pi
class CanvasPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.canvas = FigCanvas(self, -1, self.figure)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizer)
self.Fit()
def draw(self):
t = arange(0.0, 3.0, 0.01)
s = sin(2 * pi * t)
self.axes.plot(t, s)
if __name__ == "__main__":
app = wx.PySimpleApp()
fr = wx.Frame(None, title='test')
panel = CanvasPanel(fr)
panel.draw()
fr.Show()
This is the error I receive:
Traceback (most recent call last):
File "<string>", line 11, in <module>
File "c:\python27_32bit\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstalle\loader\pyi_importers.py", line 270, in
load_module
exec(bytecode, module.__dict__)
File "C:\users\iolvera\PycharmProjects\EL and Grayscale Analyzer\build\compilertest\out00-PYZ.pyz\scipy.interpolate",line 156, in <module>
File "c:\python27_32bit\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\users\iolvera\PycharmProjects\EL and Grayscale Analyzer\build\compilertest\out00-PYZ.pyz\scipy.interpolate.interpolate", line 12, in <module>
File "c:\python27_32bit\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\users\iolvera\PycharmProjects\EL and Grayscale Analyzer\build\compilertest\out00-PYZ.pyz\scipy.special", line 531, in <module>
File "c:\python27_32bit\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 409, in load_module
module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
File "_ufuncs.pyx", line 1, in init scipy.special._ufuncs (scipy\special\_ufuncs.c:19992)
ImportError: No module named _ufuncs_cxx
My Python Path is correct C:\Python27_32bit\ and I also have \lib\site-packages\ and \DLL included correctly.
Like I mentioned, both programs run correctly in PyCharm.
Any help would be greatly appreciated.
Thank you!
I had this problem, and I fixed it in py2exe by specifically telling it to include the offending module. So, in setup.py:
includes = ['scipy.special._ufuncs_cxx']
setup(...,
options={"py2exe":{"includes":includes}}
)
I had this happen with a couple of other SciPy modules, too, so my includes list has about six things in it.