Dnaiel
Dnaiel

Reputation: 7832

module import in windows

I am new to windows and I am working on setting up code and modules with visual studio.

I have the following folder structure for my code:

myModule
  __init__.py
  mymodule.py
myScript
  myscript.py

In myscript.py I have the following command:

from myModule import *

In visual studio this command works, but when I run the script command line I get the following error:

ModuleNotFoundError: No Module named myModule

Is there a quick trick in windows to do the job w/o having to install myModule as a package?

Any of the usual tricks that work in linux don't seem to work in windows. I.e.,

sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'myModule'))

or,

import ..myModule

Upvotes: 0

Views: 84

Answers (1)

RobertB
RobertB

Reputation: 1929

The path should have entries that point to the module. Your path entry is pointing inside the module.

What you had:

os.path.join(os.path.dirname(__file__), r"..", 'myModule')

Instead, you want to point to the directory containing myModule, which would be:

os.path.join(os.path.dirname(__file__), r"..")

Upvotes: 1

Related Questions