In layman's terms, the Python interpreter cannot find the location of the sample.py file. We get such an output because the PYTHONPATH has not been set yet. ModuleNotFoundError: No module named 'sample' ![]() The script sample_script.py has the following content:įile "scripts/sample_script.py", line 1, in The module sample.py has the following content: So, with PYTHONPATH, users can import modules that have not been made installable yet. PYTHONPATH variable includes various directories as a string to be added to the sys.path directory list. It also handles the default search path for modules in Python. In simple terms, it is used by user-defined modules to set the path so that they can be directly imported into a Python program. So, the only reason to use PYTHONPATH variables is to maintain directories of custom Python libraries that are not installed in the site packages directory (the global default location). As these variables are not needed for Python to run, they are not set for most installations. Understanding the Pythonpath Environment Variable inĪn environment variable that lets you add additional directories where Python looks for packages and modules. It is available to all programs running in the same environment. PYTHONPATH is one such environment variable that is, it is a key-value pair stored in a computer's memory. ![]() Environment variables influence the behavior of Python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |