Results 1 to 9 of 9

Thread: Bizarre python error when command isn't found

  1. Default Bizarre python error when command isn't found

    Hi,

    I just decided to install Tumbleweed on my new PC (my first desktop PC actually, only ever had laptops to call my own), and one thing I noticed very early on was this error message:

    Code:
      File "/usr/bin/command-not-found", line 15
        print(file=sys.stderr)
                  ^
    SyntaxError: invalid syntax
    which didn't occur with my last Tumbleweed install. This happens whenever I type in a command that is not found. Is this is a known bug that is on its way out (thanks to someone swatting it) or is this something I need to file a bug report on?

    Thanks for your time,
    Brenton
    Brenton Horne: Linux enthusiast and writer of ​The Hornery.
    Seven favourite distros
    : Arch, Fedora, Gentoo, openSUSE Tumbleweed and Void.

  2. #2
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    12,019
    Blog Entries
    2

    Default Re: Bizarre python error when command isn't found

    If your python script is publicly available or you don't mind posting, it should be posted for others to inspect.
    And, as per the error,, line 15 should be inspected.

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  3. #3

    Default Re: Bizarre python error when command isn't found

    Your python version setup is borked. Well, incomplete, at least. The command-not-found script is written for python3. The error shows that your system is trying to run it with python2. Check the symlink /usr/bin/python3, it should point to /usr/bin/python3.6. If it does not, fix the symlink. If the target is not there, (re-)install python3-base via zypper.

    Code:
    $ head -n 1 /usr/bin/command-not-found
    #!/usr/bin/python3
    $ which python3
    /usr/bin/python3
    $ file /usr/bin/python3
    /usr/bin/python3: symbolic link to python3.6
    $ rpm -q --whatprovides /usr/bin/python3.6
    python3-base-3.6.5-3.3.x86_64
    
    # trigger error by forcing cnf to python2
    $ python2 /usr/bin/command-not-found
      File "/usr/bin/command-not-found", line 15
        print(file=sys.stderr)
                  ^
    SyntaxError: invalid syntax

  4. #4
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,431
    Blog Entries
    14

    Default Re: Bizarre python error when command isn't found

    Quote Originally Posted by tsu2 View Post
    If your python script is publicly available or you don't mind posting, it should be posted for others to inspect.
    And, as per the error,, line 15 should be inspected.

    TSU
    This is not about the OP's own script, but about the /usr/bin/command-not-found script.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  5. #5
    Join Date
    Sep 2018
    Location
    Osnabrüvk
    Posts
    7

    Default Re: Bizarre python error when command isn't found

    I am having the same problem:

    Code:
    head -n 1 /usr/bin/command-not-found
    #!/usr/bin/python3
    
    
    /usr/bin/python3: symbolic link to python3.6
    
    echo $SHELL
    /bin/zsh
    
    which python    
    /usr/bin/python
    
    which python3
    /usr/bin/python3
    
    LSB Version:    core-2.0-noarch:core-3.2-noarch:core-4.0-noarch:core-2.0-x86_64:core-3.2-x86_64:core-4.0-x86_64:desktop-4.0-amd64:desktop-4.0-noarch:graphics-2.0-amd64:graphics-2.0-noarch:graphics-3.2-amd64:graphics-3.2-noarch:graphics-4.0-amd64:graphics-4.0-noarch

  6. #6
    Join Date
    Jun 2008
    Location
    Rural Australia
    Posts
    289

    Default Re: Bizarre python error when command isn't found

    Similar problem using openSUSE Leap 15.0 GNOME Version 3.26.2

    .

  7. #7

    Default Re: Bizarre python error when command isn't found

    Perhaps this is a problem with the zsh shell in Tumbleweed? I can't reproduce the error in Bash, only in zsh:

    Code:
     code
    % echo $0                                                                                                                ckglxe95@localhost
    zsh
     code
    % fdsafdsa                                                                                                               ckglxe95@localhost
      File "/usr/bin/command-not-found", line 15
        print(file=sys.stderr)
                  ^
    SyntaxError: invalid syntax
     code
    % bash                                                                                                                   ckglxe95@localhost
    ckglxe95@localhost:~/code> echo $0
    bash
    ckglxe95@localhost:~/code> dfasdfas
    If 'dfasdfas' is not a typo you can use command-not-found to lookup the package that contains it, like this:
        cnf dfasdfas
    ckglxe95@localhost:~/code>
    Maybe this will help?

    Cheers

  8. #8
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,431
    Blog Entries
    14

    Default Re: Bizarre python error when command isn't found

    Quote Originally Posted by christopolise View Post
    Perhaps this is a problem with the zsh shell in Tumbleweed? I can't reproduce the error in Bash, only in zsh:

    Code:
     code
    % echo $0                                                                                                                ckglxe95@localhost
    zsh
     code
    % fdsafdsa                                                                                                               ckglxe95@localhost
      File "/usr/bin/command-not-found", line 15
        print(file=sys.stderr)
                  ^
    SyntaxError: invalid syntax
     code
    % bash                                                                                                                   ckglxe95@localhost
    ckglxe95@localhost:~/code> echo $0
    bash
    ckglxe95@localhost:~/code> dfasdfas
    If 'dfasdfas' is not a typo you can use command-not-found to lookup the package that contains it, like this:
        cnf dfasdfas
    ckglxe95@localhost:~/code>
    Maybe this will help?

    Cheers
    Hi welcome, thanks for stepping in. Can't reproduce in bash either. If this is the culprit, the OP definitely should have told us, bash is the default on openSUSE
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  9. #9

    Default Re: Bizarre python error when command isn't found

    It turns out that this is a result of the zsh/bash handler for the command-not-found program in Tumbleweed that is run with /usr/bin/python even though the script denotes it needs to use python3. (This leaves discrepancy between the system using python2 or python3, depending on what is default). This was fixed in an update, so for anyone having issues with this still, the best course of action is to
    Code:
    sudo zypper dup
    .

    Cheers

    Source: https://github.com/openSUSE/scout/pull/14

Tags for this Thread

Posting Permissions

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