p5
p5 copied to clipboard
AttributeError: module 'builtins' has no attribute 'exit'
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:
- p5 release (version number or latest commit): 0.5.0
- Python version: 3.5.4
- Operating system: Windows 10
Was also able to replicate on:
- p5: 0.5.0
- Python: 3.6.5
- OS: OS X El Capitan 10.11.6
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.
@dbzhao, thanks for bringing this up. The behavior does seems a little odd. Could you try two things:
- Run this in a Python shell:
>>> import builtins
>>> 'exit' in dir(builtins)
- 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 callbuiltins.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.
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
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.
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()
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
File "C:\Users\Lenovo\Documents\Python Scripts\double_pendulum.py", line 27, in
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'
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
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