I am trying an OpenGL tutorial. I am running macosx with Haskell Platform installed
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
main :: IO ()
main = do
(progname, _) <- getArgsAndInitialize
createWindow "Hello World"
displayCallback $= display
display :: IO ()
display = do
clear [ ColorBuffer ]
flush
This is the error I am getting, the following is repeated for "clear","ColorBuffer" and "Flush"
Hello_World.hs:8:19:
Ambiguous occurrence `$='
It could refer to either `Graphics.Rendering.OpenGL.$=',
imported from `Graphics.Rendering.OpenGL' at Hello_World.hs:1:1-32
(and originally defined in `Data.StateVar')
or `Graphics.UI.GLUT.$=',
imported from `Graphics.UI.GLUT' at Hello_World.hs:2:1-23
(and originally defined in `OpenGL-2.2.3.1:Graphics.Rendering.OpenGL.GL.StateVar')
This code was working before, since then I have installed some packages via cabal install and by homebrew.
Since I think it might have something to do with packages here is "ghc-pkg list" (sorry for the block, just extra info that might help)
Cabal-1.14.0
GLUT-2.1.2.1
HTTP-4000.2.5
HUnit-1.2.5.1
OpenGL-2.2.3.1
QuickCheck-2.5.1.1
array-0.4.0.0
async-2.0.1.3
base-4.5.1.0
bin-package-db-0.0.0.0
binary-0.5.1.0
bytestring-0.9.2.1
cgi-3001.1.7.4
containers-0.4.2.1
deepseq-1.3.0.0
directory-1.1.0.2
extensible-exceptions-0.1.1.4
fgl-5.4.2.4
filepath-1.3.0.0
ghc-7.4.2
ghc-prim-0.2.0.0
haskell-platform-2012.4.0.0
haskell-src-1.0.1.5
haskell2010-1.1.0.1
haskell98-2.0.0.1
hoopl-3.8.7.3
hpc-0.5.1.1
html-1.0.1.2
integer-gmp-0.4.0.0
mtl-2.1.2
network-2.3.1.0
old-locale-1.0.0.4
old-time-1.1.0.0
parallel-3.2.0.3
parsec-3.1.3
pretty-1.1.1.0
primitive-0.5.0.1
process-1.1.0.1
random-1.0.1.1
regex-base-0.93.2
regex-compat-0.95.1
regex-posix-0.95.2
rts-1.0
split-0.2.1.1
stm-2.4
syb-0.3.7
template-haskell-2.7.0.0
text-0.11.2.3
time-1.4
transformers-0.3.0.0
unix-2.5.1.1
vector-0.10.0.1
xhtml-3000.2.1
zlib-0.5.4.0
/Users/james/.ghc/x86_64-darwin-7.4.2/package.conf.d
Cabal-1.16.0.3
GLURaw-1.3.0.0
ObjectName-1.0.0.0
OpenGL-2.6.0.1
OpenGLRaw-1.3.0.0
StateVar-1.0.0.0
Tensor-1.0.0.1
aeson-0.6.1.0
ansi-terminal-0.6
ansi-wl-pprint-0.6.6
attoparsec-0.10.4.0
blaze-builder-0.3.1.0
blaze-html-0.5.1.3
blaze-markup-0.5.1.4
cairo-0.12.4
cpphs-1.16
data-default-0.5.0
dlist-0.5
fay-0.14.1.0
fay-base-0.14.1.0
ghc-paths-0.1.0.9
gio-0.12.4
glib-0.12.4
gtk-0.12.4
hashable-1.2.0.5
haskeline-0.7.0.3
haskell-lexer-1.0
haskell-src-exts-1.13.5
hostname-1.0
language-ecmascript-0.10
language-haskell-extract-0.2.4
optparse-applicative-0.5.2.1
pango-0.12.4
pretty-show-1.5
safe-0.3.3
terminfo-0.3.2.5
test-framework-0.8
test-framework-hunit-0.3.0
test-framework-th-0.2.4
uniplate-1.6.10
unordered-containers-0.2.3.0
utf8-string-0.3.7
xml-1.3.12
You've imported both of these modules
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
which each export a function named ($=). You should figure out which you want to use and probably hide one of them, e.g.
import Graphics.Rendering.OpenGL hiding (($=))
or use qualified imports of one or both of those libs.
There were two problems. I think the error was due to me installing OpenGL when it was already installed and the second was my code was missing "mainLoop" so the program would stop really quickly. I just ended up reinstalling the haskell platform.
Thank you
Related
I am currently using python 2.7 with enthought from pythonxy package.
In my software, I need to use my own user_manager and other permissions tool. So I need to add external sources into apptools.permissions.
In apptools documentation, it said I need to develop another egg with namespace, apptools.permissions.external.
Therefore, I have developed a folder with three level:
apptools,
apptools.permissions,
apptools.permissions.external.
and setup.py.
In setup.py, I wrote:
# 3
from setuptools import setup, find_packages
setup(
name = "apptools.permissions.external",
author = "Airbus",
version = '0.1' ,
include_package_data = True, package_data={'': ['*.*']},
packages = find_packages(),#exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
test_suite = 'nose.collector',
entry_points = """
[envisage.plugins]
apptools.permissions.external = apptools.permissions.external.permissions_plugin:ExternalPermissionsPlugin
""",
#install_requires = ['Aerocity==1.01'],
zip_safe=True,
namespace_packages = ['apptools',
'apptools.permissions',
'apptools.permissions.external',
],
)
However, after I did python setup.py develop. I went to python and try to import apptools.permissions.external.
Python told me:
>>> import apptools.permissions.external
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named external
So it somehow cannot find this external egg. However, if I quickly changed the name of apptools to like apptools_test and related in folders and setup.py. I actually can import apptools_test.permissions.external.
So I think there is some problems when I merge namespace apptools.permissions.external to apptools. Python somehow gets confused.
Could someone help me with this case?
apptools.permissions was architected a long time ago when it was enthought.permissions and enthought was a namespace package. We have long since stopped doing that and refactored most of ETS into separate packages (sadly, apptools is still something of a grab-bag). When we did that, it seems that no one noticed that it was (ab)using the namespace package like that. Sorry about that. We, uh, don't use it much ourselves. Take that for whatever cold comfort it brings you. :-)
The only places it does this kind of indirection is in _*_default() methods, so you should be able to just assign your own instances for these traits. I'm not really sure why the namespace extension mechanism was attempted at all.
I'd like to either disable the VTK warning window or, better yet, catch them to handle with my application's logging system. My application is using an embedded mayavi view, and I don't want error windows popping up that I have no control over. The following code demonstrates the warning window.
import numpy as np
from mayavi import mlab
x1 = np.array([1, 1, 2, 3])
y1 = np.array([1, 1, 4, 2])
z1 = np.array([1, 1, 5, 1])
mlab.plot3d(x1, y1, z1)
mlab.show()
Ok, I've done some research and discovered that vtk.vtkObject.GlobalWarningDisplayOff() will disable the window completely, which is nice. Better yet the followingcode will log the warnings to a file (found it here):
def redirect_vtk_messages ():
""" Can be used to redirect VTK related error messages to a
file."""
import tempfile
tempfile.template = 'vtk-err'
f = tempfile.mktemp('.log')
log = vtkpython.vtkFileOutputWindow()
log.SetFlush(1)
log.SetFileName(f)
log.SetInstance(log)
So while this is nice, I'm still unable to pipe the warnings directly into a logging handler. I'd rather not have to have a vtk_log file next to my regular log files. Also I might want to handle the warnings in my GUI somehow, or give the user options on how to handle them and constantly watching a log file for changes seems like a poor way to do that.
Any suggestions on a robust pythonic way to handle vtk warnings in an application which embeds mayavi/vtk?
I don't know whether this will work in the Mayavi environment, but this works for Python wrappings to VTK
# pipe vtk output errors to file
errOut = vtk.vtkFileOutputWindow()
errOut.SetFileName("VTK Error Out.txt")
vtkStdErrOut = vtk.vtkOutputWindow()
vtkStdErrOut.SetInstance(errOut)
I guess this partially answer your question, but you could implement an error observer in python as explained here http://public.kitware.com/pipermail/vtkusers/2012-June/074703.html and add it to the vtk class you are interested.
In c++ I find much simpler to redirect the output to stderr (this example is for windows):
vtkSmartPointer<vtkWin32OutputWindow> myOutputWindow = vtkSmartPointer<vtkWin32OutputWindow>::New();
myOutputWindow->SetSendToStdErr(true);
vtkOutputWindow::SetInstance(myOutputWindow);
In python I tried
ow = vtk.vtkOutputWindow()
ow.SendToStdErrOn()
it sends the error to console, but I still see the vtk window and it doesn't really seem catching the errors.
Another option could be to recompile vtk with VTK_USE_DISPLAY turned off ( http://osdir.com/ml/python-enthought-devel/2009-11/msg00164.html). I am not going to try this because I am using the vtk distribution already compiled in paraview
You can create a subclass deriving from vtkOutputWindow and implement your message handling in the method void DisplayText(const char* someText). I did this is in a C++ project to redirect all output to cerr and even suppress specific warnings.
An approach I found similar to #SciCompLover's answer that suppresses the output window while also printing to the console:
import vtk
vtk_out = vtk.vtkOutputWindow()
vtk_out.SetInstance(vtk_out)
Tested on Mayavi 4.7.1 with VTK 8.2.0 on Windows and MacOS.
I get an error when I try to call the init_printing function from scipy
init_printing(use_latex=True)
TypeError: init_printing() got an unexpected keyword argument 'use_latex'
How do I correctly enable latex?
help(init_printing)
Help on function init_printing in module sympy.interactive.printing:
init_printing(pretty_print=True, order=None, use_unicode=None, wrap_line=None, no_global=False, ip=None)
Initializes pretty-printer depending on the environment.
You probably aren't using a new enough version of SymPy. Make sure you are using 0.7.4.1, the latest.
I am running OSX Lion and trying to import the python module for goocanvas, using python2.7.
I managed to successfully compile pygoocanvas-0.14.1, but when I try to import goocanvas through the python2.7 console, I get a segfault. After some debugging, I'm led to this code:
DL_EXPORT (void)
initgoocanvas (void)
{
PyObject *m, *d;
fprintf(stderr,"init<< \n");
// Pycairo_IMPORT; // XXX removed, it expands to the line below, anyways
Pycairo_CAPI = (Pycairo_CAPI_t*) PyCObject_Import("cairo", "CAPI"); // ADDED XXX
fprintf(stderr,"after import<< \n");
if (Pycairo_CAPI == NULL) {
return;
}
I discovered that the segfault happens when the C++ code of the goocanvas python module tries to import the "cairo" library through PyCObject_Import("cairo", "CAPI"). However, if I try to import the cairo module directly through the python2.7 console via import cairo, it works.
How should I proceed? I have a blind seg fault and no idea on why it happens. Remembering that I managed to compile the python goocanvas module, but it segfaults upon trying to import it on python.
What kind of console are you using? I think gtk/glib has some hooks to enable running the main loop concurrently with the REPL. This means that threads are in use, which may cause crashes if glib.threads_init() was not called.
IMHO this is broken by design, because by just importing glib or any g* module a sane Python program that uses any threads will suddenly start to segfault. Supporting threading should be the default.
In our case, the crash was caused by the logging system of glib which was forwarded to Python without holding the GIL.
I thought to try using D for some system administration scripts which require high performance (for comparing performance with python/perl etc).
I can't find an example in the tutorials I looked through so far (dsource.org etc.) on how to make a system call (i.e. calling another software) and receiving it's output from stdout, though?
If I missed it, could someone point me to the right docs/tutorial, or provide with the answer right away?
Well, then I of course found it: http://www.digitalmars.com/d/2.0/phobos/std_process.html#shell (Version using the Tango library here: http://www.dsource.org/projects/tango/wiki/TutExec).
The former version is the one that works with D 2.0 (thereby the current dmd compiler that comes with ubuntu).
I got this tiny example to work now, compiled with dmd:
import std.stdio;
import std.process;
void main() {
string output = shell("ls -l");
write(output);
}
std.process has been updated since... the new function is spawnShell
import std.stdio;
import std.process;
void main(){
auto pid = spawnShell("ls -l");
write(pid);
}