Click here to Skip to main content
15,885,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am very new to Python. I have taken on a project by someone who left. It is in Pycharm and I am trying to use pipenv.

In Pycharm, the project has folder path ./a/b/app (I have changed the folder names from their real names to a,b)

The path to flask_application.py is ./a/b/app/flask_application.py
There is also a file ./a/b/app/common_functions.py which I need to access from flask-application.

When I try to run the project I get the error:

File "....a/b/app/flask-application.py" line 8 in <module>
import b.app.common_functions as common
'ModuleNotFoundError: No module named 'b'

What do I need to do to get rid of this error? It is not a package that needs to be installed, it is a file that seems to not know about the project it is part of.

What I have tried:

I have tried installing 'b' and the pipfile has a line under [packages]
b = "*"
but it still gives that error
Posted
Comments
Richard MacCutchan 9-Nov-21 6:26am    
The error message is telling you that Python cannot find a valid path starting at b in the module that it is trying to build. You need to check the structure of your project, and find out exactly where this module is in relation the the one doing the import.
Jackie Lloyd 2021 9-Nov-21 6:58am    
Thank you for helping.
flask-application.py is doing the import to access common_functions.py.
they are both in a/b/app
so I can't see what the problem is

I apologise if I am missing something which should be obvious.
mbancroft 9-Nov-21 10:14am    
is the folder "a" on your python path? I think Python is going to look in those folders for a "b" folder and then for a common_functions within that.
The alternative might be to use a relative import rather than an absolute one i.e. with "from . import common_functions as common"
Jackie Lloyd 2021 11-Nov-21 4:24am    
Hi, thank you for all your help, I did try that and it didn't make any difference. In the end I just pulled the code again and redid the setup and the problem has not reappeared, which is still slightly annoying that I don't know why it happened!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900