PDA

View Full Version : import: command not found: python on ubuntu?



psychoman.exe
April 14th, 2008, 03:29 AM
I recieved a python script that runs perfectly on windows, but when I try running it in terminal I get several of these:

import: command not found

now, as far as I know, import is a basic command in any version of python.
Do I need to get another library, or (as strange as it sounds) are some commands just different in ubuntu?

Wybiral
April 14th, 2008, 03:32 AM
Can you show us the code that's doing this? "import" is built into the language, it's a keyword.

LaRoza
April 14th, 2008, 03:34 AM
You most likely are missing the shebang line.

Windows uses file extensions to determine the file type (and everything else...), Linux is a bit more smart about it.

This should be the first line:


#!/usr/bin/python

psychoman.exe
April 14th, 2008, 03:40 AM
import sys

import socket

import string

import random

those are the first four lines of code

this is what terminal tells me:



/home/steven/Desktop/Scrambles.py: line 1: import: command not found
/home/steven/Desktop/Scrambles.py: line 2: import: command not found
/home/steven/Desktop/Scrambles.py: line 3: import: command not found
/home/steven/Desktop/Scrambles.py: line 4: import: command not found

LaRoza
April 14th, 2008, 03:41 AM
[CODE]
those are the first four lines of code

this is what terminal tells me:


Do what I said above.

Wybiral
April 14th, 2008, 03:44 AM
LaRoza is right, it looks like you're trying to execute it using "./program.py" which won't work without the shebang. You could, however, use "python program.py" to execute it without a shebang.

psychoman.exe
April 14th, 2008, 03:44 AM
ah, thanks Larosa, it works perfectly now

LaRoza
April 14th, 2008, 03:46 AM
ah, thanks Larosa, it works perfectly now

Of course it does. It worked perfectly before as well, just not the way you expected ;)

That line will be ignored in Windows, so it is safe that way.