Fatal Python error: Py_Initialize: Unable to get the locale encoding … SyntaxError: invalid syntax Aborted...












13















I installed anaconda by running the



bash Anaconda-2.2.0-Linux-x86_64.sh


command on my Ubuntu 14.04 system , which installed successfully, after which I was asked to export my new /home/username/anaconda/bin $PATH environment variable.



On doing so, I was able to use all of anaconda's features including the IDE's as well as use all conda based commands successfully.



The next time I booted up my system, every miss-typed command saw a



Fatal Python error: Py_Initialize: Unable to get the locale encoding
File "/usr/local/lib/python2.7/encodings/__init__.py", line 123
raise CodecRegistryError,
^
SyntaxError: invalid syntax
Aborted (core dumped)


error. (All commands except python to be specific)



On following a few stackexchange and askubuntu posts and also noticing that my $PYTHONPATH had been set to usr/local/lib/python2.7, I tried to



export PYTHONPATH=$PYTHONPATH:/home/username/anaconda/lib/python2.7


but it didn't help.



This had me go through a entire saga of package removals and reinstalls, and of course, a lot of updates and upgrades, to try and fix the problem by myself.



conda info -a returns:



CIO_TEST: <not set>
CONDA_DEFAULT_ENV: <not set>
CONDA_ENVS_PATH: <not set>
LD_LIBRARY_PATH: <not set>
PATH: /home/username/anaconda/bin:/home/username/Scala-sbt/sbt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/bin:/usr/local/java/jdk1.8.0_20/bin
PYTHONHOME: <not set>
PYTHONPATH: /usr/local/lib/python2.7:/home/username/anaconda/bin/python


The command



which python


returns



/home/username/anaconda/bin/python


and



echo "$PATH"


returns



/home/username/anaconda/bin:/home/username/Scala-sbt/sbt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/bin:/usr/local/java/jdk1.8.0_20/bin


I know it's something to do with the way I set the path variables, specifically in the ~/.bashrc in which Anaconda automatically prepended my /home/username/anaconda/bin folder to the $PATH variable (This happened during a second installation of Anaconda after I removed it first).



I haven't modified any other environment variable in either ~/.profile or ~/.bashrc.





I added the export $PYTHONPATH line to my ~/.bashrc before restarting.



All of Anaconda's features work now, although the same Fatal Python error: Py_Initialize: Unable to get the locale encoding error keeps showing up instead of the usual unknown command error, for most mistyped commands.



I will keep looking into this and edit my answer (or refer to existing answers, if any) as soon as I find out why this happens.










share|improve this question





























    13















    I installed anaconda by running the



    bash Anaconda-2.2.0-Linux-x86_64.sh


    command on my Ubuntu 14.04 system , which installed successfully, after which I was asked to export my new /home/username/anaconda/bin $PATH environment variable.



    On doing so, I was able to use all of anaconda's features including the IDE's as well as use all conda based commands successfully.



    The next time I booted up my system, every miss-typed command saw a



    Fatal Python error: Py_Initialize: Unable to get the locale encoding
    File "/usr/local/lib/python2.7/encodings/__init__.py", line 123
    raise CodecRegistryError,
    ^
    SyntaxError: invalid syntax
    Aborted (core dumped)


    error. (All commands except python to be specific)



    On following a few stackexchange and askubuntu posts and also noticing that my $PYTHONPATH had been set to usr/local/lib/python2.7, I tried to



    export PYTHONPATH=$PYTHONPATH:/home/username/anaconda/lib/python2.7


    but it didn't help.



    This had me go through a entire saga of package removals and reinstalls, and of course, a lot of updates and upgrades, to try and fix the problem by myself.



    conda info -a returns:



    CIO_TEST: <not set>
    CONDA_DEFAULT_ENV: <not set>
    CONDA_ENVS_PATH: <not set>
    LD_LIBRARY_PATH: <not set>
    PATH: /home/username/anaconda/bin:/home/username/Scala-sbt/sbt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/bin:/usr/local/java/jdk1.8.0_20/bin
    PYTHONHOME: <not set>
    PYTHONPATH: /usr/local/lib/python2.7:/home/username/anaconda/bin/python


    The command



    which python


    returns



    /home/username/anaconda/bin/python


    and



    echo "$PATH"


    returns



    /home/username/anaconda/bin:/home/username/Scala-sbt/sbt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/bin:/usr/local/java/jdk1.8.0_20/bin


    I know it's something to do with the way I set the path variables, specifically in the ~/.bashrc in which Anaconda automatically prepended my /home/username/anaconda/bin folder to the $PATH variable (This happened during a second installation of Anaconda after I removed it first).



    I haven't modified any other environment variable in either ~/.profile or ~/.bashrc.





    I added the export $PYTHONPATH line to my ~/.bashrc before restarting.



    All of Anaconda's features work now, although the same Fatal Python error: Py_Initialize: Unable to get the locale encoding error keeps showing up instead of the usual unknown command error, for most mistyped commands.



    I will keep looking into this and edit my answer (or refer to existing answers, if any) as soon as I find out why this happens.










    share|improve this question



























      13












      13








      13


      4






      I installed anaconda by running the



      bash Anaconda-2.2.0-Linux-x86_64.sh


      command on my Ubuntu 14.04 system , which installed successfully, after which I was asked to export my new /home/username/anaconda/bin $PATH environment variable.



      On doing so, I was able to use all of anaconda's features including the IDE's as well as use all conda based commands successfully.



      The next time I booted up my system, every miss-typed command saw a



      Fatal Python error: Py_Initialize: Unable to get the locale encoding
      File "/usr/local/lib/python2.7/encodings/__init__.py", line 123
      raise CodecRegistryError,
      ^
      SyntaxError: invalid syntax
      Aborted (core dumped)


      error. (All commands except python to be specific)



      On following a few stackexchange and askubuntu posts and also noticing that my $PYTHONPATH had been set to usr/local/lib/python2.7, I tried to



      export PYTHONPATH=$PYTHONPATH:/home/username/anaconda/lib/python2.7


      but it didn't help.



      This had me go through a entire saga of package removals and reinstalls, and of course, a lot of updates and upgrades, to try and fix the problem by myself.



      conda info -a returns:



      CIO_TEST: <not set>
      CONDA_DEFAULT_ENV: <not set>
      CONDA_ENVS_PATH: <not set>
      LD_LIBRARY_PATH: <not set>
      PATH: /home/username/anaconda/bin:/home/username/Scala-sbt/sbt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/bin:/usr/local/java/jdk1.8.0_20/bin
      PYTHONHOME: <not set>
      PYTHONPATH: /usr/local/lib/python2.7:/home/username/anaconda/bin/python


      The command



      which python


      returns



      /home/username/anaconda/bin/python


      and



      echo "$PATH"


      returns



      /home/username/anaconda/bin:/home/username/Scala-sbt/sbt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/bin:/usr/local/java/jdk1.8.0_20/bin


      I know it's something to do with the way I set the path variables, specifically in the ~/.bashrc in which Anaconda automatically prepended my /home/username/anaconda/bin folder to the $PATH variable (This happened during a second installation of Anaconda after I removed it first).



      I haven't modified any other environment variable in either ~/.profile or ~/.bashrc.





      I added the export $PYTHONPATH line to my ~/.bashrc before restarting.



      All of Anaconda's features work now, although the same Fatal Python error: Py_Initialize: Unable to get the locale encoding error keeps showing up instead of the usual unknown command error, for most mistyped commands.



      I will keep looking into this and edit my answer (or refer to existing answers, if any) as soon as I find out why this happens.










      share|improve this question
















      I installed anaconda by running the



      bash Anaconda-2.2.0-Linux-x86_64.sh


      command on my Ubuntu 14.04 system , which installed successfully, after which I was asked to export my new /home/username/anaconda/bin $PATH environment variable.



      On doing so, I was able to use all of anaconda's features including the IDE's as well as use all conda based commands successfully.



      The next time I booted up my system, every miss-typed command saw a



      Fatal Python error: Py_Initialize: Unable to get the locale encoding
      File "/usr/local/lib/python2.7/encodings/__init__.py", line 123
      raise CodecRegistryError,
      ^
      SyntaxError: invalid syntax
      Aborted (core dumped)


      error. (All commands except python to be specific)



      On following a few stackexchange and askubuntu posts and also noticing that my $PYTHONPATH had been set to usr/local/lib/python2.7, I tried to



      export PYTHONPATH=$PYTHONPATH:/home/username/anaconda/lib/python2.7


      but it didn't help.



      This had me go through a entire saga of package removals and reinstalls, and of course, a lot of updates and upgrades, to try and fix the problem by myself.



      conda info -a returns:



      CIO_TEST: <not set>
      CONDA_DEFAULT_ENV: <not set>
      CONDA_ENVS_PATH: <not set>
      LD_LIBRARY_PATH: <not set>
      PATH: /home/username/anaconda/bin:/home/username/Scala-sbt/sbt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/bin:/usr/local/java/jdk1.8.0_20/bin
      PYTHONHOME: <not set>
      PYTHONPATH: /usr/local/lib/python2.7:/home/username/anaconda/bin/python


      The command



      which python


      returns



      /home/username/anaconda/bin/python


      and



      echo "$PATH"


      returns



      /home/username/anaconda/bin:/home/username/Scala-sbt/sbt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/username/bin:/usr/local/java/jdk1.8.0_20/bin


      I know it's something to do with the way I set the path variables, specifically in the ~/.bashrc in which Anaconda automatically prepended my /home/username/anaconda/bin folder to the $PATH variable (This happened during a second installation of Anaconda after I removed it first).



      I haven't modified any other environment variable in either ~/.profile or ~/.bashrc.





      I added the export $PYTHONPATH line to my ~/.bashrc before restarting.



      All of Anaconda's features work now, although the same Fatal Python error: Py_Initialize: Unable to get the locale encoding error keeps showing up instead of the usual unknown command error, for most mistyped commands.



      I will keep looking into this and edit my answer (or refer to existing answers, if any) as soon as I find out why this happens.







      14.04 python python-2.7 conda






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 6 '15 at 9:53









      karel

      60.4k13131155




      60.4k13131155










      asked Jun 23 '15 at 15:31









      samirzachsamirzach

      68115




      68115






















          4 Answers
          4






          active

          oldest

          votes


















          10














          I would recommend unsetting PYTHONPATH. It is generally not needed, and it causes things to break like this by making one Python load things from another Python (in this case, it looks like the system's Python 3 is trying to load something that was written for Python 2).






          share|improve this answer



















          • 3





            Sincere apologies for the late reply, sir. By unsetting the PYTHONPATH, do you mean manually setting it up on startup everytime? Anaconda runs Python 2.7.10 currently and I haven't installed Python 3, so why would this error show up? The reason why I'm asking is that Conda's info for user site dirs specifies the PYTHONPATH variable as PYTHONPATH: /home/usrnme/anaconda/lib/python2.7:/usr/local/lib/python2.7. If I am to remove the PYTHONPATH: /home/usrnme/anaconda.. line from my ~/.bashrc , the error would still persist, and also none of Anaconda's features would work, until I set it again.

            – samirzach
            Jul 9 '15 at 11:10





















          3














          I have been having similar issues in the past couple days, so I traced it back to how bash handles "command not found". In Ubuntu 14.04 (and Linux Mint 17, which I uses the 14.04 scripts), /etc/bash.bashrc has the following function:



          if [ -x /usr/lib/command-not-found ]; then
          function command_not_found_handle {
          # check because c-n-f could've been removed in the meantime
          if [ -x /usr/lib/command-not-found ]; then
          /usr/bin/python /usr/lib/command-not-found -- $1
          return $?
          else
          return 127
          fi
          }
          fi


          However, /usr/lib/command-not-found has been rewritten for Python 3. It handles the /etc/bash.bashrc command with:



          if sys.version < '3':                                                       
          # We might end up being executed with Python 2 due to an old
          # /etc/bash.bashrc.
          import os
          if "COMMAND_NOT_FOUND_FORCE_PYTHON2" not in os.environ:
          os.execvp("python3", [sys.argv[0]] + sys.argv)


          This calls "python3" from the path rather than giving the direct path. To correct this, line 22 of /usr/lib/command-not-found should be changed from



          os.execvp("python3", [sys.argv[0]] + sys.argv)


          to



          os.execv("/usr/bin/python3", [sys.argv[0]] + sys.argv)


          This appears to be a bug with Ubuntu rather than Anaconda. I will check to see if it appears in later distributions.






          share|improve this answer































            1














            After having installed python3 in the standard locations and realizing I needed sudo to use it, I installed locally using this in my home directory:



            python3 -m venv env_py3
            source env_py3/bin/activate


            But had more errors. Simply unsetting PYTHONPATH on AWS's Amazon Linux instance worked just great for me.






            share|improve this answer

































              -2














              I had a similar issue on windows - I deleted the PYTHONHOME system variable.
              I will try to translate the solution into English. My Computer > Properties > Advanced System Settings > Environment Variables, look for the variable PYTHONHOME and delete it.






              share|improve this answer

























                Your Answer








                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "89"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f640010%2ffatal-python-error-py-initialize-unable-to-get-the-locale-encoding-syntaxe%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                10














                I would recommend unsetting PYTHONPATH. It is generally not needed, and it causes things to break like this by making one Python load things from another Python (in this case, it looks like the system's Python 3 is trying to load something that was written for Python 2).






                share|improve this answer



















                • 3





                  Sincere apologies for the late reply, sir. By unsetting the PYTHONPATH, do you mean manually setting it up on startup everytime? Anaconda runs Python 2.7.10 currently and I haven't installed Python 3, so why would this error show up? The reason why I'm asking is that Conda's info for user site dirs specifies the PYTHONPATH variable as PYTHONPATH: /home/usrnme/anaconda/lib/python2.7:/usr/local/lib/python2.7. If I am to remove the PYTHONPATH: /home/usrnme/anaconda.. line from my ~/.bashrc , the error would still persist, and also none of Anaconda's features would work, until I set it again.

                  – samirzach
                  Jul 9 '15 at 11:10


















                10














                I would recommend unsetting PYTHONPATH. It is generally not needed, and it causes things to break like this by making one Python load things from another Python (in this case, it looks like the system's Python 3 is trying to load something that was written for Python 2).






                share|improve this answer



















                • 3





                  Sincere apologies for the late reply, sir. By unsetting the PYTHONPATH, do you mean manually setting it up on startup everytime? Anaconda runs Python 2.7.10 currently and I haven't installed Python 3, so why would this error show up? The reason why I'm asking is that Conda's info for user site dirs specifies the PYTHONPATH variable as PYTHONPATH: /home/usrnme/anaconda/lib/python2.7:/usr/local/lib/python2.7. If I am to remove the PYTHONPATH: /home/usrnme/anaconda.. line from my ~/.bashrc , the error would still persist, and also none of Anaconda's features would work, until I set it again.

                  – samirzach
                  Jul 9 '15 at 11:10
















                10












                10








                10







                I would recommend unsetting PYTHONPATH. It is generally not needed, and it causes things to break like this by making one Python load things from another Python (in this case, it looks like the system's Python 3 is trying to load something that was written for Python 2).






                share|improve this answer













                I would recommend unsetting PYTHONPATH. It is generally not needed, and it causes things to break like this by making one Python load things from another Python (in this case, it looks like the system's Python 3 is trying to load something that was written for Python 2).







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jun 24 '15 at 16:40









                asmeurerasmeurer

                35027




                35027








                • 3





                  Sincere apologies for the late reply, sir. By unsetting the PYTHONPATH, do you mean manually setting it up on startup everytime? Anaconda runs Python 2.7.10 currently and I haven't installed Python 3, so why would this error show up? The reason why I'm asking is that Conda's info for user site dirs specifies the PYTHONPATH variable as PYTHONPATH: /home/usrnme/anaconda/lib/python2.7:/usr/local/lib/python2.7. If I am to remove the PYTHONPATH: /home/usrnme/anaconda.. line from my ~/.bashrc , the error would still persist, and also none of Anaconda's features would work, until I set it again.

                  – samirzach
                  Jul 9 '15 at 11:10
















                • 3





                  Sincere apologies for the late reply, sir. By unsetting the PYTHONPATH, do you mean manually setting it up on startup everytime? Anaconda runs Python 2.7.10 currently and I haven't installed Python 3, so why would this error show up? The reason why I'm asking is that Conda's info for user site dirs specifies the PYTHONPATH variable as PYTHONPATH: /home/usrnme/anaconda/lib/python2.7:/usr/local/lib/python2.7. If I am to remove the PYTHONPATH: /home/usrnme/anaconda.. line from my ~/.bashrc , the error would still persist, and also none of Anaconda's features would work, until I set it again.

                  – samirzach
                  Jul 9 '15 at 11:10










                3




                3





                Sincere apologies for the late reply, sir. By unsetting the PYTHONPATH, do you mean manually setting it up on startup everytime? Anaconda runs Python 2.7.10 currently and I haven't installed Python 3, so why would this error show up? The reason why I'm asking is that Conda's info for user site dirs specifies the PYTHONPATH variable as PYTHONPATH: /home/usrnme/anaconda/lib/python2.7:/usr/local/lib/python2.7. If I am to remove the PYTHONPATH: /home/usrnme/anaconda.. line from my ~/.bashrc , the error would still persist, and also none of Anaconda's features would work, until I set it again.

                – samirzach
                Jul 9 '15 at 11:10







                Sincere apologies for the late reply, sir. By unsetting the PYTHONPATH, do you mean manually setting it up on startup everytime? Anaconda runs Python 2.7.10 currently and I haven't installed Python 3, so why would this error show up? The reason why I'm asking is that Conda's info for user site dirs specifies the PYTHONPATH variable as PYTHONPATH: /home/usrnme/anaconda/lib/python2.7:/usr/local/lib/python2.7. If I am to remove the PYTHONPATH: /home/usrnme/anaconda.. line from my ~/.bashrc , the error would still persist, and also none of Anaconda's features would work, until I set it again.

                – samirzach
                Jul 9 '15 at 11:10















                3














                I have been having similar issues in the past couple days, so I traced it back to how bash handles "command not found". In Ubuntu 14.04 (and Linux Mint 17, which I uses the 14.04 scripts), /etc/bash.bashrc has the following function:



                if [ -x /usr/lib/command-not-found ]; then
                function command_not_found_handle {
                # check because c-n-f could've been removed in the meantime
                if [ -x /usr/lib/command-not-found ]; then
                /usr/bin/python /usr/lib/command-not-found -- $1
                return $?
                else
                return 127
                fi
                }
                fi


                However, /usr/lib/command-not-found has been rewritten for Python 3. It handles the /etc/bash.bashrc command with:



                if sys.version < '3':                                                       
                # We might end up being executed with Python 2 due to an old
                # /etc/bash.bashrc.
                import os
                if "COMMAND_NOT_FOUND_FORCE_PYTHON2" not in os.environ:
                os.execvp("python3", [sys.argv[0]] + sys.argv)


                This calls "python3" from the path rather than giving the direct path. To correct this, line 22 of /usr/lib/command-not-found should be changed from



                os.execvp("python3", [sys.argv[0]] + sys.argv)


                to



                os.execv("/usr/bin/python3", [sys.argv[0]] + sys.argv)


                This appears to be a bug with Ubuntu rather than Anaconda. I will check to see if it appears in later distributions.






                share|improve this answer




























                  3














                  I have been having similar issues in the past couple days, so I traced it back to how bash handles "command not found". In Ubuntu 14.04 (and Linux Mint 17, which I uses the 14.04 scripts), /etc/bash.bashrc has the following function:



                  if [ -x /usr/lib/command-not-found ]; then
                  function command_not_found_handle {
                  # check because c-n-f could've been removed in the meantime
                  if [ -x /usr/lib/command-not-found ]; then
                  /usr/bin/python /usr/lib/command-not-found -- $1
                  return $?
                  else
                  return 127
                  fi
                  }
                  fi


                  However, /usr/lib/command-not-found has been rewritten for Python 3. It handles the /etc/bash.bashrc command with:



                  if sys.version < '3':                                                       
                  # We might end up being executed with Python 2 due to an old
                  # /etc/bash.bashrc.
                  import os
                  if "COMMAND_NOT_FOUND_FORCE_PYTHON2" not in os.environ:
                  os.execvp("python3", [sys.argv[0]] + sys.argv)


                  This calls "python3" from the path rather than giving the direct path. To correct this, line 22 of /usr/lib/command-not-found should be changed from



                  os.execvp("python3", [sys.argv[0]] + sys.argv)


                  to



                  os.execv("/usr/bin/python3", [sys.argv[0]] + sys.argv)


                  This appears to be a bug with Ubuntu rather than Anaconda. I will check to see if it appears in later distributions.






                  share|improve this answer


























                    3












                    3








                    3







                    I have been having similar issues in the past couple days, so I traced it back to how bash handles "command not found". In Ubuntu 14.04 (and Linux Mint 17, which I uses the 14.04 scripts), /etc/bash.bashrc has the following function:



                    if [ -x /usr/lib/command-not-found ]; then
                    function command_not_found_handle {
                    # check because c-n-f could've been removed in the meantime
                    if [ -x /usr/lib/command-not-found ]; then
                    /usr/bin/python /usr/lib/command-not-found -- $1
                    return $?
                    else
                    return 127
                    fi
                    }
                    fi


                    However, /usr/lib/command-not-found has been rewritten for Python 3. It handles the /etc/bash.bashrc command with:



                    if sys.version < '3':                                                       
                    # We might end up being executed with Python 2 due to an old
                    # /etc/bash.bashrc.
                    import os
                    if "COMMAND_NOT_FOUND_FORCE_PYTHON2" not in os.environ:
                    os.execvp("python3", [sys.argv[0]] + sys.argv)


                    This calls "python3" from the path rather than giving the direct path. To correct this, line 22 of /usr/lib/command-not-found should be changed from



                    os.execvp("python3", [sys.argv[0]] + sys.argv)


                    to



                    os.execv("/usr/bin/python3", [sys.argv[0]] + sys.argv)


                    This appears to be a bug with Ubuntu rather than Anaconda. I will check to see if it appears in later distributions.






                    share|improve this answer













                    I have been having similar issues in the past couple days, so I traced it back to how bash handles "command not found". In Ubuntu 14.04 (and Linux Mint 17, which I uses the 14.04 scripts), /etc/bash.bashrc has the following function:



                    if [ -x /usr/lib/command-not-found ]; then
                    function command_not_found_handle {
                    # check because c-n-f could've been removed in the meantime
                    if [ -x /usr/lib/command-not-found ]; then
                    /usr/bin/python /usr/lib/command-not-found -- $1
                    return $?
                    else
                    return 127
                    fi
                    }
                    fi


                    However, /usr/lib/command-not-found has been rewritten for Python 3. It handles the /etc/bash.bashrc command with:



                    if sys.version < '3':                                                       
                    # We might end up being executed with Python 2 due to an old
                    # /etc/bash.bashrc.
                    import os
                    if "COMMAND_NOT_FOUND_FORCE_PYTHON2" not in os.environ:
                    os.execvp("python3", [sys.argv[0]] + sys.argv)


                    This calls "python3" from the path rather than giving the direct path. To correct this, line 22 of /usr/lib/command-not-found should be changed from



                    os.execvp("python3", [sys.argv[0]] + sys.argv)


                    to



                    os.execv("/usr/bin/python3", [sys.argv[0]] + sys.argv)


                    This appears to be a bug with Ubuntu rather than Anaconda. I will check to see if it appears in later distributions.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered May 25 '16 at 15:37









                    rymacrymac

                    312




                    312























                        1














                        After having installed python3 in the standard locations and realizing I needed sudo to use it, I installed locally using this in my home directory:



                        python3 -m venv env_py3
                        source env_py3/bin/activate


                        But had more errors. Simply unsetting PYTHONPATH on AWS's Amazon Linux instance worked just great for me.






                        share|improve this answer






























                          1














                          After having installed python3 in the standard locations and realizing I needed sudo to use it, I installed locally using this in my home directory:



                          python3 -m venv env_py3
                          source env_py3/bin/activate


                          But had more errors. Simply unsetting PYTHONPATH on AWS's Amazon Linux instance worked just great for me.






                          share|improve this answer




























                            1












                            1








                            1







                            After having installed python3 in the standard locations and realizing I needed sudo to use it, I installed locally using this in my home directory:



                            python3 -m venv env_py3
                            source env_py3/bin/activate


                            But had more errors. Simply unsetting PYTHONPATH on AWS's Amazon Linux instance worked just great for me.






                            share|improve this answer















                            After having installed python3 in the standard locations and realizing I needed sudo to use it, I installed locally using this in my home directory:



                            python3 -m venv env_py3
                            source env_py3/bin/activate


                            But had more errors. Simply unsetting PYTHONPATH on AWS's Amazon Linux instance worked just great for me.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Feb 22 at 11:00









                            mature

                            2,1574931




                            2,1574931










                            answered Feb 22 at 9:19









                            RiggerRigger

                            111




                            111























                                -2














                                I had a similar issue on windows - I deleted the PYTHONHOME system variable.
                                I will try to translate the solution into English. My Computer > Properties > Advanced System Settings > Environment Variables, look for the variable PYTHONHOME and delete it.






                                share|improve this answer






























                                  -2














                                  I had a similar issue on windows - I deleted the PYTHONHOME system variable.
                                  I will try to translate the solution into English. My Computer > Properties > Advanced System Settings > Environment Variables, look for the variable PYTHONHOME and delete it.






                                  share|improve this answer




























                                    -2












                                    -2








                                    -2







                                    I had a similar issue on windows - I deleted the PYTHONHOME system variable.
                                    I will try to translate the solution into English. My Computer > Properties > Advanced System Settings > Environment Variables, look for the variable PYTHONHOME and delete it.






                                    share|improve this answer















                                    I had a similar issue on windows - I deleted the PYTHONHOME system variable.
                                    I will try to translate the solution into English. My Computer > Properties > Advanced System Settings > Environment Variables, look for the variable PYTHONHOME and delete it.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Feb 1 '18 at 21:54









                                    Kevin Bowen

                                    14.7k155970




                                    14.7k155970










                                    answered Feb 1 '18 at 20:25









                                    user790300user790300

                                    1




                                    1






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Ask Ubuntu!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f640010%2ffatal-python-error-py-initialize-unable-to-get-the-locale-encoding-syntaxe%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                                        Mangá

                                         ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