Pyinstaller TypeError: expected str, bytes or os.PathLike object, not NoneType Fix

Categories:   web development  
Tags:   python  

After writing a few Python scripts, you might want to make it executable so you can run it without using the command line.

pyinstaller is an easy way to export your python script as an executable file for your OS.

To install it run:

pip install pyinstaller

Once installed, you can export your script with this command:

pyinstaller --onefile <yourscript>.py

The –onefile argument will export your script to one file instead of a folder of mess.

The executable file should be exported to the dist folder in your project.

Running the executable file will do exactly what your script did.

This means that if your script depends on certain files and folders, the location of those files must be the same with your executable file.

You also need Python installed on the machine to run this executable file.

I have a bunch of executable scripts on my desktop that are used for automating work, keystroke logging and other useless tasks.

Windows 10 - TypeError: expected str, bytes or os.PathLike object, not NoneType

I don’t know how common this error is but upon running pyinstaller on windows 10, I get the error:

TypeError: expected str, bytes or os.PathLike object, not NoneType

I get this error on Windows 10, whether a fresh install or not.

A quick fix was found here, in case anyone stumbles across this problem:

All you need to do is edit this file (if you are using a virtual environment):


and add these lines between these comments:

# Python library NOT found. Resume searching using alternative methods.

# Work around for python venv having VERSION.dll rather than pythonXY.dll
if is_win and 'VERSION.dll' in dlls:
    pydll = 'python%d%d.dll' % sys.version_info[:2]
    if pydll in PYDYLIB_NAMES:
        filename = getfullnameof(pydll)
        return filename

# Applies only to non Windows platforms.

After editing this file, I havn’t had issues with exporting executable files in Windows 10.

The downside is that I have to do this everytime for each project.

Related Products

Categories:   web development  
Tags:   python