LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Running Python Scripts (https://www.linuxquestions.org/questions/linux-newbie-8/running-python-scripts-4175473893/)

dragonpoet 08-19-2013 08:10 AM

Running Python Scripts
 
I have Red Hat Enterprise Linux 6.3 installed on two machines. When I try to run a python script on either of them (the same script for testing) it seems to start but immediately end. No pop-ups are present after starting the scripts.

After running the program, it should be asking to change values but it never shows up. Any suggestions on what could be wrong?

druuna 08-19-2013 08:18 AM

Quote:

Originally Posted by dragonpoet (Post 5011852)
I have Red Hat Enterprise Linux 6.3 installed on two machines. When I try to run a python script on either of them (the same script for testing) it seems to start but immediately end. No pop-ups are present after starting the scripts.

After running the program, it should be asking to change values but it never shows up. Any suggestions on what could be wrong?

A few questions for you:

- How are you running this script? From the GUI or from a terminal or ????
- What command are you using to execute the script?
- Are you sure the script works correctly?

dragonpoet 08-19-2013 08:27 AM

Quote:

Originally Posted by druuna (Post 5011856)
A few questions for you:

- How are you running this script? From the GUI or from a terminal or ????
- What command are you using to execute the script?
- Are you sure the script works correctly?

-I've tried just double-clicking and selecting 'run', and I've tried selecting 'run in terminal'
-I've changed the directory to the where the files are and used 'python (file name)'
-I got the script from someone else but on his machine (same OS and build) it ran just fine.

druuna 08-19-2013 08:50 AM

Quote:

Originally Posted by dragonpoet (Post 5011864)
-I've tried just double-clicking and selecting 'run', and I've tried selecting 'run in terminal'
-I've changed the directory to the where the files are and used 'python (file name)'
-I got the script from someone else but on his machine (same OS and build) it ran just fine.

I'd advise you to use a terminal (or multiple terminals). This makes running/editing the script(s) easier (my opinion).

This should work from a terminal:
Code:

cd /path/to/script_directory
python script_name.py

# mini example

cd /tmp
python test.py
1 + 2 = 3
foo bar foobar

# test.py mini script looks like this
import math
print "1 + 2 =", 1+2
print "foo bar foobar";

You might want to try running the test.py script, just to make sure python is working correctly. If not, please post any error/warning messages that are shown.

If your script isn't too long you might want to post it (do use [code] ... [/code] tags) so we can have a look.

dragonpoet 08-19-2013 08:54 AM

I just noticed a message after attempting to run the program in the terminal. "ImportError: no module named argparse"

I tried seeing if I have it using this command | python -c "import argparse; print argparse" and the same message appears.

YankeePride13 08-19-2013 09:24 AM

What version of Python are you running?

druuna 08-19-2013 09:26 AM

Assuming you use python 2.x: The argparse module isn't installed by default and I do believe also not part of the default packages that are available.

A little search comes up with this: python-argparse-1.2.1-2.el6.noarch.rpm

I do believe argparse became part of native python in version 3.2

dragonpoet 08-19-2013 09:42 AM

It is version 2.6.6.

YankeePride13 08-19-2013 09:46 AM

Quote:

Originally Posted by dragonpoet (Post 5011911)
It is version 2.6.6.

Then the module is not installed, you need to install it.

dragonpoet 08-19-2013 10:09 AM

I'm attempting to install the version 3.2.5 and when I do the './configure' there is a message saying "no acceptable C compiler in $Path"

I downloaded the file from the website and it was saved to my Downloads folder. I unzipped it and that is when I ran './configure' Is there something I am doing wrong up to this point?

YankeePride13 08-19-2013 10:19 AM

Quote:

Originally Posted by dragonpoet (Post 5011929)
I'm attempting to install the version 3.2.5 and when I do the './configure' there is a message saying "no acceptable C compiler in $Path"

I downloaded the file from the website and it was saved to my Downloads folder. I unzipped it and that is when I ran './configure' Is there something I am doing wrong up to this point?

Do you have GCC installed? If not, you need to install it.

dragonpoet 08-19-2013 10:52 AM

Ok. Thanks for all the feedback. I had assumed the GCC would have been installed when I installed the OS. Finally got the GCC installed and finishing installing Python 3.2.5. If I have any other problems I'll be sure to ask for your help again. Thank!

szboardstretcher 08-19-2013 10:55 AM

GCC is not installed by default. This is because it is an insecure program to have installed, and is widely used for evil on linux systems. Any compiler can be used for evil on an insecure system. So it is a good idea to use GCC to compile whatever you need, then uninstall it.

dragonpoet 08-19-2013 11:15 AM

Ok so following the instructions and running the install, it looks as though everything is fine. Then I tried to run my script again and it still says that the argparse module isn't installed. I checked again the version I have for python and I had assumed it would be 3.2.5 but it still says I am on 2.6.6.

I followed the read me instructions that followed like this:

- ./configure
- make
- make test
- yum make install

YankeePride13 08-19-2013 11:38 AM

First, uninstall the older version of Python. Then places the python binary in your PATH.


All times are GMT -5. The time now is 03:40 PM.