Re: Shebang line problems and python

2009-09-17 Thread Blaine
On Sep 16, 9:25 pm, Blaine  wrote:
> Hello,
>
> Scripts that have "#!/usr/bin/python" at the top do not parse
> correctly. Bash treats scripts with that shebang as if they are bash
> scripts.
>
> E.g.:
> bla...@attila ~/apps/rs-mu $ /usr/sbin/env-update
> /usr/sbin/env-update: line 6: import: command not found
> /usr/sbin/env-update: line 8: syntax error near unexpected token `('
> /usr/sbin/env-update: line 8: `def usage(status):'
>
> Scripts with "#!/usr/bin/env python" at the top work fine. In fact,
> `python` and `env python` both bring me to a python interpreter.
>
> I've tried other types of scripts. #!/bin/bash works, #!/usr/bin/perl
> works, #!/usr/bin/ruby works, etc. (and so do their #!/usr/bin/env
>  counterparts.) Because of this, I'm not sure if it is a
> Python issue or a system issue.
>
> Any and all advice appreciated, thanks.
>
> P.S. some system info:
> bla...@attila ~/apps/rs-mu $ uname -a
> Linux attila 2.6.27-gentoo #5 SMP Sun Oct 19 19:13:17 MST 2008 i686
> AMD Athlon(tm) 64 X2 Dual Core Processor 4000+ AuthenticAMD GNU/Linux
>
> bla...@attila ~/apps/rs-mu $ python --version
> Python 2.6.2
>
> bla...@attila ~/apps/rs-mu $ bash --version
> GNU bash, version 4.0.28(2)-release (i686-pc-linux-gnu)
> Copyright (C) 2009 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later  gpl.html>

Okay, in case anyone is curious, here is how I fixed the problem:
downgraded app-admin/eselect-python-20090801 to app-admin/eselect-
python-20090606
`rm /usr/bin/python/`
`ln -s -T /usr/bin/python2.6 /usr/bin/python`
`emerge python`
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shebang line problems and python

2009-09-17 Thread Rami Chowdhury
> I think I've discovered the problem. Someone from IRC had directed me
> here: http://bugs.gentoo.org/show_bug.cgi?id=279915

I would suggest testing with the Python binary itself in your shebang line 
(e.g. #!/usr/bin/python2.6, if it's in /usr/bin) to confirm, but that looks 
like it :-)


Rami Chowdhury
"Any sufficiently advanced incompetence is indistinguishable from malice." -- 
Grey's Law
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

On Wednesday 16 September 2009 23:27:12 Blaine wrote:
> On Sep 16, 9:25 pm, Blaine  wrote:
> > Hello,
> >
> > Scripts that have "#!/usr/bin/python" at the top do not parse
> > correctly. Bash treats scripts with that shebang as if they are bash
> > scripts.
> >
> > E.g.:
> > bla...@attila ~/apps/rs-mu $ /usr/sbin/env-update
> > /usr/sbin/env-update: line 6: import: command not found
> > /usr/sbin/env-update: line 8: syntax error near unexpected token `('
> > /usr/sbin/env-update: line 8: `def usage(status):'
> >
> > Scripts with "#!/usr/bin/env python" at the top work fine. In fact,
> > `python` and `env python` both bring me to a python interpreter.
> >
> > I've tried other types of scripts. #!/bin/bash works, #!/usr/bin/perl
> > works, #!/usr/bin/ruby works, etc. (and so do their #!/usr/bin/env
> >  counterparts.) Because of this, I'm not sure if it is a
> > Python issue or a system issue.
> >
> > Any and all advice appreciated, thanks.
> >
> > P.S. some system info:
> > bla...@attila ~/apps/rs-mu $ uname -a
> > Linux attila 2.6.27-gentoo #5 SMP Sun Oct 19 19:13:17 MST 2008 i686
> > AMD Athlon(tm) 64 X2 Dual Core Processor 4000+ AuthenticAMD GNU/Linux
> >
> > bla...@attila ~/apps/rs-mu $ python --version
> > Python 2.6.2
> >
> > bla...@attila ~/apps/rs-mu $ bash --version
> > GNU bash, version 4.0.28(2)-release (i686-pc-linux-gnu)
> > Copyright (C) 2009 Free Software Foundation, Inc.
> > License GPLv3+: GNU GPL version 3 or later  > gpl.html>
>
> I think I've discovered the problem. Someone from IRC had directed me
> here: http://bugs.gentoo.org/show_bug.cgi?id=279915
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shebang line problems and python

2009-09-17 Thread Diez B. Roggisch

Blaine schrieb:

Hello,

Scripts that have "#!/usr/bin/python" at the top do not parse
correctly. Bash treats scripts with that shebang as if they are bash
scripts.

E.g.:
bla...@attila ~/apps/rs-mu $ /usr/sbin/env-update
/usr/sbin/env-update: line 6: import: command not found
/usr/sbin/env-update: line 8: syntax error near unexpected token `('
/usr/sbin/env-update: line 8: `def usage(status):'

Scripts with "#!/usr/bin/env python" at the top work fine. In fact,
`python` and `env python` both bring me to a python interpreter.

I've tried other types of scripts. #!/bin/bash works, #!/usr/bin/perl
works, #!/usr/bin/ruby works, etc. (and so do their #!/usr/bin/env
 counterparts.) Because of this, I'm not sure if it is a
Python issue or a system issue.

Any and all advice appreciated, thanks.


Do you have a DOS-file-ending in your script by any chance?

Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: Shebang line problems and python

2009-09-16 Thread Blaine
On Sep 16, 9:25 pm, Blaine  wrote:
> Hello,
>
> Scripts that have "#!/usr/bin/python" at the top do not parse
> correctly. Bash treats scripts with that shebang as if they are bash
> scripts.
>
> E.g.:
> bla...@attila ~/apps/rs-mu $ /usr/sbin/env-update
> /usr/sbin/env-update: line 6: import: command not found
> /usr/sbin/env-update: line 8: syntax error near unexpected token `('
> /usr/sbin/env-update: line 8: `def usage(status):'
>
> Scripts with "#!/usr/bin/env python" at the top work fine. In fact,
> `python` and `env python` both bring me to a python interpreter.
>
> I've tried other types of scripts. #!/bin/bash works, #!/usr/bin/perl
> works, #!/usr/bin/ruby works, etc. (and so do their #!/usr/bin/env
>  counterparts.) Because of this, I'm not sure if it is a
> Python issue or a system issue.
>
> Any and all advice appreciated, thanks.
>
> P.S. some system info:
> bla...@attila ~/apps/rs-mu $ uname -a
> Linux attila 2.6.27-gentoo #5 SMP Sun Oct 19 19:13:17 MST 2008 i686
> AMD Athlon(tm) 64 X2 Dual Core Processor 4000+ AuthenticAMD GNU/Linux
>
> bla...@attila ~/apps/rs-mu $ python --version
> Python 2.6.2
>
> bla...@attila ~/apps/rs-mu $ bash --version
> GNU bash, version 4.0.28(2)-release (i686-pc-linux-gnu)
> Copyright (C) 2009 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later  gpl.html>

I think I've discovered the problem. Someone from IRC had directed me
here: http://bugs.gentoo.org/show_bug.cgi?id=279915
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shebang line problems and python

2009-09-16 Thread Johan Grönqvist

Blaine skrev:


I'm not sure if there is a Ctrl+Z in here... but, here's the output:
bla...@attila ~/tmp $ hexdump shebang-test
000 2123 752f 7273 622f 6e69 702f 7479 6f68
010 0a6e 6d69 6f70 7472 7320 7379 730a 7379
020 732e 6474 756f 2e74 7277 7469 2865 4822
030 6c65 6f6c 202c 6f77 6c72 2e64 6e5c 2922
040 000a
041


You can perhaps use "hexdump -c shebang-test"
to get characters instead of hexadecimals.

/ johan

--
http://mail.python.org/mailman/listinfo/python-list


Re: Shebang line problems and python

2009-09-16 Thread Blaine
On Sep 16, 10:46 pm, Steven D'Aprano
 wrote:
> On Wed, 16 Sep 2009 21:35:21 -0700, Blaine wrote:
> > bla...@attila ~/tmp $ cat ./shebang-test
> > #!/usr/bin/python
> > import sys
> > sys.stdout.write("Hello, world.\n")
> > bla...@attila ~/tmp $ ./shebang-test
> > ./shebang-test: line 2: import: command not found ./shebang-test: line
> > 3: syntax error near unexpected token `"Hello, world.\n"'
> > ./shebang-test: line 3: `sys.stdout.write("Hello, world.\n")'
>
> I've seen something similar to this, which was caused by invisible ctrl-Z
> characters somehow getting into my text file. If you view a hexdump of
> the file, are there any unexpected characters in the file, particularly
> before or between the # ! characters?

