Results 1 to 8 of 8

Thread: import: command not found: python on ubuntu?

  1. #1
    Join Date
    Dec 2007
    Beans
    6
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    import: command not found: python on ubuntu?

    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?

  2. #2
    Join Date
    Oct 2006
    Location
    Austin, Texas
    Beans
    2,715

    Re: import: command not found: python on ubuntu?

    Can you show us the code that's doing this? "import" is built into the language, it's a keyword.

  3. #3
    Join Date
    Apr 2007
    Beans
    14,781

    Re: import: command not found: python on ubuntu?

    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:
    Code:
    #!/usr/bin/python

  4. #4
    Join Date
    Dec 2007
    Beans
    6
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: import: command not found: python on ubuntu?

    Code:
    import sys
    
    import socket
    
    import string
    
    import random
    those are the first four lines of code

    this is what terminal tells me:

    Code:
    /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

  5. #5
    Join Date
    Apr 2007
    Beans
    14,781

    Re: import: command not found: python on ubuntu?

    Quote Originally Posted by psychoman.exe View Post
    [CODE]
    those are the first four lines of code

    this is what terminal tells me:
    Do what I said above.

  6. #6
    Join Date
    Oct 2006
    Location
    Austin, Texas
    Beans
    2,715

    Re: import: command not found: python on ubuntu?

    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.

  7. #7
    Join Date
    Dec 2007
    Beans
    6
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: import: command not found: python on ubuntu?

    ah, thanks Larosa, it works perfectly now

  8. #8
    Join Date
    Apr 2007
    Beans
    14,781

    Re: import: command not found: python on ubuntu?

    Quote Originally Posted by psychoman.exe View Post
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •