Unimplemented OBJ format statement 's' on line 's 1' ERROR - python

hi i am going to import an OBJ 3d File using Pywavefront library and Display this 3d Model on another 3d scene finally. I studied about this library and 3d Models much.
import pywavefront
import pywavefront.visualization
from pywavefront import visualization
from pywavefront import material
from pywavefront import mesh
from pywavefront import parser
import pywavefront.texture as texture
my obj file named "low-poly-fox-by-pixelmannen" that i downloaded from Clara.io website along its MTL file and added to my pycharm Working Dir both of files.
my codes for import this obj file as:
fox = pywavefront.Wavefront('low-poly-fox-by-pixelmannen.obj', collect_faces=True)
I would like to display this obj file into pycharm, but after Run, program shows ONLY a EMPTY WHITE SCREEN and says this ERROR:
Unimplemented OBJ format statement 's' on line 's 1'
Important point is: when pycharm runs and white screen appeared pycharm Thinking still and pycharm CRASH.
I am CONFUSED from Yesterday and Searched Similar errors, but I didnt find Any Solution or Comment about My problem. Please tell me what means this error? and Guide me for solve problem and Display 3d OBJ file finally.

It means you have a problem with the file which contains smooth shading statements (read here for more https://en.wikipedia.org/wiki/Wavefront_.obj_file).
Pywavefront does not know what is it (it is not implemented in their parser as I see).
So you can comment this line (# s 1), so it will not be parsed.
About visualization, I think that your problem is not with this error. According to their main parser class, it should raise an error only if you add to loader strict=True parameter (it is False by default). So I think your model is loaded w\o smooth shading, but the problem with visualization does not correspond with that error (it just warns you - logged).
I can have an assumption that you do not install or import some module that provides vizualisation.
You asked this question about 2 months ago, if you find the solution, It would be nice to share it :)

Related

Python profiling, imports (and specially __init__) is what seems to take the most time

I have a script that seemed to run slow and that i profiled using cProfile (and visualisation tool KCacheGrind)
It seems that what is taking almost 90% of the runtime is the import sequence, and especially the running of the _ _ init _ _.py files...
Here a screenshot of the KCacheGrind output (sorry for attaching an image...)
I am not very familiar with how the import sequence works in python ,so maybe i got something confused... I also placed _ _ init _ _.py files in everyone of my custom made packages, not sure if that was what i should have done.
Anyway, if anyone has any hint, greatly appreciated!
EDIT: additional picture when function are sorted by self:
EDIT2:
here the code attached, for more clarity for the answerers:
from strategy.strategies.gradient_stop_and_target import make_one_trade
from datetime import timedelta, datetime
import pandas as pd
from data.db import get_df, mongo_read_only, save_one, mongo_read_write, save_many
from data.get import get_symbols
from strategy.trades import make_trade, make_mae, get_prices, get_signals, \
get_prices_subset
#from profilehooks import profile
mongo = mongo_read_only()
dollar_stop = 200
dollar_target = 400
period_change = 3
signal = get_df(mongo.signals.signals, strategy = {'$regex' : '^indicators_group'}).iloc[0]
symbol = get_symbols(mongo, description = signal['symbol'])[0]
prices = get_prices(
signal['datetime'],
signal['datetime'].replace(hour = 23, minute = 59),
symbol,
mongo)
make_one_trade(
signal,
prices,
symbol,
dollar_stop,
dollar_target,
period_change)
The function get_prices simply get data from a mongo db database, and make_one_trade does simple calculation with pandas. This never poses problem anywhere else in my project.
EDIT3:
Here the Kcache grind screen when i select 'detect cycle' option in View tab:
Could that actually mean that there are indeed circular imports in my self created packages that takes all that time to resolve?
No. You are conflating cumulative time with time spent in the top-level code of the __init__.py file itself. The top-level code calls other methods, and those together take a lot of time.
Look at the self column instead to find where all that time is being spent. Also see What is the difference between tottime and cumtime in a python script profiled with cProfile?, the incl. column is the cumulative time, self is the total time.
I'd just filter out all the <frozen importlib.*> entries; the Python project has already made sure those paths are optimised.
However, your second screenshot does show that in your profiling run, all that your Python code busied itself with was loading bytecode for modules to import (the marshal module provides the Python bytecode serialisation implementation). Either the Python program did nothing but import modules and no other work was done, or it is using some form of dynamic import that is loading a large number of modules or is otherwise ignoring the normal module caches and reloading the same module(s) repeatedly.
You can profile import times using Python 3.7's new -X importtime command-line switch, or you could use a dedicated import-profiler to find out why imports take such a long time.

No module named objects [bokeh]

Note from maintainers: This question is no longer relevant. The bokeh.objects module has not existed for years
I'm trying to run this script:
#Code will be significantly simplified in the 0.4 release
import time
from bokeh.objects import GlyphRenderer
renderer = [r for r in curplot().renderers if isinstance(r, GlyphRenderer)][0]
ds = renderer.data_source
while True:
df = pd.io.json.read_json(url+json_call)
ds.data["x"] = x+N*i
ds.data["y"] = df.rssi
ds._dirty = True
session().store_obj(ds)
time.sleep(1.5)
i+=1
from:
https://www.continuum.io/content/painless-streaming-plots-bokeh
but at this line:
from bokeh.objects import GlyphRenderer
I got:
No module named objects
The version I'm using is
0.11.1
On linux mint 17.1
Note from maintainers: This answer is no longer relevant. The bokeh.objects module has not existed for years
did you try installing bokeh before trying the examples? If not, just run:
pip install bokeh
and try your script again.
if it does not work, it's likely that the bokeh sources changed, so you might want to change the
from bokeh.objects import GlyphRenderer
into
from bokeh.models.renderers import GlyphRenderer
cf the source code
At the first line of your example it states:
#Code will be significantly simplified in the 0.4 release
which means that the example's code was already about to be deprecated at the time of the writing of the tutorial.
So instead of copy/pasting that code, you should try to understand how it works, and recreate it using the documentation and sources:
http://docs.bokeh.org/en/latest/docs/user_guide/quickstart.html#userguide-quickstart
https://github.com/bokeh/bokeh
have fun!
The objects module was deleted in commit 5b5d28304c5ea209e243af5943917fe494d9ef9c (v0.7.1) after being deprecated in 8bb4a2f1f43b39b869c508ef7aee69f7aabb46b8 (v0.7.0). The deprecation message reads: "use bokeh.models instead". I leave finding GlyphRenderer in the current codebase as an exercise for you.
conda update bokeh solved this for me.
Regarding streaming (since that is is the example the OP was interested in), the current and stable streaming API is demonstrated here:
https://github.com/bokeh/bokeh/tree/master/examples/app/ohlc
This simple interface has been the way to efficiently stream to data soruces since 0.11.1, and will continue to be going forward.
The basic idea is to construct a dict with all the columns of a data source, and just the new data that is to be appended:
# construct a source with x and y columns
source = ColumnDataSource(data=dict(x=[....], y=[....]))
# sends the few new data points to the client, does not re-send all the data
source.stream(dict(x=[10, 11], y=[20, 21]))
Typically you'd probably call stream from some kind of periodic callback. The OHLC app linked above is a complete example.

Maya - Using Python to render a sequence

I am making a test render script in Python and am having problems getting my render calls to output sequences, and not just one frame.
I am working in Maya 2015 on a Windows 7 machine.
I have tried using the ogsRender() (Hardware 2.0) and render() (Software Render) commands. And while both of them proclaim to be able to output sequences in the docs, I can't seem to get them to do so.
import maya.cmds as cmds
cmds.render()
cmds.ogsRender()
Being a test render script, it doesn't need to be pretty--just fast.
hwRender() (old Hardware Render) seems to work fine, outputting frames according to render settings. However, I get a lot of white artifacts from any intersections when using that render, making it hard to see if things are correct.
Does anyone know how to get render() or ogsRender() to output sequences?
Or maybe remove the white artifacts hwRender() produces?
Thanks for your time!
Just incase this is what you're after, here's a rough approach you could use where you jog the frame and make your own batch-ish render system.
The only reason I've used renderfn rather than hardcoding maya.cmds.render is just incase you wanted to hook into something else (like, I dunno, dropping out some kind of scenefile that you'd feed into a renderfarm or suchlike)
import maya.cmds as mc
def render_seq(startframe = 1, endframe = 10, renderfn = mc.render, renderfn_args = None):
'''render out a sequence of frames as per global settings
defaults to using maya.cmds.render for frames 1-10'''
# save state
now = mc.currentTime(q=True)
for x in xrange(startframe, endframe):
mc.currentTime(x)
renderfn(renderfn_args)
# restore state
mc.currentTime(now)

