Re: [Tutor] Running .py files in shell

2011-09-22 Thread Steven D'Aprano

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.




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

2011-09-21 Thread Robert Layne
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

2010-07-28 Thread Alan Gauld

"Kevin Rapley"  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

2010-07-28 Thread David Hutto
On Wed, Jul 28, 2010 at 2:39 AM, Kevin Rapley  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 "", line 1, in 
> 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 "", 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 "", 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

2010-07-28 Thread Kevin Rapley



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 "", line 1, in 
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 "", 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 "", 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

2010-07-27 Thread Alan Gauld

"Kevin Rapley"  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


[Tutor] Running .py files in shell

2010-07-27 Thread Kevin Rapley
 Hello all, I am new to programming and have opted to learn Python as I 
hear it is a good first language. I am currently going through the 
exercises in 'How to Think Like a Computer Scientist: Learning with 
Python 2nd Edition'.


I am running Mac OSX v10.6.4 Snow Leopard
I am running Python 2.6.1

I have a couple of questions:

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


2. How do I install GASP which is referenced in chapter 4? The 
instructions in this book are not complete. I have researched and found 
a reference on Stack Overflow which is contributed to by GASP programmers

http://stackoverflow.com/questions/1024862/how-do-i-install-gasp-for-python-2-6-2-on-a-mac

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:


sudo port install py-pyobjc
Password:
--->  Computing dependencies for py-pyobjc
--->  Fetching py-pyobjc
Error: Target org.macports.fetch returned: PyObjC 1.4 is for Mac OS X 
10.4 and lower. On 10.5, use py-pyobjc2 instead.
Log for py-pyobjc is at: 
/opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py-pyobjc/main.log

Error: Status 1 encountered during processing.

It says to use py-objc2 instead, so I do so and get this error:

sudo port install py-pyobjc2
Error: Target org.macports.activate returned: Image error: 
/opt/local/lib/python2.4/site-packages/modulegraph/__init__.py is being 
used by the active py-modulegraph port.  Please deactivate this port 
first, or use 'port -f activate py-modulegraph-devel' to force the 
activation.
Log for py-modulegraph-devel is at: 
/opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_python_py-modulegraph-devel/main.log
Error: The following dependencies failed to build: py-py2app-devel 
py-modulegraph-devel

Error: Status 1 encountered during processing.
To report a bug, see 

I attempted to correct the issue by entering the following:

port -f activate py-modulegraph-devel

But it returned this error:

Warning: Failed to open Portfile from registry for py-modulegraph-devel 
@0.7.2_0

--->  Activating py-modulegraph-devel
Error: port activate failed: sqlite error: attempt to write a readonly 
database (8)


This is as far as I have got with resolving this issue so far. All help 
and guidance will be greatly appreciated.


Kevin Rapley
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor