0

When I try to import a module named my_module.py into the module i am working on named LEARNING PYTHON.py, I get an error message saying:

Traceback (most recent call last):
  File "/var/folders/tn/g0fq2j9d1hs6gss6db_4czwm0000gn/T/atom_script_tempfiles/2021710-52462-1bl6rr4.wrni", line 16, in <module>
    import my_module
ModuleNotFoundError: No module named 'my_module'

I am running the latest version of python and pip on my Mac and as far as i know, both modules are in the same directory. For my_module.py and LEARNING PYTHON.py, when I print the directory using:

import os

print(os.getcwd())

the following is displayed for both modules:

/Users/dylanneal/Documents

Can someone tell me what I am doing wrong and how I can import my_module in my LEARNING PYTHON.py file?

martineau
  • 119,623
  • 25
  • 170
  • 301
dneal80
  • 11
  • 1
  • Hello, welcome to stack overflow. Can we get the contents of the two files? – Rafael Barros Aug 10 '21 at 18:16
  • What matters is whether `my_module.py` and `LEARNING PYTHON.py` in the same folder, not what the the cwd (current working directory) is. – martineau Aug 10 '21 at 19:10
  • You'll probably want to check whether your module file is in `sys.path`, via: `import sys; print(sys.path)`. If the directory containing the module is not in sys.path, it will not be imported – TC Arlen Aug 10 '21 at 19:19

0 Answers0