2

I have a project with multiple packages, each containing its own src folder:

project/
  src/
    package1/
      pyproject.toml
      src/
        logic/
          somestuff.py
          mymodel1.py
        __init__.py
    package2/
      pyproject.toml
      src/
        logic/
          somestuff.py
          mymodel2.py
        __init__.py

The problem is that even when I define each package1, package2 folders with 'sources root', I have the next error. It seems PyCharm thinks that the src folder is the src folder in the package2, and not in the package1. What should I do?

enter image description here

1 Answer 1

0

This isn't one project. It's N.

  1. run 'poetry install' (or whatever you are using) to create a virtual environment for each directory with a pyproject.toml file.
  2. Open each such directory as a project in pycharm, using 'attach' to keep them all in the same window. For each one, set the interpreter (in the Python settings) to be the python in the virtual environment.
  3. Set up the inter-project dependencies in the Pycharm settings.
Sign up to request clarification or add additional context in comments.

5 Comments

You are very right that this is a monorepo with few "projects", and venv should be created for each. But is there an option to still having all in 1 IDE? i dont want to open many windows. The only solution i found is not using the name "src" in many places but for example the name of the package. Then the imports will be proper for pycharm
#Relys You need to make one of the packages submodule using git and install the dependencies. Then you can mark one of the packages as sources root. stackoverflow.com/a/56959602/9528291
When opening a "sub"-projects choose "Attach" so you will have multiple projects in the same window. Still a hustle to configure each "sub"-project manually but we are working on implementing a proper "multi-model" (or "monorepo") projects. I would expect some results in 2025.3.* or 2026.1 versions.
So do I need that git submodule thing that user70 said? Or simply cloning the repo and attaching each direcrory? Also do i need to define 3 different interpreters for each module?
You do not need submodules.

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.