Python module issues

I am running Windows 7 and I can import the built-in modules, but when I save my own script and try to import it in IDLE, I get an error message saying that the module does not exist.

I am using the Python text editor, which can be found by clicking File and New Window from the Python shell. I save it as a .py file in the Module folder that I created in the Python directory. However, whenever I type import module_name in IDLE, it says that the module does not exist.

What am I doing wrong or not doing? I tried importing module_name, import module_name.py, python module_name, python module_name.py

+3
source share
5 answers

Python uses the PYTHONPATH environment variable to determine the list of folders to look at when importing modules. Most likely your folder is not PYTHONPATH

+4
source

Try adding the path to the sys.path variable path:

import sys

sys.path.append(pathToModule)

+1
source

- :

from Module import *

Module - .

0

? , :

  • lib\sitepackages python ex: myModules
  • python init.py . . , .
  • ex: myGamesModule.py

( python) :

myModules myGamesModule myModules myGamesModule myGmMod

, .. ex myGmMod.Player()

, , , .

0

init.py . python,

__init__.py

stackoverflow . Thats 2 init

0

Source: https://habr.com/ru/post/1759785/


All Articles