HELP How do I start Python?

Robert Heller heller at deepsoft.com
Sat Aug 30 16:51:26 UTC 2014


At Sun, 31 Aug 2014 01:37:39 +1000 taig at melbpc.org.au,         "Ubuntu user technical support,  not for general discussions" <ubuntu-users at lists.ubuntu.com> wrote:

> 
> 
> 
> My knowledge of Linux is purely academic - that is, I know WHAT it is. 
> However, when it comes to detail, I still think IBM PC and compatible, 
> after 30+ years working in that area. Very little Linux has rubbed off 
> over the past few years.
> 
> I need to start Python and don't know how.
> 
> I'm using Ubuntu 10.04 Lucid which had Python v2.6.5 installed. I needed 
> v3.2 and installed it using the following code.
> 
> sudo add-apt-repository ppa:fkrull/deadsnakes
> sudo apt-get update
> sudo apt-get install python3.2
> 
> That produced about 100+ lines of output in the terminal window and each 
> activity reached a conclusion - there were no errors etc.
> 
> Before I continue with my project and following more instructions I need 
> to be sure that Py3.2 is installed and working. Note: I'm following 
> fairly explicit instructions but it doesn't involve this really basic 
> stuff. The author has to assume a certain amount of basic knowledge.
> 
> In my Applications Menu the Programming Tab contains four items:
> - Bless Hex Editor
> - bpython
> - DrPython
> - CompoZer
> 
> I may have opened one or two over the years but like most other stuff 
> with Ubuntu, I've used none of them. Anyway, none of these starts 
> Python, either 2.6 OR 3.2.  I would have expected to see a menu item? No!
> 
> Python3.2 is scattered everywhere. I've searched the entire disk for 
> files that are python3.2 related and found many files, directories, but 
> I don't know or which files to use to start the ball rolling. I've found 
> Executables, links to Executables, links to scripts, lot of stuff.
> 
> One doc I found talks about the importance of usr/bin/pythnx.y and yes, 
> I have many of them.  There are Python Executables for versions 1, 2, 3 
> and many other files in that directory but just looking at those is 
> meaningless. If I was using an IBM based machine I would use an exe or a 
> batch file. I was writing batch files in my sleep in 1982 but when it 
> comes to Linux I have no idea what starts an app running.  Some help in 
> that area might start the ball rolling for me.  I can follow trails, 
> read files, understand simple English (and complex) but where is that 
> starting point and since Python3.2 would appear to be installed, how can 
> I set up a little script that runs it each time?
> 

In UNIX and Linux, executable programs have no 'extension' and are indicated
simply by having executable permissions set: 'x's in the permissions (ls -l)
and/or a '*' at the end of the file name (ls -F).  Most (all?) of the files in 
/usr/bin will be executable programs (or scripts).

> Perhaps more importantly, how does any other program know? Is there a 
> procedure that's followed by all programs when they call upon the 
> services of another system?   In DOS based systems we had an environment 
> variable called a "path". This path was searched every time a command 
> was issued.  Stored somewhere in a directory in the path you would 
> expect to find the EXE or the batch file needed to start a program or 
> task running. Or, you'd set it up that way.
> 
> What happens in Linux?

Linux also has a PATH environment variable. This is a standard POSIX shell 
feature (which MS-DOS borrowed from), in a sense it is just like MS-DOS. 
(/usr/bin, as well as /bin should be in your PATH environment variable).

Python is a scripting language.  Generally one does not run Python by itself, 
instead one creates Python scripts.  A Python script (like any other script) 
is just a text file that has execute permissions (chmod +x foo.py).  The first 
line of a Python script would contain a line like:

#!/usr/bin/python -tt

that tells the command shell (eg bash) that the stript needs to be passed to 
/usr/bin/python (the usually place where Python would be installed).  The rest 
of the file would be the Python program -- the script.

Usually one creates these scripts with a plain text editor (emacs, vim, gedit, 
etc.).  And then makes them executable with the chmod command (eg chmod +x 
foo.py).  Python scripts *generally* end in .py, but they don't have to.  For 
security reasons, the current directory (.) is NOT included in the PATH 
environment variable, so to run a program in the current directory, one needs 
to specific the path explicity, generally with './' in front.

So what ones does is something like:

% vi helloworld.py
(vi commands to write the hello world in Python)
% chmod +x helloworld.py
% ./helloworld.py
Hello World

(I don't know if there are pointy-clicky IDEs for doing the above.)

> 
> Where is the fabulous tutorial that compares all this stuff?

That I can't say, since I don't use Python myself.

> 
> TIA
> GaryT
> 
> 
> 

-- 
Robert Heller             -- 978-544-6933
Deepwoods Software        -- Custom Software Services
http://www.deepsoft.com/  -- Linux Administration Services
heller at deepsoft.com       -- Webhosting Services
                                           




More information about the ubuntu-users mailing list