diff --git a/conans/client/hook_manager.py b/conans/client/hook_manager.py
index be634d2ee..25f7fd8a0 100644
--- a/conans/client/hook_manager.py
+++ b/conans/client/hook_manager.py
@@ -101,8 +101,14 @@ class HookManager(object):
                 module = sys.modules[added]
                 if module:
                     try:
-                        folder = os.path.dirname(module.__file__)
-                    except AttributeError:  # some module doesn't have __file__
+                        try:
+                            # Most modules will have __file__ != None
+                            folder = os.path.dirname(module.__file__)
+                        except (AttributeError, TypeError):
+                            # But __file__ might not exist or equal None
+                            # Like some builtins and Namespace packages py3
+                            folder = module.__path__._path[0]
+                    except AttributeError:  # In case the module.__path__ doesn't exist
                         pass
                     else:
                         if folder.startswith(current_dir):
diff --git a/conans/client/loader.py b/conans/client/loader.py
index 9bd73cab0..361e0628a 100644
--- a/conans/client/loader.py
+++ b/conans/client/loader.py
@@ -261,8 +261,14 @@ def _parse_conanfile(conan_file_path):
             module = sys.modules[added]
             if module:
                 try:
-                    folder = os.path.dirname(module.__file__)
-                except AttributeError:  # some module doesn't have __file__
+                    try:
+                        # Most modules will have __file__ != None
+                        folder = os.path.dirname(module.__file__)
+                    except (AttributeError, TypeError):
+                        # But __file__ might not exist or equal None
+                        # Like some builtins and Namespace packages py3
+                        folder = module.__path__._path[0]
+                except AttributeError:  # In case the module.__path__ doesn't exist
                     pass
                 else:
                     if folder.startswith(current_dir):

[bug] conanfile loader "crashes" because of missing __file__ attribute in Python 3.7(+)
Hi there,
I am using multiple Python versions (e.g. 3.6, 3.7). My primary Python version is 3.6.
But occationally I execute Python version 3.7. With 3.6 there where no problems. 3.7 does not work.

I have 2 projects. One (```pkg_a```) gets ```python_requires```d into the other (```pkg_b```).
pkg_b inherits from a python file that gets exported with pkg_a. Now Python 3.6 everything works fine. In Python 3.7 I get an exception.

