Repository: pyinstaller/pyinstaller

Issue:
PyInstaller "TypeError: expected str, bytes or os.PathLike object, not NoneType" Error
I want to make an exe of my code. But i have an error. It's "TypeError: expected str, bytes or os.PathLike object, not NoneType".

I'm using that libraries:

- python-docx
- fitz (PyMuPDF)
- PIL
- tkinter
- extract_msg
- docx2pdf
- PyPDF2
- os
- glob
- shutil
- xlwings
- webbrowser
- docx.shared
- tabula
- win32com
- openpyxl
- pandas
- matplotlib.pyplot




>     Running auto-py-to-exe v2.24.1
> 
>     Building directory: C:\Users\user\AppData\Local\Temp\tmp0luhfhlf
> 
>     Provided command: pyinstaller --noconfirm --onefile --windowed --icon "C:/Users/user/Desktop/index.ico"
> 
>     --name "Puls Test Reporter" --clean "C:/Users/user/Desktop/Puls_Automation_v0.8.py"
> 
>     Recursion Limit is set to 5000
> 
>     Executing: pyinstaller --noconfirm --onefile --windowed --icon C:/Users/user/Desktop/index.ico --name Puls Test Reporter --clean C:/Users/user/Desktop/Puls_Automation_v0.8.py --distpath C:\Users\user\AppData\Local\Temp\tmp0luhfhlf\application --workpath C:\Users\user\AppData\Local\Temp\tmp0luhfhlf\build --specpath C:\Users\user\AppData\Local\Temp\tmp0luhfhlf
> 
>     113932 INFO: PyInstaller: 5.3
> 
>     113945 INFO: Python: 3.9.15 (conda)
> 
>     114014 INFO: Platform: Windows-10-10.0.19044-SP0
> 
>     114029 INFO: wrote C:\Users\user\AppData\Local\Temp\tmp0luhfhlf\Puls Test Reporter.spec
> 
>     114048 INFO: UPX is not available.
> 
>     114055 INFO: Removing temporary files and cleaning cache in C:\Users\user\AppData\Local\pyinstaller
> 
>     114603 INFO: Extending PYTHONPATH with paths ['C:\Users\user\Desktop']
> 
>     119809 INFO: checking Analysis
> 
>     119829 INFO: Building Analysis because Analysis-00.toc is non existent
> 
>     119842 INFO: Initializing module dependency graph...
> 
>     119891 INFO: Caching module graph hooks...
> 
>     119935 WARNING: Several hooks defined for module 'lark'. Please take care they do not conflict.
> 
>     119957 WARNING: Several hooks defined for module 'numpy'. Please take care they do not conflict.
> 
>     120003 INFO: Analyzing base_library.zip ...
> 
>     137431 INFO: Processing pre-find module path hook distutils from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks\pre_find_module_path\hook-distutils.py'.
> 
>     137439 INFO: distutils: retargeting to non-venv dir 'C:\Users\user\.conda\envs\Pulse\lib'
> 
>     154728 INFO: Caching module dependency graph...
> 
>     154942 INFO: running Analysis Analysis-00.toc
> 
>     154986 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable required by C:\Users\user.conda\envs\Pulse\python.exe 155411 INFO: Analyzing C:\Users\user\Desktop\Puls_Automation_v0.8.py
> 
>     184708 INFO: Processing pre-find module path hook site from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks\pre_find_module_path\hook-site.py'.
> 
>     184728 INFO: site: retargeting to fake-dir 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\fake-modules'
> 
>     243573 INFO: Processing pre-safe import module hook six.moves from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks\pre_safe_import_module\hook-six.moves.py'.
> 
>     327770 INFO: Processing pre-safe import module hook gi from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks\pre_safe_import_module\hook-gi.py'.
> 
>     356863 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks\pre_safe_import_module\hook-urllib3.packages.six.moves.py'.
> 
>     446966 INFO: Processing pre-safe import module hook win32com from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\pre_safe_import_module\hook-win32com.py'.
> 
>     770606 INFO: Processing module hooks...
> 
>     770621 INFO: Loading module hook 'hook-bcrypt.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     770645 INFO: Loading module hook 'hook-certifi.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     770682 INFO: Loading module hook 'hook-Crypto.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     772151 INFO: Loading module hook 'hook-cryptography.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     779516 INFO: Loading module hook 'hook-docutils.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     802909 INFO: Loading module hook 'hook-docx.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     803263 INFO: Loading module hook 'hook-docx2pdf.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     803300 INFO: Loading module hook 'hook-IPython.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     807457 INFO: Loading module hook 'hook-jedi.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     818122 INFO: Loading module hook 'hook-jinja2.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     818145 INFO: Loading module hook 'hook-jsonschema.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     818271 INFO: Loading module hook 'hook-lark.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     818392 INFO: Loading module hook 'hook-lxml.etree.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     818412 INFO: Loading module hook 'hook-lxml.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     823468 INFO: Loading module hook 'hook-nacl.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     823573 INFO: Loading module hook 'hook-nbconvert.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     824111 INFO: Loading module hook 'hook-nbformat.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     824278 INFO: Loading module hook 'hook-parso.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     824360 INFO: Loading module hook 'hook-platformdirs.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     824366 INFO: Loading module hook 'hook-plotly.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     1673230 INFO: Loading module hook 'hook-pycparser.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     1673249 INFO: Loading module hook 'hook-pythoncom.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     1676270 INFO: Loading module hook 'hook-pywintypes.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     1678463 INFO: Loading module hook 'hook-win32com.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     1678478 INFO: Loading module hook 'hook-zmq.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     1691698 INFO: Loading module hook 'hook-zoneinfo.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
> 
>     1692658 INFO: Loading module hook 'hook-numpy.py' from 'C:\Users\user\.conda\envs\Pulse\Lib\site-packages\numpy\_pyinstaller'...
> 
>     1693072 WARNING: Conda distribution 'numpy', dependency of 'numpy', was not found. If you installed this distribution with pip then you may ignore this warning.
> 
>     1693212 INFO: Import to be excluded not found: 'f2py'
> 
>     1693278 INFO: Loading module hook 'hook-babel.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks'...
> 
>     1694321 INFO: Loading module hook 'hook-difflib.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks'...
> 
>     1694369 INFO: Loading module hook 'hook-distutils.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks'...
> 
>     1694389 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks'...
> 
>     1694432 INFO: Loading module hook 'hook-encodings.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks'...
> 
>     1697502 INFO: Loading module hook 'hook-gevent.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks'...
> 
>     1702164 INFO: Determining a mapping of distributions to packages...
> 
>     1879274 WARNING: Unable to find package for requirement zope.event from package gevent.
> 
>     1879290 WARNING: Unable to find package for requirement zope.interface from package gevent.
> 
>     1879306 INFO: Packages required by gevent: ['setuptools', 'greenlet', 'cffi']
> 
>     1884186 INFO: Loading module hook 'hook-heapq.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks'...
> 
>     1884229 INFO: Loading module hook 'hook-importlib_metadata.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks'...
> 
>     1884251 INFO: Loading module hook 'hook-importlib_resources.py' from 'C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks'...
> 
>     An error occurred while packaging
> 
>     Traceback (most recent call last): File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\auto_py_to_exe\packaging.py", line 131, in package
> 
>     run_pyinstaller()
> 
>     File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller_main_.py", line 178, in
> 
>     run
> 
>     run_build(pyi_config, spec_file, **vars(args))
> 
>     File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller_main_.py", line 59, in
> 
>     run_build
> 
>     PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
> 
>     File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\building\build_main.py",
> 
>     line 934, in main
> 
>     build(specfile, distpath, workpath, clean_build)
> 
>     File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\building\build_main.py",
> 
>     line 856, in build
> 
>     exec(code, spec_namespace)
> 
>     File "C:\Users\user\AppData\Local\Temp\tmp0luhfhlf\Puls Test Reporter.spec", line 7, in
> 
>     a = Analysis(
> 
>     File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\building\build_main.py",
> 
>     line 381, in init
> 
>     self.__postinit__()
> 
>     File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\building\datastruct.py",
> 
>     line 173, in postinit
> 
>     self.assemble()
> 
>     File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\building\build_main.py",
> 
>     line 550, in assemble
> 
>     self.graph.process_post_graph_hooks(self)
> 
>     File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\analysis.py", line
> 
>     329, in process_post_graph_hooks
> 
>     module_hook.post_graph(analysis)
> 
>     File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\imphook.py", line
> 
>     429, in post_graph
> 
>     self._load_hook_module()
> 
>     File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\depend\imphook.py", line
> 
>     384, in _load_hook_module
> 
>     self._hook_module = importlib_load_source(self.hook_module_name, self.hook_filename)
> 
>     File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\compat.py", line 603, in
> 
>     importlib_load_source
> 
>     return mod_loader.load_module()
> 
>     File "", line 529, in _check_name_wrapper
> 
>     File "", line 1029, in load_module
> 
>     File "", line 854, in load_module
> 
>     File "", line 274, in _load_module_shim
> 
>     File "", line 711, in _load
> 
>     File "", line 680, in _load_unlocked
> 
>     File "", line 850, in exec_module
> 
>     File "", line 228, in _call_with_frames_removed
> 
>     File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\hooks\hook-
> 
>     importlib_resources.py", line 24, in
> 
>     res_loc = os.path.dirname(get_module_file_attribute('importlib_resources'))
> 
>     File "C:\Users\user.conda\envs\Pulse\lib\ntpath.py", line 223, in dirname
> 
>     return split(p)[0]
> 
>     File "C:\Users\user.conda\envs\Pulse\lib\ntpath.py", line 185, in split
> 
>     p = os.fspath(p)
> 
>     TypeError: expected str, bytes or os.PathLike object, not NoneType
> 
>     Project output will not be moved to output folder
> 
>     Complete.
> 

I tried on cmd screen and auto-py-to-exe but they didn't work. I installed libraries with "pip". I tried to install them with "conda" but i can't find all libraries with "conda". How can i fix that error?


Discussion:
This looks like an oddly mixed environment to me - you have an anaconda python

> 113945 INFO: Python: 3.9.15 (conda)

with conda-created environment 

> File "C:\Users\user.conda\envs\Pulse\lib\ntpath.py", line 223, in dirname

but PyInstaller is installed in site-packages directory usually used by python.org python 

> File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\PyInstaller\building\build_main.py"

Do you have both python.org python and anaconda installed on the system? Or is pip from anaconda python actually installing pacakges to `C:\Users\user\AppData\Roaming\Python\Python39\site-packages`?

---

The above environment might be the cause of the problem, but the symptom is that location of `importlib_resources` module cannot be determined. Although I think the module/package must be present somewhere, otherwise the hook would not be triggered.

1) Do you have `importlib_resources` installed in your environment (with python 3.9, the stdlib `importlib.resources` should be used in the first place...)? If so, what is its version? If you run 
```pythoh
import importlib_resources
print(importlib_resources.__file__)
``` 
in the same python environment you use with PyInstaller, what is the output?

