Saturday 12 December 2020

ModuleNotFoundError is raised when I try to import a module that is in my current working directory

I have Python installed on a network drive. I used the pushd command to go into my project's folder on the same network drive. I open python in that folder. I try to import a module which is in that folder. A ModuleNotFoundError is raised:

C:\users\myprofile>pushd \\network\drive\my\directory\my-program
U:\my\directory\my-program>"\\network\drive\Python\installations\python-3.8.3rc1-embed-win32\python.exe"
Python 3.8.3rc1 (tags/v3.8.3rc1:802eb67, Apr 29 2020, 21:21:45) [MSC v.1925 32 bit (Intel)] on win32
>>> import os
>>> import dict2obj
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'dict2obj'
>>> os.listdir()
['config.yml', 'dict2obj.py', 'files', 'main.py', 'start.bat', 'templates', '__pycache__']

I utilized os.listdir() to see what files are in my current working directory.

I don't see how this problem has to do with being on a network drive.

Update: Problem persists even after I do the following:

import os
os.chdir("\\\\network\\drive\\my\\directory\\my-program")

Edit: Please do NOT mark this as a duplicate of Python can't find module in the same folder. It is NOT. In that article, OP didn't confirm that their working directory was correct, unlike this issue.

Edit: Here is everything in sys.path:

\\network\drive\Python\installations\python-3.8.3rc1-embed-win32\python38.zip
\\network\drive\Python\modules\site-packages
\\network\drive\Python\modules\custom-modules
\\network\drive\Python\installations\python-3.8.3rc1-embed-win32


from ModuleNotFoundError is raised when I try to import a module that is in my current working directory

No comments:

Post a Comment