Code Point
September 08, 2010, 08:32:20 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Geshi Sintax Hilighting Mod Installed. Tens of languages available.
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Simple env problem - No Executables  (Read 2279 times)
flebber
Jr. Member
*

Karma: 0
Offline Offline

Posts: 4


« on: April 06, 2007, 07:05:59 AM »

HI

I am having a simple env problem.

from the Book " learning python" I was trying to create a small module

Quote
#! /usr/bin/env python
print 'Hello module world!'

This should be simple as it says chmod +x module1.py

and then can be executed by simply typing at a prompt > module1

However I cannot the prompt returns command not found. And the Interpreter
Quote
>>> module1

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in -toplevel-
    module1
NameError: name 'module1' is not defined
>>>

So I set the environmental variable $PATH
Quote
echo $PATH /home/flebber/Python /home/flebber
/usr/bin:/bin:/usr/local/bin:/usr/X11R6/bin/:sbin:/usr/sbin:/usr/games:/usr/lib/qt3//bin:/home/flebber/bin:/usr/lib/qt3//bin /home/flebber/Python /home/flebber
tried again but no luck. The solution must be so simple but I can't see it now cause it is so simple.

Any Ideas.
Logged
Alter Lobo
Global Moderator
Jr. Member
*****

Karma: 10
Offline Offline

Posts: 65


« Reply #1 on: April 06, 2007, 10:49:44 AM »

From your post I presume you are in Linux. Please correct me as the program execution from the prompt is different in Windows.

This should be simple as it says chmod +x module1.py

and then can be executed by simply typing at a prompt > module1

If the file name is module1.py then that is the name you should use, with the extension.

However I cannot the prompt returns command not found. And the Interpreter
Code
>>> module1
 
Traceback (most recent call last):
 File "<pyshell#1>", line 1, in -toplevel-
   module1
NameError: name 'module1' is not defined
>>>

From the interpreter the module should be imported (without the extension):

Code
>>> import module1
 
Logged
flebber
Jr. Member
*

Karma: 0
Offline Offline

Posts: 4


« Reply #2 on: April 06, 2007, 11:20:33 AM »

I have fixed it, yes I am in linux.

I was using the wrong #! setting I corrected this by typing at a prompt > which python
I found it should have been #! /usr/bin/python

I could run the module as ./module1.py
After I specified the PATH setting as
PATH=$PATH:/home/flebber/Python

then success
Quote
[flebber@localhost Python]$ PATH=$PATH:/home/flebber/Python
[flebber@localhost Python]$ module1.py
Hello module world!
[flebber@localhost Python]$


Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!