user9846208
user9846208

Reputation:

Module Not Found Error in Python 3.6 on windows command prompt

I have created a project like the below one:

project
|
| --package1
|      |
|      -- __init__py
|      --module1.py
|
| --package2
       |
       --__init__.py
       --module2.py

I want to import module1 into module2, (from package1 import module1)

In PyCharm everything is just working fine. But when I try to open the file "module2.py" from Windows10 command prompt I get ModuleNotFoundError: No module named 'module1'.

I was looking for the solution but not a single one worked. I'm using python 3.6 and I have set environment variable PYTHONPATH = I:\project\package1

Upvotes: 3

Views: 13262

Answers (1)

Lucax
Lucax

Reputation: 407

By default, python only searches current directory. So you'll need to append the path a bit.

In module 2:

import sys
sys.path.append('C:\PathTo\project\package1')
import module1

That should fix the issue you were having.

Upvotes: 5

Related Questions