Strange `Module not found exception` when running from PyCharm's Python console

I ran today in a problem with PyCharm in the Python console. This problem occurs only in the Python console

The python code below runs perfectly on bin/python3 (and on bin\ipython) and in PyCharm both as python script and from the terminal but not from the Python console.

When running from the Python console it raises an ImportException: No module named 'Products.CMFCore.exportimport.typeinfo.importTypesTool'; 'Products.CMFCore.exportimport.typeinfo' is not a package

The exception is raised in Products.GenericSetup.utils when using __import__ when using Products.CMFPlone.factory.addPloneSite(...) (see code below).

As far as I understand it __import__ usually raises ImportException.

But obviously not when used by Products.GenericSetup.utils.

My question is: how is __import__ in Products.GenericSetup.utils working that it is usually able to __import__ modules?

Maybe the answer can help to find out why this code is not working in the Python console.

The Python console perfectly accepts both import and importlib.import_module:

from Products.CMFCore.exportimport.typeinfo import importTypesTool
import importlib
importlib.import_module("Products.CMFCore.exportimport.typeinfo")

but not __import__:

__import__("Products.CMFCore.exportimport.typeinfo.importTypesTool")

To reproduce it we are using a pip Installation of Plone-6.0-dev

rm -rf ~/plonepip
mkdir ~/plonepip
cd ~/plonepip
python3 -m venv .
bin/python3 -m pip install "pip==19.2.3"
bin/pip3 install -U setuptools wheel
bin/pip3 install Plone \
    -c https://dist.plone.org/release/6.0-dev/constraints.txt \
    -f https://dist.plone.org/release/6.0-dev/
bin/mkwsgiinstance \
    -u admin:admin \
    -d instance
# bin/runwsgi -v instance/etc/zope.ini

create a PyCharm project using ~/plonepip/bin/python3 as previously configured interpreter

New Project
  Pure Python
    (x) Previously configured interpreter
    Interpreter [...]
      Virtualenv Environment
        Interpreter [...]
          ~/plonepip/bin/python3
          [OK]
      [OK]
  [x] Create a main.py welcome script
  [Create]
# Wait for Background Task "Updating indexes"

The following code runs perfectly on bin/python3 (and on bin\ipython) and in PyCharm both as python script and from the terminal but not from the Python console.

Create a filename.py in PyCharm, add the following code and run it:

from Zope2.Startup.run import make_wsgi_app
publish_module = make_wsgi_app(
    {"debug_mode": "true", "debug_exceptions": "true"},
    "/home/map/plonepip/instance/etc/zope.conf",
)

import Zope2
app = Zope2.app()
app._p_jar.sync()

from Testing.makerequest import makerequest
app = makerequest(app)

from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager
admin_username = "admin"
acl_users = app.acl_users
user = acl_users.getUser(admin_username)
user = user.__of__(acl_users)
newSecurityManager(None, user)

from Products.CMFPlone.factory import addPloneSite
plone_site_name = "Plone"
if app.hasObject(plone_site_name):
    app.manage_delObjects(plone_site_name)

# the following call to addPloneSite raises an ImportException
# when running from the Python console
plone_site = addPloneSite(
    app,
    plone_site_name,
    extension_ids=("plonetheme.barceloneta:default", "plone.app.caching:default"),
    setup_content=True,
)
print(plone_site)