Re: [Tutor] Running .py Files
On 06/06/2012 04:14, Benjamin Cox wrote: Hello, So, I'm very new to Python and programming in general, and I've been having trouble figuring out how to run programs by clicking on their .py file name. For some reason, my computer's default setting is to open them in wordpad. I have Windows 7 32-bit OS and Python 3.2.3. Any help would be greatly appreciated! Thanks, Ben ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Start here http://docs.python.org/release/3.2/using/windows.html, any problems please feel free to ask as we don't bite :) -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running .py files in shell
Robert Layne wrote: Well everybody, sorry for the incomplete sentences and overall poor English but I wanted to make this simple to read and understand for someone who is completely inexperienced in any sort of programming, Generally speaking, incomplete sentences and overall poor English make things HARDER to read and understand rather than easier. Or to put it another way: Generally speaking, incomplete overall poor make things HARDER read understand than easier. wink as I am (very first day messing with this stuff, e.g., terminal). This is the result of hours of Googling that was all done in one day. Perhaps someone who is familiar with the commands below (in bold) wouldn’t Many of your readers -- including me -- prefer plain text email rather than HTML (what Outlook wrongly calls rich text), for various reasons including security. So you should not assume that colours and bold text will be coloured or bold. If you want to emphasis text, writing it like *this* is a good way. This *especially* holds true for programmers, who tend to be very suspicious of fancy colourful fonts and dancing paperclips and prefer good old plain text that you could read over telnet using a 28K modem to a computer in Siberia over a flaky link at 3 in the morning. mind explaining what exactly is taking place. Additionally, this was all done in terminal on a MacBook Pro running Mac OS Lion. Unfortunately, I haven't used a Mac since about 1999 or thereabouts, so I can't answer any Mac specific questions. However, I will say one thing: you seem to have made a really complicated job out of something as simple as be able to run Python programs from the shell. For starters, I'm pretty sure Mac OS X comes with Python automatically. Perhaps not the most recent version, but I'm sure it will be there. Just try running python from the shell, and it should Just Work. If you want to install the most recent version, you shouldn't need to install pygame, then uninstall pygame. It shouldn't take eight steps to install the latest version of Python! (Even installing from source code under Linux, it only takes five: download, extract, configure, make, install.) My suggestion is you try something like the Mac installer for ActivePython: http://www.activestate.com/activepython/downloads The instructions here are pretty old, but they should give you some hints: http://diveintopython.org/installing_python/macosx.html Or just use the Mac installer from here: http://www.python.org/download/ -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running .py files in shell
Well everybody, sorry for the incomplete sentences and overall poor English but I wanted to make this simple to read and understand for someone who is completely inexperienced in any sort of programming, as I am (very first day messing with this stuff, e.g., terminal). This is the result of hours of Googling that was all done in one day. Perhaps someone who is familiar with the commands below (in bold) wouldn’t mind explaining what exactly is taking place. Additionally, this was all done in terminal on a MacBook Pro running Mac OS Lion. 1. Install macport binary (comes with installer; easy) 2. sudo port install py-game a. not sure if this is necessary, as it doesn’t appear to cause pygame to be functional for python version 2.7.1 (stock python on lion) 3. sudo port select --set python python 2.7 a. I believe this set the default python version to 2.7.2 which I also believe was downloaded during step 2 (therefore why I think this ends up being a necessary step) 4. Download setuptools-0.6c11-py2.7.tar 5. In folder gasp-0.3.4, which appears after clicking on the .tar, place setup.py in the gasp folder 6. sudo python gasp/setup.py install a. make sure your directory is the folder gasp-0.3.4 7. sudo port –v install py27-gtk a. takes about an hour for this step to complete 8. sudo port uninstall py-game a. this step is not necessary for gasp to work; I simply didn’t want any unnecessary stuff on my computer that was downloaded during the second step; however, this step put python 2.7.2 on my computer; could install 2.7.2 separately I guess but this way worked for me; a lot of other unnecessary stuff is installed during this step too but I think it’ll remain even after this command, oh well ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running .py files in shell
I am running Mac OSX v10.6.4 Snow Leopard I am running Python 2.6.1 In general get the MacPython distributions of Python etc, they usually install easier (ie from the GUI) than the Unix based versions. Okay, thanks. I will look into that. 1. How do I execute .py files in the command line shell? I have my files in /Users/Kevin/python-exercises/ and am opening python in shell from that directory There are numerous ways, especially in MacOS. The simplest way is to put a shebang line at the top of your script and then make them executable: $ cat myscript.py What is the significance of this and how do I use it? I guess this is a command to add in to Shell, however when I use this I get the following error: cat tryme1.py Traceback (most recent call last): File stdin, line 1, in module NameError: name 'cat' is not defined #! /bin/env python With my configuration, I am guessing I need to change this snippet to: #! /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin python # the above line must be the first line in your file and tells the # shell where to find python # rest of your code follows. Then use chmod +x to make it executable $ chmod +x myscript.py When I try to run this with one of my files I get the following error: chmod +x tryme1.py File stdin, line 1 chmod +x tryme1.py ^ SyntaxError: invalid syntax Now you can run it: $ myscript.py Alternatively you can just call python explicitly: $ python myscript.py I get a syntax error doing this too: python tryme1.py File stdin, line 1 python tryme1.py ^ SyntaxError: invalid syntax ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running .py files in shell
On Wed, Jul 28, 2010 at 2:39 AM, Kevin Rapley ke...@digikev.co.uk wrote: I am running Mac OSX v10.6.4 Snow Leopard I am running Python 2.6.1 In general get the MacPython distributions of Python etc, they usually install easier (ie from the GUI) than the Unix based versions. Okay, thanks. I will look into that. 1. How do I execute .py files in the command line shell? I have my files in /Users/Kevin/python-exercises/ and am opening python in shell from that directory There are numerous ways, especially in MacOS. The simplest way is to put a shebang line at the top of your script and then make them executable: $ cat myscript.py What is the significance of this and how do I use it? I guess this is a command to add in to Shell, however when I use this I get the following error: cat tryme1.py Traceback (most recent call last): File stdin, line 1, in module NameError: name 'cat' is not defined #! /bin/env python With my configuration, I am guessing I need to change this snippet to: #! /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin python # the above line must be the first line in your file and tells the # shell where to find python # rest of your code follows. Then use chmod +x to make it executable $ chmod +x myscript.py When I try to run this with one of my files I get the following error: chmod +x tryme1.py File stdin, line 1 chmod +x tryme1.py ^ SyntaxError: invalid syntax Now you can run it: $ myscript.py Alternatively you can just call python explicitly: $ python myscript.py I get a syntax error doing this too: python tryme1.py File stdin, line 1 python tryme1.py ^ SyntaxError: invalid syntax ___ Tutor maillist - tu...@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor It looks like you're trying to type it into the python prompt, when you should be trying to type it into the shell command prompt. You can import tryme1.py in the python shell/interpreter, but you python tryme.py from the shell ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running .py files in shell
Kevin Rapley ke...@digikev.co.uk wrote The simplest way is to put a shebang line at the top of your script and then make them executable: $ cat myscript.py What is the significance of this and how do I use it? cat tryme1.py Notice the difference in the prompt. A dollar sign is the generic way of indicating a Unix shell prompt. cat is a Unix command which catenates the output to a file, again using cat like this is a generic way of sayong create a file containing whatever follows cat. In practice you would use a text editor like vim or pico etc. means the python prompt. You are typing a Unix command into Python which doesn't reciognise it, hence the error. My apologies for not being explicit. I assumed since you were using the shell to run sudo port install that you were an experienced Unix shell user and would understand the significance of $. (Incidentally % is the generic way of indicating a rioot user command, so % cat mydfile implies login as root (or use sudo) to type the command) Then use chmod +x to make it executable $ chmod +x myscript.py When I try to run this with one of my files I get the following error: chmod +x tryme1.py Same problem. chmod is the unix command to Change Mode of a file. $ myscript.py Alternatively you can just call python explicitly: $ python myscript.py I get a syntax error doing this too: python tryme1.py And again, you type python on its own to start a Python interpreter session. You type, in Unix shell, python file.py to get Python to execute file.py You can find a box explaining some of this in my tutor in the Style topic, near the bottom... HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running .py files in shell
Kevin Rapley ke...@digikev.co.uk wrote I am running Mac OSX v10.6.4 Snow Leopard I am running Python 2.6.1 In general get the MacPython distributions of Python etc, they usually install easier (ie from the GUI) than the Unix based versions. 1. How do I execute .py files in the command line shell? I have my files in /Users/Kevin/python-exercises/ and am opening python in shell from that directory There are numerous ways, especially in MacOS. The simplest way is to put a shebang line at the top of your script and then make them executable: $ cat myscript.py #! /bin/env python # the above line must be the first line in your file and tells the # shell where to find python # rest of your code follows. Then use chmod +x to make it executable $ chmod +x myscript.py Now you can run it: $ myscript.py Alternatively you can just call python explicitly: $ python myscript.py You can do other things with file associations and MacOS bundles/packages etc but unless its a major app that you use a lot the techniques above are easier. 2. How do I install GASP which is referenced in chapter 4? Can't help you there, sorry... I have MacPorts installed and have attempted to install PyObjC, which is referenced as a prerequisite to PyGame and GASP. I get the following error when attempting to install PyObjC: Check the MacPython web site, I'm sure I used an install package when I played with PyObjC... HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor