So I'm using wand for a project and it's been working fine, except whenever I want to use a function that has been 'OpenCL-accelerated' (list of functions here), it stops working, no error or anything, but I'm pretty sure that OpenCL is what's causing it.
So my question is, how can I disable OpenCL in wand so that I can use those functions? Again, I've looked for solutions, but alas I couldn't find anything python specific, and the api module and the python module itself don't seem to mention anything about it either.
Any help would be greatly appreciated, thanks!
Just set the environment variable MAGICK_OCL_DEVICE=off to disable OpenCL.
Either before running the script.
export MAGICK_OCL_DEVICE=OFF
python myScript.py
Or within the python script before invoking any Wand code.
import os
os.environ['MAGICK_OCL_DEVICE'] = 'OFF'
# ... wand stuff ...
And the reason that it looks like your application stops running is that ImageMagick will need to run an OpenCL benchmark the first time and that can take a while. The result of the benchmark will be cached and used the next time an "OpenCL-accelerated" method is executed.
Related
How can I set my path so that I can easily switch between several coding languages? I am new to stuff like this so I appreciate any help.
You shouldn't have to set anything. Whatever reads your python code is a completely separate entity from what compiles/understands your C++ code. Your operating system's PATH variable contains a list of places for the system to look for programs.
Your python and C++ tools can co-exist in your PATH without butting heads or causing any issues. I have C++, python, and C# stuff all installed and they get along fine.
I'm trying to get back into coding for some math/physics experimentations and found VTK as a powerful tool using python. So I installed Python(x,y) and Pycharm Community edition. But I cannot get the Code Completion for VTK to work. I know this question has been posted quite a lot of times, but I couldn't find any concrete answer.
Here's what I know so far:
In order for Code Completion to work Pycharm constructs Skeletons. (Basically Python files with empty Classes/Methods that match the C++ API and can then be used like any other Python file for code completion.)
If I locate these files they don't appear to be complete and look something like this:
If this is indeed the skeleton (the file is called vtkRenderingPython.py) then shouldn't there be empty function declarations?
The result is that I get code completion for the classnames, but not the functions. For a library this huge that's rather annoying. Is there an easy way to get this working, or is this just a limitation I have to live with? Is there maybe a way to get complete Skeletons and replace the ones I have here? Am I missing the point entirely?
After another couple of hours I tried my luck with the PyDev extension for Eclipse. I didn't think that would work, but to my surprise it did! No settings necessary, it just worked out of the box.
The only drawback is that inherited methods are not shown in code completion. The base class is shown in the documentation window though so you can get the available functions by creating a temporary object of the base class and scrolling through the code completion there.
I have an executable (face recognition) written by one of our programmers who's no longer with us. It takes a commandline argument and prints the result to STDOUT like this.
I need to be able to use this in Python but performance is important so I'm not sure if I should just use subprocess. I need to capture the output of the program so is it a better idea to modify the code to make it a C++ library instead and write a wrapper for it in Python? How would that impact performance compared to using subprocess?
I have looked into the Python docs for running C code and found this but the answer here is different. The second method does not even use Python.h so I'm a little confused. What's the best way to do what I need when performance is important?
At first I have to tell you I think subprocess method and running external application and reading output from STD output would be slow and unreliable. I won't recommend that method.
Instead, here is some suggestions:
You can create a Python extension in C or C++, you can find a lot of resources online about it. So you can convert your current code to Python extension format and just use Python extension skeleton template, integrate your functions and code in it and you'll have a python extension, simply you'll be able to call it's functions from Python code. See: http://docs.python.org/2/extending/index.html
Convert your current C++ code directly into a DLL and exports functions of your code you want to call from python if you are in Windows or simply convert it to a shared library if you are using Linux. It will be compiled to .so . Then you can call functions as an external library in your Python code. Example with explanation: http://www.linuxforu.com/2010/05/extending-python-via-shared-libraries/
I've never tried them, but it seems these projects can help you with what you want:
http://sourceforge.net/projects/pygccxml/?source=dlp
https://code.google.com/p/pybindgen/
http://www.cython.org/
I guess this is kind of a weird question, but let's say you run a code in python that does something computationally expensive, like image processing. Oh I'm running Ubuntu 12.04 by the way. So I'm running a code, and open another terminal and type top to see what's doing what. This is ok as it tells me that python is doing its job, but what if I want to see which line is being run on the code? Is this possible? More importantly is it worth it to get this information? I can post a sample code of some of the processing if necessary
Don't blink, unless your "line of code" is unbelievably slow there is no way for such a thing to be useful. What you probably want is a Python Profiler. I suggest you start looking in http://docs.python.org/2/library/profile.html for info related to profiling your python code.
It usually is very slow but you can trace you code:
python -m trace --count -C . somefile.py ...
More manual but traditional way is logging: you can insert print statements before and after slow operations.
You can find slow places in you code using a profiler.
And you can run your code step by step with a debugger. Just insert import pdb; pdb.set_trace() (or ipdb if you like ipython) before slow operation.
This is the classic use case for a debugger. Have a look at Eclipse with the PyDev plugin, which is an IDE for Python with a useful debugger integration.
For example, a debugger allows you to set breakpoints where the execution will stop in order to let you manually step through the relevant lines of code to see how it goes. At the same time, you can inspect the variables' contents. You will thereby get a better understanding of what is happening, where and why it fails, and so on.
Go and get yourself a debugger!
I am currently in a course that is using OpenGL and I have been using C for all the programs so far. I have Python installed on Fedora as well as OpenGL, however the minute I call an OpenGL command in my Python code, I get a segmentation fault. I have no idea why this is.
Just to avoid the "just use C" comments, here is why I want to use Python:
There are a couple reasons I am wanting to switch from C to Python, but the main one is because we are about to start writing a raytracer and I would like to use classes to make it easier on me. Since I hate classes in C++ and structs in C seems a little crazy, I thought I would give Python a try at it. I have also been looking for a reason to use Python again as it has been a while.
Thanks for any help.
You may also want to consider using Pyglet instead of PyOpenGL. It's a ctypes-wrapper around the native OpenGL libs on the local platform, along with windowing support (should handle most of the stuff you want to use GLUT for.) The pyglet-users list is pretty active and very helpful.
Well, I don't know if these are the libs the original poster are using but I saw identical issues in a pet project I'm working on (Graphics Engine using C++ and Python) using PyOpenGL.
PyOpenGL didn't correctly pick up the rendering context if it was created after the python script had been loaded (I was loading the script first, then calling Python methods in it from my C++ code).
The problem doesn't appear if you initialize the display and create the OpenGL rendering context before loading the Python script.
What OpenGL library are you using? What windowing library? What version of Python?
Most likely cause I can think of is that your windowing library (SDL or whatever you're using) isn't initializing OpenGL before you start calling into it.
We have neither ideas about random segmentation faults. There is not enough information. What python libraries are you using for opengl? How do you use them? Can you show us your code? It's probably something trivial but my god -skill ends up to telling me just and only that.
Raytracer in python? I'd prefer just doing that in C with those structs. But then, I'm assuming you aren't going to do a realtime raytracer so that may be ok.
Perhaps you are calling an OpenGL function that requires an active OpenGL context, without having one? That shouldn't necessarily crash, but I guess it might. How to set up such a context depends on the platform, and it's been a while since I used GL from Python (and when I did, I also used GTK+ which complicates matters).
Scripts never cause segmentation faults.
But first see if your kernel and kmod video driver working property ...
Extension modules can cause "segmentation fault".