0
votes

I have a module that I use in a number of scripts. Its path is C:\PYTHONprojects\utilities\utility_module.py There is an (empty) file called __init__.py in the same folder.

If I import the module inside the PyCharm environment, it works fine: import utility_module as um but if do the same from the Python command line, I get: ModuleNotFoundError: No module named 'utility_module'

But the folder is in the PATH: From the windows command line: In: PATH

Out: 
......
C:\PYTHONprojects\utilities; C:\PYTHONprojects
.....

or from the Python Command Line:

In: import sys
    sys.path

Out:
    ......
    'C:\\PYTHONprojects', 'C:\\PYTHONprojects\\utilities'
1

1 Answers

1
votes

In order to load your module, it needs to be part of your PYTHONPATH system env (not PATH) or sys.path.

Your pycharm loads the working directory into your path for you. When you do that on command line, you need to take care for that.

So either add your project folder to system env PYTHONPATH or before you load the module, execute this:

import sys
sys.path.append(r'C:\PYTHONprojects\utilities')