Seemingly easy and small error baffles me.

THIS CASE HAS BEEN SOLVED! PLEASE LOOK AT THE BOTTOM FOR THE ANSWERS, AND THANKS TO EVERYONE THAT HAS HELPED!

-SPIFFY

Yeah, I am kind of embarrassed but I have failed with the helloworld.py The gods of Python must hate me.

Before I start, I used text wrangler for my editing and my script is located in /Users/AAlcott/Documents/Python

I tried to do the line
python helloworld.py
It says there is a syntax error

Like this:

python helloworld.py
syntax error ^

Or something…

I am using byte of py’s tut

Please help
Thanks… spiffy!

P.S. I know, I am missing something so F***in Simple… but what?

What OS are you running?
I’m only familar with Windows, but it looks like python doesn’t know where the helloworld.py file is.
Try running that line from the directory that the file is in.

hi
if it gives you a syntax error,
it seems that you wrote “python helloworld.py” inside your python script
that’s no the thing to do
your python script is a .py file containing :
print “hello world” #or something else

and you should run a console and do :
python thescriptfile.py (on unices or windows if the python has been added to the system path)
or
C:\Python2.4\python.exe thescriptfile.py (or so on windows, considering that python is installed in c:\Python2.4\

the command “python thing.py” doesn’t exist in the python language, it’s just a call to run a program in your operating system

ok the first post I made was a little hasty, class just ended and I had to rush…

Let me explain in detail so you can help me easier.

I used the byte of python tutorial. http://swaroopch.info/text/Byte_of_Python:First_Steps this page to be exact.

I am using a mac, so I followed the steps: Mac OS X users can access the shell by opening Finder → Applications → Utilities → Terminal. Then, type python and press the enter key.
I then did the print ‘hello world’ and it works

Then I got an editor, like it told me to. I got text wrangler, (I don’t have the link) it is on the byte of python page though. Using that, I created a lovely document with print ‘hello world’ in it and I saved it as helloworld.py as per the tutorial. I saved the document in (please check my first post) and went back to the terminal and typed python helloworld.py

I did all that it told me too yet it does not work, there are no spelling errors, and the thing about programs of which you speak, I thought I MADE a program, or at least that is what the tutorial told me.

If you need anymore info, please ask, I really need to understand.

P.S. I don’t understand what you meant by the # or something in the script…

Bumpady Bump Bump! I really would like this information before my class is over… (no getting to play with python for a whole two weeks :frowning: )

maybe you could post the exact error (like the terminal prints it)
that is very helpful for more experienced programers sometimes (not that I am an experienced programer but anyway)

just post from the command promt to the next one, e.g.

python helloworld.py

blablabla
error ----^
bla

:smiley:

ok here it is…
Last login: Wed Dec 20 11:25:50 on ttyp1
Welcome to Darwin!
Hsa-107-D5:~ AAlcott$ python
Python 2.3.5 (#1, Mar 20 2005, 20:38:20)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> python helloworld.py
File “<stdin>”, line 1
python helloworld.py
^
SyntaxError: invalid syntax
>>>

Thanks

PS… The ^ is supposed to be under the d in helloworld… but the forum screwed it up

You should be typing python helloworld.py at the “Hsa-107-D5:~AAlcott$” prompt. But that also assumes that your helloworld.py file is in the ~AAlcot directory. I’m not familiar with Mac OS, but if it’s anything like unix (which I think it is), typing a “ls -l” (no quotes) or “ls” shoud list the files in the current directory.

What your doing is typing 'python", which is starting up the python interpeter, the “>>>” prompt indicates that python is waiting for a command. You’re then typing “python helloworld”… and the syntax error is because there is no “python” comand inside python.

Get it ?

If you want to run your script after you’ve started the python interepreter (i.e. at the “>>>” prompt), type “import helloworld” (no quotes) and it should work.

Re-reading your previous post, the problem is that after you started the python interepreter, then went to your editor, when you returned to the shell you had never exited python (CTR-Z … on a P.C. anyway), so that’s why the “python helloworld.py” didn’t work. You have to exit the python interpreter … or start up a new shell and it will work.

Mike

ok thanks for the help. I finally got back from winter break and I am now back at school. However I tried a new shell and it kind of worked… However it now cannot open it. I am thinking it is because it cannot find it, and I read something in a post here about paths, Does anyone know how to actually set up a path to the folder where my scripts are? Or is there a python script folder where it looks and I can place it there? I cannot have my script in the AAlcott folder as there are subfolders in that, Specifically, Users-AAlcott-Documents-(custom folder named Python).

Any help and tips?

If not I would also take any info on how to write a line to run the program, but that seems a hassle to do so everytime. Also, I shall include my lines from the recent shell.

Last login: Fri Jan 5 11:33:54 on ttyp1
Welcome to Darwin!
Hsa-107-D5:~ AAlcott$ python helloworld.py
python: can’t open file ‘helloworld.py’
Hsa-107-D5:~ AAlcott$

Meh…

If you want to run scripts from the command line, you either use the terminal command cd to move to the directory containing the script or just drag the script into the window. Let’s say you have a script in /users/somebody/helloworld.py

You can type:
cd /users/somebody/ hit return
python helloworld.py hit return

or just type python and drag the file into the window

In the case of running Python scripts for Blender, you generally don’t want to run them from the command line. You would either open them in the text window and hit alt-p or do what I do. If you make sure your python directory is set in your user prefs, you can add a block to the start of the file like this:

#!BPY

“”"
Name: ‘hello world’
Blender: 233
Group: ‘Export’
Tip: ‘print hello world’
“”"

Put your helloworld file in the scripts directory and when you go to the scripts panel and go to update menus, your helloworld script will appear in the export submenu. This way, you have the script open in a text editor (I use Smultron instead of Textwrangler btw because Textwrangler doesn’t like some PC encodings and it will scramble the file without warning) then when you save it, just go to the menu and choose the script again.

The output of the print command appears in your console (/Applications/Utitlities/console).

GOD I HATE PYTHON!

Or macs… Something, I must hate something!

To quote oxsrules…"if you want to run scripts from the command line, you either use the terminal command cd to move to the directory containing the script or just drag the script into the window. Let’s say you have a script in /users/somebody/helloworld.py

You can type:
cd /users/somebody/ hit return
python helloworld.py hit return

or just type python and drag the file into the window

I went into the terminal and decided to try your advice.

I decided first to try and type python and then drag and drop the .py file into it

Last login: Mon Jan 8 11:26:24 on ttyp1
Welcome to Darwin!
Hsa-107-D5:~ AAlcott$ python/Users/AAlcott/Documents/Python/helloworld.py
-bash: python/Users/AAlcott/Documents/Python/helloworld.py: No such file or directory
Hsa-107-D5:~ AAlcott$

As you can see, it didn’t think it was a file or directory… I think I did something wrong…

I then thought maybe I shouldn’t type python and maybe it would work

Hsa-107-D5:~ AAlcott$ /Users/AAlcott/Documents/Python/helloworld.py
-bash: /Users/AAlcott/Documents/Python/helloworld.py: Permission denied
Hsa-107-D5:~ AAlcott$

Now this one showed some promise… saying that permission is denied… If I can figure out how to let the computer know that it is me, maybe it will run it?

Any help?

I can give pics, anything ANYTHING! I just really want to start pythoning!

Please help ASAP, and sorry for being such a hard case.

-Ever Thankfull,
Spiffy

Run your terminal program.

After it starts, type “pwd” (no quotes). That will tell you what directory you’re in.

Save your python scripts to that directory, and you should be able to run them.

Do you have Blender on your machine there? … You can just run python scripts right in Blender’s text window, or change to a scripts window and run the system/interactive console which is handy because the output goes right into the same window, instead of the seperate blender-console window (when you run a script in the text window with alt-p).

Mike

How about inserting a space after “python” (and then drag’n’drop the file)?

python /Users/AAlcott/Documents/Python/helloworld.py

sw00t!

It worked It worked! sw00t sw00t sw00ty sw00t!

Thanks alot for all of your help! Finally I can go on and learn more python!

Have a great Day everyone!