I'm not sure if there is a Ctrl+Z in here... but, here's the output:
bla...@attila ~/tmp $ hexdump shebang-test
000 2123 752f 7273 622f 6e69 702f 7479 6f68
010 0a6e 6d69 6f70 7472 7320 7379 730a 7379
020 732e 6474 756f 2e74 7277 7469 2865 4822
030 6c65 6f6c 202c 6f77 6c72 2e64 6e5c 2922
040 000a
041


> If not, what happens if you run the file directly with Python?
>
> python shebang-test

bla...@attila ~/tmp $ python shebang-test
Hello, world.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shebang line problems and python

2009-09-16 Thread km
assuming that ur on linux/unix
and assuming that u have shebang line as #!/usr/bin/python in ur script
set permissions like this
chmod 755 myscript.py
and then run the script as ./myscripy.py
OR
simply run the python script as "python myscript.py" at the shell prompt
(note that this doesnt need shebang line in ur script file)

HTH,
Krishna

On Thu, Sep 17, 2009 at 1:46 PM, Steven D'Aprano <
ste...@remove.this.cybersource.com.au> wrote:

> On Wed, 16 Sep 2009 21:35:21 -0700, Blaine wrote:
>
> > bla...@attila ~/tmp $ cat ./shebang-test
> > #!/usr/bin/python
> > import sys
> > sys.stdout.write("Hello, world.\n")
> > bla...@attila ~/tmp $ ./shebang-test
> > ./shebang-test: line 2: import: command not found ./shebang-test: line
> > 3: syntax error near unexpected token `"Hello, world.\n"'
> > ./shebang-test: line 3: `sys.stdout.write("Hello, world.\n")'
>
>
> I've seen something similar to this, which was caused by invisible ctrl-Z
> characters somehow getting into my text file. If you view a hexdump of
> the file, are there any unexpected characters in the file, particularly
> before or between the # ! characters?
>
> If not, what happens if you run the file directly with Python?
>
> python shebang-test
>
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shebang line problems and python

2009-09-16 Thread Steven D'Aprano
On Wed, 16 Sep 2009 21:35:21 -0700, Blaine wrote:

> bla...@attila ~/tmp $ cat ./shebang-test
> #!/usr/bin/python
> import sys
> sys.stdout.write("Hello, world.\n")
> bla...@attila ~/tmp $ ./shebang-test
> ./shebang-test: line 2: import: command not found ./shebang-test: line
> 3: syntax error near unexpected token `"Hello, world.\n"'
> ./shebang-test: line 3: `sys.stdout.write("Hello, world.\n")'


I've seen something similar to this, which was caused by invisible ctrl-Z 
characters somehow getting into my text file. If you view a hexdump of 
the file, are there any unexpected characters in the file, particularly 
before or between the # ! characters?

If not, what happens if you run the file directly with Python?

python shebang-test



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shebang line problems and python

2009-09-16 Thread Blaine
Chris Rebert, Rami Chowdhury:
bla...@attila ~/tmp $ which python
/usr/bin/python

Ben Finney:
bla...@attila ~/tmp $ echo $SHELL
/bin/bash
bla...@attila ~/tmp $ cat ./shebang-test
#!/usr/bin/python
import sys
sys.stdout.write("Hello, world.\n")
bla...@attila ~/tmp $ ./shebang-test
./shebang-test: line 2: import: command not found
./shebang-test: line 3: syntax error near unexpected token `"Hello,
world.\n"'
./shebang-test: line 3: `sys.stdout.write("Hello, world.\n")'

bla...@attila ~/tmp $ cat shebang-test2
#!/usr/bin/env python
import sys
sys.stdout.write("Hello, world.\n")
bla...@attila ~/tmp $ ./shebang-test2
Hello, world.

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shebang line problems and python

2009-09-16 Thread Ben Finney
Blaine  writes:

> Scripts that have "#!/usr/bin/python" at the top do not parse
> correctly. Bash treats scripts with that shebang as if they are bash
> scripts.

