0

I have a folder as follows:

Folder structure

The message.py file has a class Message that I would like to import and similarly segments.py file has a class Segment that I would like to import.

When I do:

from pydifact.message import Message
from pydifact.segments import Segment

I get the following error:

Traceback (most recent call last):

  File "<ipython-input-1-cc598c8ad3ca>", line 1, in <module>
    from pydifact.message import Message

ModuleNotFoundError: No module named 'pydifact.message'

But when I add:

import sys
sys.path.insert(0, r"C:\Users\Desktop\automatic-mscons-invoice-generator\edilite\pydifact")

from pydifact.message import Message
from pydifact.segments import Segment

it works fine.

Is there a way I can do the imports directly without having to add the sys.path.insert ?

My working directory is:

C:\Users\Desktop\automatic-mscons-invoice-generator

reinhardt
  • 1,873
  • 3
  • 9
  • 23

1 Answers1

0

As you mentioned, adding to sys.path manually solved the problem.

Try adding that path to the PYTHONPATH environment variable, this tells the interpreter where are the scripts available for importing.

Nexaspx
  • 371
  • 4
  • 20