Python's not found

/bin/sh: python: command not found

I can’t run python because of this error

There are a few (very obvious) questions that need to be addressed here:

  • What computer OS are you using
  • How did you install Python (this is OS dependent)
  • If you downloaded Python, where did you download it from
  • What version of Python did you download/install

… that should do for now.

2 Likes

Try python3 instead.

I’m not sure what you means by try python3 because when I run a file, it just print out that rather than working

While it’s possible that someone will be able to understand your issue and offer some support, it’s very much more likely to happen, if you were far less vague and far more forthcoming.

1 Like

How do you run a file?

I think (guess) that what he means is he has the .py file and the 1st line is:

#!/bin/python

or something like that.

Hoang,

I think they mean to:

  • start a term/ssh command then
  • run:
python3 -V

then see (and post) what that outputs

vs code

Click the debug button on the top

clear sys.modules

destroy _frozen_importlib

destroy codecs

destroy encodings.aliases

destroy encodings.utf_8

destroy _codecs

destroy re

destroy abc

destroy os

destroy _sre

destroy _abc

destroy _collections_abc

destroy sys

destroy _operator

destroy _weakref

destroy _collections

destroy collections.abc

destroy builtins

destroy itertools

destroy _functools

destroy _thread

clear sys.audit hooks

hoangnguyen@Hoangs-Laptop ~ % clear

hoangnguyen@Hoangs-Laptop ~ % python3 -v
import _frozen_importlib # frozen
import _imp # builtin
import ‘_thread’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘_warnings’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘_weakref’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘_io’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘marshal’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘posix’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘_frozen_importlib_external’ # <class ‘_frozen_importlib.FrozenImporter’>

installing zipimport hook

import ‘time’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘zipimport’ # <class ‘_frozen_importlib.FrozenImporter’>

installed zipimport hook

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/encodings/pycache/init.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/encodings/init.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/encodings/pycache/init.cpython-312.pyc’

import ‘_codecs’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘codecs’ # <class ‘_frozen_importlib.FrozenImporter’>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/encodings/pycache/aliases.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/encodings/aliases.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/encodings/pycache/aliases.cpython-312.pyc’

import ‘encodings.aliases’ # <_frozen_importlib_external.SourceFileLoader object at 0x102ffcb30>
import ‘encodings’ # <_frozen_importlib_external.SourceFileLoader object at 0x102fd7fe0>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/encodings/pycache/utf_8.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/encodings/utf_8.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/encodings/pycache/utf_8.cpython-312.pyc’

import ‘encodings.utf_8’ # <_frozen_importlib_external.SourceFileLoader object at 0x102fff0b0>
import ‘_signal’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘_abc’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘abc’ # <class ‘_frozen_importlib.FrozenImporter’>
import ‘io’ # <class ‘_frozen_importlib.FrozenImporter’>
import ‘_stat’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘stat’ # <class ‘_frozen_importlib.FrozenImporter’>
import ‘_collections_abc’ # <class ‘_frozen_importlib.FrozenImporter’>
import ‘genericpath’ # <class ‘_frozen_importlib.FrozenImporter’>
import ‘posixpath’ # <class ‘_frozen_importlib.FrozenImporter’>
import ‘os’ # <class ‘_frozen_importlib.FrozenImporter’>
import ‘_sitebuiltins’ # <class ‘_frozen_importlib.FrozenImporter’>
Processing user site-packages
Processing global site-packages
Adding directory: ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages’
import ‘site’ # <class ‘_frozen_importlib.FrozenImporter’>

extension module ‘readline’ loaded from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload/readline.cpython-312-darwin.so’

extension module ‘readline’ executed from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload/readline.cpython-312-darwin.so’

import ‘readline’ # <_frozen_importlib_external.ExtensionFileLoader object at 0x1030155e0>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/rlcompleter.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/rlcompleter.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/rlcompleter.cpython-312.pyc’

import ‘atexit’ # <class ‘_frozen_importlib.BuiltinImporter’>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/inspect.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/inspect.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/inspect.cpython-312.pyc’

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/ast.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ast.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/ast.cpython-312.pyc’

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/pycache/init.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/init.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/pycache/init.cpython-312.pyc’

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/enum.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/enum.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/enum.cpython-312.pyc’

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/types.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/types.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/types.cpython-312.pyc’

import ‘types’ # <_frozen_importlib_external.SourceFileLoader object at 0x103087d70>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/operator.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/operator.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/operator.cpython-312.pyc’

import ‘_operator’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘operator’ # <_frozen_importlib_external.SourceFileLoader object at 0x103087fe0>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/functools.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/functools.cpython-312.pyc’

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/collections/pycache/init.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/collections/init.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/collections/pycache/init.cpython-312.pyc’

import ‘itertools’ # <class ‘_frozen_importlib.BuiltinImporter’>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/keyword.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/keyword.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/keyword.cpython-312.pyc’

import ‘keyword’ # <_frozen_importlib_external.SourceFileLoader object at 0x1030b7590>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/reprlib.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/reprlib.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/reprlib.cpython-312.pyc’

import ‘reprlib’ # <_frozen_importlib_external.SourceFileLoader object at 0x1030b78c0>
import ‘_collections’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘collections’ # <_frozen_importlib_external.SourceFileLoader object at 0x10309f920>
import ‘_functools’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘functools’ # <_frozen_importlib_external.SourceFileLoader object at 0x10309d0a0>
import ‘enum’ # <_frozen_importlib_external.SourceFileLoader object at 0x1030851f0>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/pycache/_compiler.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/_compiler.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/pycache/_compiler.cpython-312.pyc’

import ‘_sre’ # <class ‘_frozen_importlib.BuiltinImporter’>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/pycache/_parser.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/_parser.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/pycache/_parser.cpython-312.pyc’

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/pycache/_constants.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/_constants.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/pycache/_constants.cpython-312.pyc’

import ‘re._constants’ # <_frozen_importlib_external.SourceFileLoader object at 0x1030e70e0>
import ‘re._parser’ # <_frozen_importlib_external.SourceFileLoader object at 0x1030e5d30>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/pycache/_casefix.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/_casefix.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/pycache/_casefix.cpython-312.pyc’

import ‘re._casefix’ # <_frozen_importlib_external.SourceFileLoader object at 0x10309dfd0>
import ‘re._compiler’ # <_frozen_importlib_external.SourceFileLoader object at 0x1030e4470>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/copyreg.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/copyreg.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/copyreg.cpython-312.pyc’

import ‘copyreg’ # <_frozen_importlib_external.SourceFileLoader object at 0x1030e7fb0>
import ‘re’ # <_frozen_importlib_external.SourceFileLoader object at 0x103084530>
import ‘_ast’ # <class ‘_frozen_importlib.BuiltinImporter’>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/contextlib.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/contextlib.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/contextlib.cpython-312.pyc’

import ‘contextlib’ # <_frozen_importlib_external.SourceFileLoader object at 0x10311bf50>
import ‘ast’ # <_frozen_importlib_external.SourceFileLoader object at 0x103056d20>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/dis.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/dis.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/dis.cpython-312.pyc’

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/opcode.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/opcode.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/opcode.cpython-312.pyc’

extension module ‘_opcode’ loaded from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload/_opcode.cpython-312-darwin.so’

extension module ‘_opcode’ executed from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload/_opcode.cpython-312-darwin.so’

import ‘_opcode’ # <_frozen_importlib_external.ExtensionFileLoader object at 0x1031b05f0>
import ‘opcode’ # <_frozen_importlib_external.SourceFileLoader object at 0x103183980>
import ‘dis’ # <_frozen_importlib_external.SourceFileLoader object at 0x103057dd0>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/collections/pycache/abc.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/collections/abc.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/collections/pycache/abc.cpython-312.pyc’

import ‘collections.abc’ # <_frozen_importlib_external.SourceFileLoader object at 0x1031b1e20>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/pycache/init.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/init.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/pycache/init.cpython-312.pyc’

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/warnings.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/warnings.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/warnings.cpython-312.pyc’

import ‘warnings’ # <_frozen_importlib_external.SourceFileLoader object at 0x1031b18e0>
import ‘importlib’ # <_frozen_importlib_external.SourceFileLoader object at 0x1031b1c70>
import ‘importlib.machinery’ # <class ‘_frozen_importlib.FrozenImporter’>

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/linecache.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/linecache.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/linecache.cpython-312.pyc’

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/tokenize.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tokenize.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/tokenize.cpython-312.pyc’

/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/token.cpython-312.pyc matches /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/token.py

code object from ‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/pycache/token.cpython-312.pyc’

import ‘token’ # <_frozen_importlib_external.SourceFileLoader object at 0x1031d1250>
import ‘_tokenize’ # <class ‘_frozen_importlib.BuiltinImporter’>
import ‘tokenize’ # <_frozen_importlib_external.SourceFileLoader object at 0x1031b3e00>
import ‘linecache’ # <_frozen_importlib_external.SourceFileLoader object at 0x1031b3bc0>
import ‘inspect’ # <_frozen_importlib_external.SourceFileLoader object at 0x103015ca0>
import ‘rlcompleter’ # <_frozen_importlib_external.SourceFileLoader object at 0x103015730>
Python 3.12.1 (v3.12.1:2305ca5144, Dec 7 2023, 17:23:38) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

Hi,

From one of the lines you posted:

so that means your path includes the directory where the python3 binary/executable is located.

Now you need to find out where (the path) that is, so try puttying into the system and type:

which python3

The output from that command will show you the path to the python3 binary.

On one my machines, I get:

-bash-4.4$ which python3
/usr/bin/python3

so the path to the python3 is:

/usr/bin/python3

So now, edit one of your .py files and make the very 1st line:

#!/usr/bin/python3

Save the .py file, then you need to make the .py file executable, so type:

chmod a+x xxxx.py (where xxxx.py is your .py file)

After that, to run the python .py file, just type:

./xxxx.py (where xxxx.py is your .py file)

I THINK that that was what you were asking about?

/Library/Frameworks/Python.framework/Versions/3.12/bin/python3