When you run a file as a command, it's not Bash that decides how to run
it; the kernel has the job of understanding how to run the program. Bash
simply ignores the shebang line, since it is (intentionally) a comment
as far as Bash is concerned.

> E.g.:
> bla...@attila ~/apps/rs-mu $ /usr/sbin/env-update
> /usr/sbin/env-update: line 6: import: command not found
> /usr/sbin/env-update: line 8: syntax error near unexpected token `('
> /usr/sbin/env-update: line 8: `def usage(status):'

As usual, it helps if we can see the actual content of a complete
minimal example.

Here's mine::

=
$ echo $SHELL
/bin/bash

$ cat ./shebang-test 
#! /usr/bin/python
import sys
sys.stdout.write("Hello, world.\n")

$ ./shebang-test
Hello, world.
=

Does the above session work differently for you?

Can you come up with a complete, minimal example that shows the
behaviour you're describing?

-- 
 \“Of course, everybody says they're for peace. Hitler was for |
  `\  peace. Everybody is for peace. The question is: what kind of |
_o__)peace?” —Noam Chomsky, 1984-05-14 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shebang line problems and python

2009-09-16 Thread Rami Chowdhury
Is it possible that python is installed not in /usr/bin but in, say, / 
usr/local/bin?


I'd suggest you try 'which python' to find out where it is. On my OS  
X, for instance:


$ which python
/Library/Frameworks/Python.framework/Versions/Current/bin/python


-
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)




On Sep 16, 2009, at 20:25 , Blaine wrote:


Hello,

Scripts that have "#!/usr/bin/python" at the top do not parse
correctly. Bash treats scripts with that shebang as if they are bash
scripts.

E.g.:
bla...@attila ~/apps/rs-mu $ /usr/sbin/env-update
/usr/sbin/env-update: line 6: import: command not found
/usr/sbin/env-update: line 8: syntax error near unexpected token `('
/usr/sbin/env-update: line 8: `def usage(status):'

Scripts with "#!/usr/bin/env python" at the top work fine. In fact,
`python` and `env python` both bring me to a python interpreter.

I've tried other types of scripts. #!/bin/bash works, #!/usr/bin/perl
works, #!/usr/bin/ruby works, etc. (and so do their #!/usr/bin/env
 counterparts.) Because of this, I'm not sure if it is a
Python issue or a system issue.

Any and all advice appreciated, thanks.

P.S. some system info:
bla...@attila ~/apps/rs-mu $ uname -a
Linux attila 2.6.27-gentoo #5 SMP Sun Oct 19 19:13:17 MST 2008 i686
AMD Athlon(tm) 64 X2 Dual Core Processor 4000+ AuthenticAMD GNU/Linux

bla...@attila ~/apps/rs-mu $ python --version
Python 2.6.2

bla...@attila ~/apps/rs-mu $ bash --version
GNU bash, version 4.0.28(2)-release (i686-pc-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
--
http://mail.python.org/mailman/listinfo/python-list


--
http://mail.python.org/mailman/listinfo/python-list


Re: Shebang line problems and python

2009-09-16 Thread Chris Rebert
On Wed, Sep 16, 2009 at 8:25 PM, Blaine  wrote:
> Hello,
>
> Scripts that have "#!/usr/bin/python" at the top do not parse
> correctly. Bash treats scripts with that shebang as if they are bash
> scripts.
>
> E.g.:
> bla...@attila ~/apps/rs-mu $ /usr/sbin/env-update
> /usr/sbin/env-update: line 6: import: command not found
> /usr/sbin/env-update: line 8: syntax error near unexpected token `('
> /usr/sbin/env-update: line 8: `def usage(status):'
>
> Scripts with "#!/usr/bin/env python" at the top work fine. In fact,
> `python` and `env python` both bring me to a python interpreter.
>
> I've tried other types of scripts. #!/bin/bash works, #!/usr/bin/perl
> works, #!/usr/bin/ruby works, etc. (and so do their #!/usr/bin/env
>  counterparts.) Because of this, I'm not sure if it is a
> Python issue or a system issue.
>
> Any and all advice appreciated, thanks.

Admittedly stupid questions:
1. Is there actually anything located at /usr/bin/python ?
2. What does "which python" output in bash?

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list