Crawling through the conan code I identified (at least I think) the code where the solution lies.
At [this code line](https://github.com/conan-io/conan/blob/4fdebfb79ce12f956b4be512253e8479e9d6bb17/conans/client/loader.py#L265) conan can catch an exception if the python module has no ```__file__``` attribute.
But in Python 3.7 I get a ```TypeError``` exception instead of an ```AttributeError``` exception.

The [Python docs describe](https://docs.python.org/3.6/library/exceptions.html#AttributeError) ([see](https://docs.python.org/3.6/library/exceptions.html#AttributeError)) that there could be raised a ```TypeError``` exception.

In turn I modified the code line [265](https://github.com/conan-io/conan/blob/4fdebfb79ce12f956b4be512253e8479e9d6bb17/conans/client/loader.py#L265) in the conan [loader.py](https://github.com/conan-io/conan/blob/develop/conans/client/loader.py).

From:
```python
except AttributeError: # some module doesn't have __file__
    pass
```

To:
```python
except AttributeError: # some module doesn't have __file__
    pass
except TypeError: # Python 3.7: some module doesn't have __file__
    pass
```

And everything worked like before.
I do not know if this is a Python or Conan problem. But at the moment this is a real issue as noone with a version of Python 3.7+ can execute my recipe.

For reference I made a minimal example to track down the issue.
[py36_py37_exception.zip](https://github.com/conan-io/conan/files/2915266/py36_py37_exception.zip)

diff --git a/conans/test/unittests/client/conanfile_loader_test.py b/conans/test/unittests/client/conanfile_loader_test.py
index 9ad90f4ba..898aaf622 100644
--- a/conans/test/unittests/client/conanfile_loader_test.py
+++ b/conans/test/unittests/client/conanfile_loader_test.py
@@ -1,21 +1,27 @@
 import os
+import sys
+import textwrap
 import unittest
 from collections import OrderedDict
 
+import six
 from mock import Mock
 from mock.mock import call
+from parameterized import parameterized
 
 from conans.client.graph.python_requires import ConanPythonRequire
-from conans.client.loader import ConanFileLoader, ConanFileTextLoader
+from conans.client.loader import ConanFileLoader, ConanFileTextLoader,\
+    _parse_conanfile
+from conans.client.tools.files import chdir
 from conans.errors import ConanException
 from conans.model.options import OptionsValues
 from conans.model.profile import Profile
 from conans.model.requires import Requirements
 from conans.model.settings import Settings
 from conans.test.utils.test_files import temp_folder
-from conans.util.files import save
 from conans.test.utils.tools import test_processed_profile,\
     TestBufferConanOutput
+from conans.util.files import save
 
 
 class ConanLoaderTest(unittest.TestCase):
@@ -225,3 +231,102 @@ class MyTest(ConanFile):
         recipe = loader.load_consumer(conanfile_path,
                                       test_processed_profile(profile))
         self.assertIsNone(recipe.settings.os.value)
+
+
+class ImportModuleLoaderTest(unittest.TestCase):
+    @staticmethod
+    def _create_and_load(myfunc, value, subdir_name, add_subdir_init):
+        subdir_content = textwrap.dedent("""
+            def get_value():
+                return {value}
+            def {myfunc}():
+                return "{myfunc}"
+        """)
+
+        side_content = textwrap.dedent("""
+            def get_side_value():
+                return {value}
+            def side_{myfunc}():
+                return "{myfunc}"
+        """)
+
+        conanfile = textwrap.dedent("""
+            import pickle
+            from {subdir}.api import get_value, {myfunc}
+            from file import get_side_value, side_{myfunc}
+            from fractions import Fraction
+            def conanfile_func():
+                return get_value(), {myfunc}(), get_side_value(), side_{myfunc}(), str(Fraction(1,1))
+        """)
+        expected_return = (value, myfunc, value, myfunc, "1")
+
+        tmp = temp_folder()
+        with chdir(tmp):
+            save("conanfile.py", conanfile.format(value=value, myfunc=myfunc, subdir=subdir_name))
+            save("file.py", side_content.format(value=value, myfunc=myfunc))
+            save("{}/api.py".format(subdir_name), subdir_content.format(value=value, myfunc=myfunc))
+            if add_subdir_init:
+                save("__init__.py", "")
+                save("{}/__init__.py".format(subdir_name), "")
+
+        loaded, module_id = _parse_conanfile(os.path.join(tmp, "conanfile.py"))
+        return loaded, module_id, expected_return
+
+    @parameterized.expand([(True, False), (False, True), (False, False)])
+    @unittest.skipIf(six.PY2, "Python 2 requires __init__.py file in modules")
+    def test_py3_recipe_colliding_init_filenames(self, sub1, sub2):
+        myfunc1, value1 = "recipe1", 42
+        myfunc2, value2 = "recipe2", 23
+        loaded1, module_id1, exp_ret1 = self._create_and_load(myfunc1, value1, "subdir", sub1)
+        loaded2, module_id2, exp_ret2 = self._create_and_load(myfunc2, value2, "subdir", sub2)
+
+        self.assertNotEqual(module_id1, module_id2)
+        self.assertEqual(loaded1.conanfile_func(), exp_ret1)
+        self.assertEqual(loaded2.conanfile_func(), exp_ret2)
+
+    def test_recipe_colliding_filenames(self):
+        myfunc1, value1 = "recipe1", 42
+        myfunc2, value2 = "recipe2", 23
+        loaded1, module_id1, exp_ret1 = self._create_and_load(myfunc1, value1, "subdir", True)
+        loaded2, module_id2, exp_ret2 = self._create_and_load(myfunc2, value2, "subdir", True)
+
+        self.assertNotEqual(module_id1, module_id2)
+        self.assertEqual(loaded1.conanfile_func(), exp_ret1)
+        self.assertEqual(loaded2.conanfile_func(), exp_ret2)
+
+    @parameterized.expand([(True, ), (False, )])
+    def test_wrong_imports(self, add_subdir_init):
+        myfunc1, value1 = "recipe1", 42
+
+        # Item imported does not exist, but file exists
+        with self.assertRaisesRegexp(ConanException, "Unable to load conanfile in"):
+            self._create_and_load(myfunc1, value1, "requests", add_subdir_init)
+
+        # File does not exists in already existing module
+        with self.assertRaisesRegexp(ConanException, "Unable to load conanfile in"):
+            self._create_and_load(myfunc1, value1, "conans", add_subdir_init)
+
+    def test_helpers_python_library(self):
+        mylogger = """
+value = ""
+def append(data):
+    global value
+    value += data
+"""
+        temp = temp_folder()
+        save(os.path.join(temp, "myconanlogger.py"), mylogger)
+
+        conanfile = "import myconanlogger"
+        temp1 = temp_folder()
+        save(os.path.join(temp1, "conanfile.py"), conanfile)
+        temp2 = temp_folder()
+        save(os.path.join(temp2, "conanfile.py"), conanfile)
+
+        try:
+            sys.path.append(temp)
+            loaded1, _ = _parse_conanfile(os.path.join(temp1, "conanfile.py"))
+            loaded2, _ = _parse_conanfile(os.path.join(temp2, "conanfile.py"))
+            self.assertIs(loaded1.myconanlogger, loaded2.myconanlogger)
+            self.assertIs(loaded1.myconanlogger.value, loaded2.myconanlogger.value)
+        finally:
+            sys.path.remove(temp)

pip install -e .[dev]
parse_log_pytest
requirements.txt
nose pytest
apt-get update apt-get install -y gcc-multilib g++-multilib wget unzip
3.6
conans/requirements.txt conans/requirements_server.txt conans/requirements_dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
astroid==2.11.7
attrs==22.2.0
beautifulsoup4==4.12.3
bottle==0.12.25
certifi==2021.5.30
charset-normalizer==2.0.12
codecov==2.1.13
colorama==0.4.5
-e git+https://github.com/conan-io/conan.git@3216966dcaa745d4356c4ef64f6f3d0ab1b2330b#egg=conan
coverage==4.2
deprecation==2.0.7
dill==0.3.4
distro==1.1.0
fasteners==0.19
future==0.16.0
idna==3.10
importlib-metadata==4.8.3
importlib-resources==5.4.0
iniconfig==1.1.1
isort==5.10.1
Jinja2==2.11.3
lazy-object-proxy==1.7.1
MarkupSafe==2.0.1
mccabe==0.7.0
mock==1.3.0
node-semver==0.6.1
nose==1.3.7
packaging==21.3
parameterized==0.8.1
patch==1.16
pbr==6.1.1
platformdirs==2.4.0
pluggy==1.0.0
pluginbase==0.7
py==1.11.0
Pygments==2.14.0
PyJWT==1.7.1
pylint==2.13.9
pyparsing==3.1.4
pytest==7.0.1
PyYAML==3.13
requests==2.27.1
six==1.17.0
soupsieve==2.3.2.post1
tomli==1.2.3
tqdm==4.64.1
typed-ast==1.5.5
typing_extensions==4.1.1
urllib3==1.26.20
waitress==2.0.0
WebOb==1.8.9
WebTest==2.0.35
wrapt==1.16.0
zipp==3.6.0

name: conan
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - astroid==2.11.7
      - attrs==22.2.0
      - beautifulsoup4==4.12.3
      - bottle==0.12.25
      - charset-normalizer==2.0.12
      - codecov==2.1.13
      - colorama==0.4.5
      - coverage==4.2
      - deprecation==2.0.7
      - dill==0.3.4
      - distro==1.1.0
      - fasteners==0.19
      - future==0.16.0
      - idna==3.10
      - importlib-metadata==4.8.3
      - importlib-resources==5.4.0
      - iniconfig==1.1.1
      - isort==5.10.1
      - jinja2==2.11.3
      - lazy-object-proxy==1.7.1
      - markupsafe==2.0.1
      - mccabe==0.7.0
      - mock==1.3.0
      - node-semver==0.6.1
      - nose==1.3.7
      - packaging==21.3
      - parameterized==0.8.1
      - patch==1.16
      - pbr==6.1.1
      - platformdirs==2.4.0
      - pluggy==1.0.0
      - pluginbase==0.7
      - py==1.11.0
      - pygments==2.14.0
      - pyjwt==1.7.1
      - pylint==2.13.9
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pyyaml==3.13
      - requests==2.27.1
      - six==1.17.0
      - soupsieve==2.3.2.post1
      - tomli==1.2.3
      - tqdm==4.64.1
      - typed-ast==1.5.5
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - waitress==2.0.0
      - webob==1.8.9
      - webtest==2.0.35
      - wrapt==1.16.0
      - zipp==3.6.0
prefix: /opt/conda/envs/conan

conans/test/unittests/client/conanfile_loader_test.py::ImportModuleLoaderTest::test_py3_recipe_colliding_init_filenames_1 conans/test/unittests/client/conanfile_loader_test.py::ImportModuleLoaderTest::test_py3_recipe_colliding_init_filenames_2 conans/test/unittests/client/conanfile_loader_test.py::ImportModuleLoaderTest::test_recipe_colliding_filenames
conans/test/unittests/client/conanfile_loader_test.py::test_processed_profile conans/test/unittests/client/conanfile_loader_test.py::ConanLoaderTest::test_package_settings conans/test/unittests/client/conanfile_loader_test.py::ImportModuleLoaderTest::test_helpers_python_library conans/test/unittests/client/conanfile_loader_test.py::ImportModuleLoaderTest::test_py3_recipe_colliding_init_filenames_0 conans/test/unittests/client/conanfile_loader_test.py::ImportModuleLoaderTest::test_wrong_imports_0 conans/test/unittests/client/conanfile_loader_test.py::ImportModuleLoaderTest::test_wrong_imports_1
conans/client/hook_manager.py conans/client/loader.py
conans/client/hook_manager.py conans/client/loader.py