2) If `importlib_resources` is not installed, do you have a .py file with that name located next to your entry-point python script?




Resolving patch:
diff --git a/PyInstaller/hooks/hook-importlib_resources.py b/PyInstaller/hooks/hook-importlib_resources.py
--- a/PyInstaller/hooks/hook-importlib_resources.py
+++ b/PyInstaller/hooks/hook-importlib_resources.py
@@ -12,19 +12,11 @@
 `importlib_resources` is a backport of the 3.9+ module `importlib.resources`
 """
 
-import os
+from PyInstaller.utils.hooks import is_module_satisfies, collect_data_files
 
-from PyInstaller.utils.hooks import get_module_file_attribute, is_module_satisfies
-
-if is_module_satisfies("importlib_resources >= 1.2.0"):
-    # since 1.2.0 importlib.metadata is used which PyInstaller knows how to handle.
-    pass
-else:
-    # include the version.txt file, used to set __version__
-    res_loc = os.path.dirname(get_module_file_attribute('importlib_resources'))
-    datas = [
-        (os.path.join(res_loc, 'version.txt'), 'importlib_resources'),
-    ]
+# Prior to v1.2.0, a `version.txt` file is used to set __version__. Later versions use `importlib.metadata`.
+if is_module_satisfies("importlib_resources < 1.2.0"):
+    datas = collect_data_files("importlib_resources", includes=["version.txt"])
 
 if is_module_satisfies("importlib_resources >= 1.3.1"):
     hiddenimports = ['importlib_resources.trees']


Test patch: