p5py / p5

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

run() is not defined #120

Open GypsyDangerous opened 5 years ago

GypsyDangerous commented 5 years ago

I installed p5 with pip using pip install p5 --user and i installed GLFW version 3.3 and added it to PATH. When i tried to run a p5py sketch it gives me an error saying that the run function is not defined. how can i fix this?.

here is the code i am trying to run

from p5 import *
x = 100
y = 100

xspeed = 1
yspeed = 3.3

def setup():
    size(200, 200)
    background(255)

def draw():
    global x
    global y
    global xspeed
    global yspeed

    no_stroke()
    fill(255, 10)
    rect((0, 0), width, height)

    # add the current speed to the location
    x = x + xspeed
    y = y + yspeed

    if x > width or x < 0:
        xspeed = -xspeed

    if y > height or y < 0:
        yspeed = -yspeed

    stroke(0)
    fill(175)
    circle((x, y), 16)

if __name__ == '__main__':
    run()

my relevant specs are: Windows 10 Python 3 GLFW 3.3

here is the error report python gives me:

Traceback (most recent call last):
  File "C:\Users\david\Python\p5.py", line 37, in <module>
    run()
NameError: name 'run' is not defined
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "C:\Users\david\Python\p5.py"]
[dir: C:\Users\david\Python]
[path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\ffmpeg\bin;C:\Program Files\Git\cmd;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\david\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users\david\AppData\Local\Programs\Python\Python37-32\;C:\Users\david\AppData\Local\Microsoft\WindowsApps;C:\Users\david\AppData\Local\atom\bin;C:\ffmpeg\bin;C:\Program Files\JetBrains\PyCharm Community Edition with Anaconda plugin 2019.1.1\bin;;C:\Program Files\heroku\bin;C:\Users\david\Downloads\glfw-3.3.bin.WIN64\glfw-3.3.bin.WIN64\lib-mingw-w64;]
jeremydouglass commented 5 years ago

Possibly a duplicate of #85 Although this is on Windows and not Mac OS, same error.

JXSTY commented 4 years ago

so am i platform-mac OS 10.15.3

stylerhall commented 4 years ago

Any update on this??

rpuntaie commented 4 years ago

You named your file p5.py. Then it loads your own file, which has indeed no run(). I made the same mistake.

virtualeiro commented 1 year ago

I have the same problem here. The file is saved as "Untitled.py".

from p5 import *

def setup(): size(800,600)

def draw(): background(0)

run()


Update - Fixed: I had two conflicting python versions installed 3.9 and 3.10 . I am using Visual Studio Code. When I checked the python packages installed (Settings>Code>Python), p5 and GLFW were installed under version 3.9 and it was interpreting the code under 3.10.

Juhhxx commented 1 year ago

still having the same issue tho jsut on new python files(?)

what could be the problem?

tushar5526 commented 1 year ago

Can you share the folder structure?