NameError: global name 'imshow' is not defined but Matplotlib is imported

I'm currently writing a python script which plots a numpy matrix containing some data (which I'm not having any difficulty computing). For complicated reasons having to do with how I'm creating that data, I have to go through terminal. I've done problems like this a million times in Spyder using imshow(). So, I thought I'd try to do the same in terminal. Here's my code:
from numpy import *
from matplotlib import *
def make_picture():
f = open("DATA2.txt")
arr = zeros((200, 200))
l = f.readlines()
for i in l:
j = i[:-1]
k = j.split(" ")
arr[int(k[0])][int(k[1])] = float(k[2])
f.close()
imshow(arr)
make_picture()
Suffice it to say, the array stuff works just fine. I've tested it, and it extracts the data perfectly well. So, I've got this 200 by 200 array of numbers floating around my RAM and I'd like to display it. When I run this code in Spyder, I get exactly what I expected. However, when I run this code in Terminal, I get an error message:
Traceback (most recent call last):
File "DATAmine.py", line 15, in <module>
make_picture()
File "DATAmine.py", line 13, in make_picture
imshow(arr)
NameError: global name 'imshow' is not defined
(My program's called DATAmine.py) What's the deal here? Is there something else I should be importing? I know I had to configure my Spyder paths, so I wonder if I don't have access to those paths or something. Any suggestions would be greatly appreciated. Thanks!
P.S. Perhaps I should mention I'm using Ubuntu. Don't know if that's relevant.
To make your life easier you can use
from pylab import *
This will import the full pylab package, which includes matplotlib and numpy.
Cheers

Python: Converting COM PyIUnknown to known data type

I am currently trying to make a python app do the same thing as a VB app.
The app retrieves an image from an external device over the COM API. I've used win32com and managed to use the Dispatch mechanism to talk with the COM API.
In the VB app, the image is stored like this
pictureData = objResult.Properties('ResultImage')
myImage = AxHost.GetPictureFromIPicture(pictureData)
In my Python app, however on the picture data member, I get PyIUnknown object type. How do I get the image data out of this 'unknown' object?
Let me add that for other 'basic' data like strings, I can see them fine over the Python app.
I found a method that works, maybe not perfect, but if someone Google's this question, I hope it helps.
from win32com.client import Dispatch
import pythoncom
imagedata = data.Properties.Item('ResultImage') #this is samas the VB line in the question , except I have to add 'Item' here
#win32com does not define IPicture type (http://timgolden.me.uk/pywin32-docs/com_objects.html)
ipicture = Dispatch(imagedata.QueryInterface(pythoncom.IID_IDispatch))
import win32ui
import win32gui
#creates a PyCBitMap object
imagebitmap = win32ui.CreateBitmapFromHandle(ipicture.Handle)
#we need a DC handle to save the bitmap file for some reason...
dc_handler = win32ui.CreateDCFromHandle(win32gui.GetDC(0))
#this overwrites any older file without asking
imagebitmap.SaveBitmapFile(dc_handler,'last_pic.bmp')
Questions I still have in my mind are:
are we only forced to interact with IPicture or any non-defined COM (by win32com) in a dynamic way? Is there an elegant way to extend the definitions of interfaces etc.?
I tried using QueryInterface(pythontypes.IID('{7BF80980-BF32-101A-8BBB-00AA00300CAB}'). I got this IID from http://msdn.microsoft.com/en-us/library/windows/desktop/ms680761(v=vs.85).aspx however I got an error within Python that this interface cannot be handled.
Not sure why I cannot use the methods defined for IPicture, but I could access the attributes?
I tried simply to use ipicture.get_Handle() or ipicture.SaveAsFile() but these didn't work.

Categories