Repository: pyinstaller/pyinstaller

Issue:
issue with having a folder name packaging when --hiddenimport pandas (this is very weird)
## Description of the issue
I came across this very weird behavior of pyinstaller. I found out that when I have a folder in the project dir named as "packaging", pyinstaller while building distribution would throw error. I have couple of hiddenimport modules like boto3, and pandas in the spec file. If i remove pandas, the build process successfully runs. 

pyinstaller-pandas-err/
├── packaging
├── test.py
└── test.spec



### Context information (for bug reports)

* Output of `pyinstaller --version`: ```(5.1)```
* Version of Python:  3.9
* Platform: Linux (ubuntu 20.4)
* How you installed Python: conda
* Did you also try this on another platform? Does it work there? : Got the same error. 

### A minimal example program which shows the error

```
print('Hello World')
```

### log-level=debug
```
8531 INFO: Loading module hook 'hook-packaging.py' from '/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/hooks'...
8547 DEBUG: Looking for egg data files...
8547 INFO: Looking for ctypes DLLs
8547 DEBUG: Scanning test.support for shared libraries or dlls
8594 DEBUG: Scanning multiprocessing.sharedctypes for shared libraries or dlls
8595 DEBUG: Scanning setuptools.windows_support for shared libraries or dlls
8595 DEBUG: Scanning numpy.distutils._shell_utils for shared libraries or dlls
8596 DEBUG: Scanning numpy.core._dtype_ctypes for shared libraries or dlls
8596 DEBUG: Scanning numpy.core._internal for shared libraries or dlls
8599 DEBUG: Scanning numpy.ctypeslib for shared libraries or dlls
8601 DEBUG: Scanning dateutil.tz.win for shared libraries or dlls
8622 WARNING: Library user32 required via ctypes not found
8622 DEBUG: Scanning pandas.io.clipboard for shared libraries or dlls
8634 WARNING: Library msvcrt required via ctypes not found
8634 DEBUG: Scanning uuid for shared libraries or dlls
8636 DEBUG: Scanning setuptools._vendor.packaging.tags for shared libraries or dlls
8637 DEBUG: Scanning pkg_resources._vendor.packaging.tags for shared libraries or dlls
8638 DEBUG: Scanning pkg_resources._vendor.appdirs for shared libraries or dlls
Traceback (most recent call last):
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/bin/pyinstaller", line 8, in <module>
    sys.exit(run())
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/__main__.py", line 178, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/__main__.py", line 59, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/building/build_main.py", line 842, in main
    build(specfile, distpath, workpath, clean_build)
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/building/build_main.py", line 764, in build
    exec(code, spec_namespace)
  File "/home/bioinfo/gaurav/gworks/rough/py/pyinstaller-pandas-err/test.spec", line 7, in <module>
    a = Analysis(
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/building/build_main.py", line 319, in __init__
    self.__postinit__()
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/building/datastruct.py", line 173, in __postinit__
    self.assemble()
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/building/build_main.py", line 512, in assemble
    for (dest, source) in format_binaries_and_datas(self.graph.metadata_required()))
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/depend/analysis.py", line 676, in metadata_required
    out |= self._metadata_from(
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/depend/analysis.py", line 728, in _metadata_from
    for calls in bytecode.recursive_function_calls(code).values():
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/depend/bytecode.py", line 225, in recursive_function_calls
    return search_recursively(function_calls, code)
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/depend/bytecode.py", line 213, in search_recursively
    _memo[code] = search(code)
  File "/home/bioinfo/gaurav/gworks/rough/py/venv/lib/python3.8/site-packages/PyInstaller/depend/bytecode.py", line 172, in function_calls
    for match in finditer(_call_function_bytecode, code.co_code):
AttributeError: 'NoneType' object has no attribute 'co_code'

```

[err.txt](https://github.com/pyinstaller/pyinstaller/files/8843470/err.txt)



Discussion:

Resolving patch:
diff --git a/PyInstaller/depend/analysis.py b/PyInstaller/depend/analysis.py
--- a/PyInstaller/depend/analysis.py
+++ b/PyInstaller/depend/analysis.py
@@ -662,6 +662,10 @@ def get_code_using(self, module: str) -> dict:
                 if identifier == module or identifier.startswith(module + '.'):
                     # Skip self references or references from `modules`'s own submodules.
                     continue
+                # The code object may be None if referrer ends up shadowed by eponymous directory that ends up treated
+                # as a namespace package. See #6873 for an example.
+                if r.code is None:
+                    continue
                 co_dict[r.identifier] = r.code
         return co_dict
 


Test patch: