0% found this document useful (0 votes)
45 views

SDS Cheatsheet For Python Errors

This document discusses common Python errors that may occur when installing or using Python. It describes 5 common errors: 1) "python setup.py egg_info" failed with error code 1, which is usually due to an incompatible package; 2) "module not found" error due to an incorrect PYTHONPATH; 3) "fatal Python error: py_initialize: unable to load the file system codec" due to running multiple Python versions; 4) Python import error due to a missing module or function; and 5) "segmentation fault (core dumped)" error typically caused by a crashed Python interpreter or invalid C module code. For each error, it provides the potential causes and solutions to resolve the issue.

Uploaded by

MD HUSSAIN MIRJI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

SDS Cheatsheet For Python Errors

This document discusses common Python errors that may occur when installing or using Python. It describes 5 common errors: 1) "python setup.py egg_info" failed with error code 1, which is usually due to an incompatible package; 2) "module not found" error due to an incorrect PYTHONPATH; 3) "fatal Python error: py_initialize: unable to load the file system codec" due to running multiple Python versions; 4) Python import error due to a missing module or function; and 5) "segmentation fault (core dumped)" error typically caused by a crashed Python interpreter or invalid C module code. For each error, it provides the potential causes and solutions to resolve the issue.

Uploaded by

MD HUSSAIN MIRJI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

MOST COMMON

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.

HOW ERRORS MAY OCCUR WHEN INSTALLING PYTHON

The majority of operating systems include a Python interpreter, that is,


except for Windows. This means it is normal for developers to run into
more problems than they would with other systems. Typically, you
would find a platform-endorsed package manager with an operating
system. This allows developers to find the required tools they need,
which have been customized and tested for their system.

The first thing you will have to do is to download an installer. For


those who are just starting out, this is probably going to be a bigger
problem than for developers who have more experience. Python aims
to ensure backward compatibility within versions, but this is not the
case with Python 2.x and Python 3.x. Before addressing any other
common issues, ensure you have the most up to date version of
Python by entering 'python' into a command line window.
ERROR #1: COMMAND "PYTHON SETUP.PY EGG_INFO"
FAILED WITH ERROR CODE 1

PROBLEM

When error code 1 appears, it is because the operation is not permitted.


It is frequently due to trying to run a package that isn't compatible
with an older version of Python.

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:

Type 'pip install –upgrade setuptools' in the Python console

Check to see if the module ez_setup is there

Type 'pip install unroll'

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)

Double click on the System icon

Select Advanced

Click the Environmental Variables button

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

it is time to clean up your workspace a little. Most commonly, this is


because you have both Python 2 and Python 3 running. Uninstall both
and then reinstall one or the other. There was talk of a possible bug
which has now been resolved. Another solution is to try a_dd Python in
your environment variables we saw previously.

ERROR #4: PYTHON IMPORT ERROR

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.

ERROR #5: SEGMENTATION FAULT (CORE DUMPED) ERROR

PROBLEM

It is more than likely that the Python interpreter has crashed, and there
might be a couple of reasons for this.

SOLUTION

As always with Python, the first thing is to double-check your Python


installations and then check your third-party extension for those
that are written in C modules. When a C module crashes, causing a
segmented fault it is because you are doing something invalid. It is also
worth double-checking to see if you are running with too much data,
and your RAM is full. Finally, you might want to try identifying the line
or library that is causing the problem. Try one or both of the solutions
below:

faulthandler.enable()
/insert bad code/

$ python3 -q -x faulthandler
>>>///insert bad code

You might also like