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 "", 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
[Tutor] Running .py files in shell
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 <http://guide.macports.org/#project.tickets> 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