p5py / p5

p5 is a Python package based on the core ideas of Processing.
https://p5.readthedocs.io
GNU General Public License v3.0
723 stars 120 forks source link

AttributeError: module 'builtins' has no attribute 'exit' #70

Open dbzhao opened 6 years ago

dbzhao commented 6 years ago

Describe the bug I've been getting an AttributeError: module 'builtins' has no attribute 'exit' error whenever I try to run the example in the README. I've tried installing on a different machine with a different OS and am getting the same error. Any ideas on what could be the issue? Let me know if any additional info would help. Thanks!

To Reproduce Just trying to run the example on the README:

from p5 import *

def setup():
    size(640, 360)
    no_stroke()
    background(204)

def draw():
    if mouse_is_pressed:
        fill(random_uniform(255), random_uniform(127), random_uniform(51), 127)
    else:
        fill(255, 15)

    circle_size = random_uniform(low=10, high=80)

    circle((mouse_x, mouse_y), circle_size)

def key_pressed(event):
    background(204)

run()

Errors produced

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-a8f1c3dd0d45> in <module>()
     19     p5.background(204)
     20 
---> 21 p5.run()

C:\Users\Daniel\AppData\Roaming\Python\Python35\site-packages\p5\sketch\userspace.py in run(sketch_setup, sketch_draw, frame_rate)
    145 
    146     app.run()
--> 147     exit()
    148 
    149 def title(new_title):

C:\Users\Daniel\AppData\Roaming\Python\Python35\site-packages\p5\sketch\userspace.py in exit(*args, **kwargs)
    218         default_sketch.show(visible=False)
    219         app.quit()
--> 220     builtins.exit(*args, **kwargs)
    221 
    222 def no_cursor():

AttributeError: module 'builtins' has no attribute 'exit'

System information:

Was also able to replicate on:

johndavidmiller commented 6 years ago

I'm getting this, too. I can run the examples from bash just fine, but if I try to run that same code from ipython or jupyter, I immediately get that "AttributeError: module 'builtins' has no attribute 'exit'" error.

Worse, it looks like it's exiting immediately, whereas running from bash does not. Perhaps an issue with the vispy module, not happy with the Python REPL and notebook environment?

FWIW, I'm using the latest and greatest Anaconda Python 3.6.5 distro on Mac 10.13.6.

abhikpal commented 5 years ago

@dbzhao, thanks for bringing this up. The behavior does seems a little odd. Could you try two things:

  1. Run this in a Python shell:
>>> import builtins
>>> 'exit' in dir(builtins)
  1. Can you try modifying your C:\Users\Daniel\AppData\Roaming\Python\Python35\site-packages\p5\sketch\userspace.py and commenting out line 220 (this is where p5 is trying to call builtins.exit() and then failing)?

but if I try to run that same code from ipython or jupyter, I immediately get that "AttributeError: module 'builtins' has no attribute 'exit'" error.

We haven't done any testing on running sketches from within Jupyter. It would be very neat to have Jupyter, though. We just haven't gotten the time to work on it. I won't have the time over the next couple of months, but is someone wants to dig into this, feel free!

Perhaps an issue with the vispy module,

Possible. They have been experimenting with adding support for Jupyter notebooks, I don't think there's anything stable enough currently.

guenounzakaria commented 5 years ago

I'm also using anaconda, so i wrote import builtins builtins.exit() still the same error its as if the compiler cannot access the exit attribute in builtins Any ideas how to fix it ? @abhikpal @dbzhao @johndavidmiller

pzanazzi commented 5 years ago

I had the same issue with anaconda, i like to use Spyder.

As a workaround you can just execute the script via conda prompt, e.g. 'python C:Code\p5_tutorial.py' and it works like a charm.

charamond commented 4 years ago

avec ide anaconda Python 3.7.4 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Windows 10 .
AttributeError: module 'p5.core.p5' has no attribute 'exit' sous anaconda prompt, p5 fonctionne une erreur est générée avec la fonction no_smooth()

Gauthameshwar commented 4 years ago

I'm getting the same error when i try to run the sample code provided in the README... Please help.. Im using python 3.7 in Spyder 4 environment to run my python p5 code...

The error:

WARNING: Traceback (most recent call last): File "C:\Users\Lenovo\anaconda3\lib\runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "C:\Users\Lenovo\anaconda3\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\Lenovo\anaconda3\lib\site-packages\spyder_kernels\console__main.py", line 11, in start.main() File "C:\Users\Lenovo\anaconda3\lib\site-packages\spyder_kernels\console\start.py", line 319, in main kernel.start() File "C:\Users\Lenovo\anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 583, in start self.io_loop.start() File "C:\Users\Lenovo\anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 149, in start self.asyncio_loop.run_forever() File "C:\Users\Lenovo\anaconda3\lib\asyncio\base_events.py", line 541, in run_forever self._run_once() File "C:\Users\Lenovo\anaconda3\lib\asyncio\base_events.py", line 1786, in _run_once handle._run() File "C:\Users\Lenovo\anaconda3\lib\asyncio\events.py", line 88, in _run self._context.run(self._callback, self._args) File "C:\Users\Lenovo\anaconda3\lib\site-packages\tornado\ioloop.py", line 690, in lambda f: self._run_callback(functools.partial(callback, future)) File "C:\Users\Lenovo\anaconda3\lib\site-packages\tornado\ioloop.py", line 743, in _run_callback ret = callback() File "C:\Users\Lenovo\anaconda3\lib\site-packages\tornado\gen.py", line 787, in inner self.run() File "C:\Users\Lenovo\anaconda3\lib\site-packages\tornado\gen.py", line 748, in run yielded = self.gen.send(value) File "C:\Users\Lenovo\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 361, in process_one yield gen.maybe_future(dispatch(args)) File "C:\Users\Lenovo\anaconda3\lib\site-packages\tornado\gen.py", line 209, in wrapper yielded = next(result) File "C:\Users\Lenovo\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 268, in dispatch_shell yield gen.maybe_future(handler(stream, idents, msg)) File "C:\Users\Lenovo\anaconda3\lib\site-packages\tornado\gen.py", line 209, in wrapper yielded = next(result) File "C:\Users\Lenovo\anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 541, in execute_request user_expressions, allow_stdin, File "C:\Users\Lenovo\anaconda3\lib\site-packages\tornado\gen.py", line 209, in wrapper yielded = next(result) File "C:\Users\Lenovo\anaconda3\lib\site-packages\ipykernel\ipkernel.py", line 300, in do_execute res = shell.run_cell(code, store_history=store_history, silent=silent) File "C:\Users\Lenovo\anaconda3\lib\site-packages\ipykernel\zmqshell.py", line 536, in run_cell return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs) File "C:\Users\Lenovo\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2858, in run_cell raw_cell, store_history, silent, shell_futures) File "C:\Users\Lenovo\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2886, in _run_cell return runner(coro) File "C:\Users\Lenovo\anaconda3\lib\site-packages\IPython\core\async_helpers.py", line 68, in _pseudo_sync_runner coro.send(None) File "C:\Users\Lenovo\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3063, in run_cell_async interactivity=interactivity, compiler=compiler, result=result) File "C:\Users\Lenovo\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3254, in run_ast_nodes if (await self.runcode(code, result, async=asy)): File "C:\Users\Lenovo\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3331, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in runfile('C:/Users/Lenovo/Documents/Python Scripts/double_pendulum.py', wdir='C:/Users/Lenovo/Documents/Python Scripts') File "C:\Users\Lenovo\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 562, in runfile exec_code(file_code, filename, ns_globals, ns_locals) File "C:\Users\Lenovo\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 463, in exec_code exec(compiled, ns_globals, ns_locals) File "C:\Users\Lenovo\Documents\Python Scripts\double_pendulum.py", line 27, in rt.run() File "C:\Users\Lenovo\anaconda3\lib\site-packages\p5\sketch\userspace.py", line 160, in run exit() File "C:\Users\Lenovo\anaconda3\lib\site-packages\p5\sketch\userspace.py", line 240, in exit app.quit() File "C:\Users\Lenovo\anaconda3\lib\site-packages\vispy\app_default_app.py", line 69, in quit return default_app.quit() File "C:\Users\Lenovo\anaconda3\lib\site-packages\vispy\app\application.py", line 155, in quit return self._backend._vispy_quit() File "C:\Users\Lenovo\anaconda3\lib\site-packages\vispy\app\backends_glfw.py", line 202, in _vispy_quit win._vispy_canvas.close() File "C:\Users\Lenovo\anaconda3\lib\site-packages\vispy\app\canvas.py", line 456, in close self.events.close() File "C:\Users\Lenovo\anaconda3\lib\site-packages\vispy\util\event.py", line 455, in call__ self._invoke_callback(cb, event) File "C:\Users\Lenovo\anaconda3\lib\site-packages\vispy\util\event.py", line 475, in _invoke_callback self, cb_event=(cb, event)) << caught exception here: >> File "C:\Users\Lenovo\anaconda3\lib\site-packages\vispy\util\event.py", line 471, in _invoke_callback cb(event) File "C:\Users\Lenovo\anaconda3\lib\site-packages\p5\sketch\base.py", line 142, in on_close exit() NameError: name 'exit' is not defined ERROR: Invoking <bound method Sketch.on_close of <Sketch (Glfw) at 0x19ca8150808>> for Event Traceback (most recent call last):

File "C:\Users\Lenovo\Documents\Python Scripts\double_pendulum.py", line 27, in rt.run()

File "C:\Users\Lenovo\anaconda3\lib\site-packages\p5\sketch\userspace.py", line 160, in run exit()

File "C:\Users\Lenovo\anaconda3\lib\site-packages\p5\sketch\userspace.py", line 241, in exit p5.exit(*args, **kwargs)

AttributeError: module 'p5.core.p5' has no attribute 'exit'

mervturner commented 4 years ago

Hi getting same result when running from Jupyter Notebook Runs OK if I call it directly python c:\code\flocking.py as noted by pzanazzi commented on Jan 10, 2019

I take it there has been no research on running in Jupyter

mervturner commented 4 years ago

There seems to have been some work in resolving vispy with Jupyter Notebooks vispy.plot not working in Jupyter notebook #1312 https://github.com/vispy/vispy/issues/1312