EnvironmentError Exception in Python Last Updated : 21 Aug, 2020 Comments Improve Suggest changes Like Article Like Report EnvironmentError is the base class for errors that come from outside of Python (the operating system, file system, etc.). It is the parent class for IOError and OSError exceptions. exception IOError - It is raised when an I/O operation (when a method of a file object ) fails. e.g "File not found" or "Disk Full".exception OSError - It is raised when a function returns a system-related error. Any example of an IOError or OSError should also be an example of Environment Error. Example 1 : Python3 # importing the module import sys try: # an invalid path file = open("GeeksforGeeks.txt", 'r') except Exception as e: print(e) print(sys.exc_info()[0]) Output[Errno 2] No such file or directory: 'GeeksforGeeks.txt' <class 'FileNotFoundError'> Example 2 : Python3 # importing the module import os import sys try: for i in range(7): print(i) print(os.ttyname(i)) except Exception as e: print(e) print(sys.exc_info()[0]) Output0 [Errno 25] Inappropriate ioctl for device <class 'OSError'> Example 3 : Python3 # importing the module import sys import os try: # an invalid path os.rmdir('GEEKS') except Exception as e: print(e) print(sys.exc_info()[0]) Output[Errno 2] No such file or directory: 'GEEKS' <class 'FileNotFoundError'> Comment More infoAdvertise with us Next Article Company-wise Practice Problems R rohanchopra96 Follow Improve Article Tags : Python Python-exceptions Practice Tags : python Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like