2

I am trying to run a python file from terminal. It has a bunch of imports from modules I wrote, and those modules also import from other modules from throughout my project. As PyCharm was my main editor, I could mark the src directory as Sources Root, which allowed me to import other modules in two ways. Say I have a module shared, I could import from it as:

from src.shared.timer import Timer

But also as:

from shared.timer import Timer

When I run my script main.py from within pycharm everything runs perfectly The problem is that when I run main.py from command line, my imports give error "No module named shared" or "No module named src" depending on whether I call from the top-level directory or from the src directory. Either way, I can never get all imports right. Is there a way to mark my src directory as Sources Root, similar to in PyCharm? I want to avoid refactoring everything and then finding out there is some other issue.

from top level directory in repository, I tried to run

python3.8 -m src.main.py

and got

ModuleNotFoundError: No module named 'shared'

1
  • 1
    Okay so it ran without any errors from the src directory once I replaced all src.some_module imports with just some_module. However, it would still be nice if I could mark the src folder as Sources Root similar to in PyCharm. Let me know if you know the answer please Commented Jan 25, 2023 at 19:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.