SDS Cheatsheet For Python Errors
SDS Cheatsheet For Python Errors
PYTHON ERRORS
IDENTIFYING AND RESOLVING SOME OF THE MOST
COMMON PYTHON ERRORS
By now, you are probably fully aware of the benefits of using Python,
and you might already have it up and running. Like others, you may
have started to come across some of the typical errors that occur
when installing Python.
PROBLEM
SOLUTION
It goes back to checking that you have the correct package installer or
PIP. To see what version of PIP is in your system, you need to type 'pip
-version' in your Python console. Following this, you need to ensure
that the setuptools and wheel are all up to date by carrying out
these steps:
This will upgrade the setuptools and resolve the issue. If not, you can
try typing an alternative code, 'easy_install -U setuptools'.
ERROR #2: MODULE NOT FOUND
PROBLEM
Modules in Python allow you to break down code into multiple files,
maintaining the readability of a codebase. This error means that
Python is unable to successfully import a module, normally because
the PYTHONPATH, which tells Python where to find modules, is
incorrect.
SOLUTION
You will need to set the Path for Python. These instructions allow you to
permanently set the Path so that you don't have to do it every time you
open a command window.
Select your control panel (if you have the option in the left-hand
column, change to classic view)
Select Advanced
Scroll down until you see the Path; variable and click on it
The final step takes great care! Use your right arrow to move along to
the end of the folder names. Be careful not to delete anything or
add any spaces. Type ;C:\Python24 and then close all of your windows.
Restart your computer, and you will find that PYTHONPATH is already
known.
ERROR #3: FATAL PYTHON ERROR: PY_INITIALIZE:
UNABLE TO LOAD THE FILE SYSTEM CODEC
PROBLEM
When this error popups up, you may not be able to perform any
coding, and it is usually down to running various versions of Python
at the same time.
SOLUTION
PROBLEM
One of the two issues could be occurring. It could be that the module
is not found, so the first step is to follow the solution in Error #2. Or, it
could be that a specified function can't be found.
SOLUTION
You want to make the most of all of the functions that each Python
module contains. Before pulling your hair out, check that all of your
Python files are correctly named '.py'. This way, the import statement
will be able to correctly recognize the file and ensure that it is prepared
to run with all of the associated functions.
PROBLEM
It is more than likely that the Python interpreter has crashed, and there
might be a couple of reasons for this.
SOLUTION
faulthandler.enable()
/insert bad code/
$ python3 -q -x faulthandler
>>>///insert bad code