How to convert python file to exe? The 'pathlib' package is an obsolete backport of a standard library package and is incompatible with PyInstaller

Question:

I am receiving following error while converting python file to .exe
I have tried to uninstall and intsall pyinstaller but it didnt helped out. i upgraded conda but still facing same error. Please support to resolve this issue

Command

(base) G:>pyinstaller –onefile grp.py

Error

The ‘pathlib’ package is an obsolete backport of a standard library package and is incompatible with PyInstaller. Please remove this package (located in C:Usersalphaanaconda3libsite-packages) using conda remove then try again.

Python Version

(base) G:>python –version
Python 3.9.16

Asked By: aza01

||

Answers:

I faced the same issue having the same versions of Anaconda/ Python. However, after executing conda remove pathlib my issue got resolved.
After removing pathlib through the above mentioned command, I checked some sample codes by importing pathlib module but everything worked fine; without any error or warning.
Listing of pathlib.py also shows that the pathlib module is still available in Anaconda environment.
Anaconda 3 and Python 3.9.16 environment

Answered By: Zahid

I face with the same problem, and I input the ‘conda remove pathlib’, it didn’t work. The result is Not found the packages, so I found the lir ‘lib’, there was a folder named ‘path-list-….’, finally I delete it, and it began working!

Answered By: jignfang

The error message you received suggests that the ‘pathlib’ package installed in your Anaconda environment is causing compatibility issues with PyInstaller. As a result, PyInstaller is unable to create a standalone executable from your Python script.

Answered By: Jangist

I’ve experienced the same problem. I managed to solve it by downgrading pyInstaller to 5.1 (from 5.8) without touching pathlib. An additional possibility to consider.

Answered By: knave

I’ve used py2exe in the past and has served me well since the question is "how to convert a .py into .exe" (paraphrased).

Checkout https://pypi.org/project/py2exe/
See Tutorial https://www.py2exe.org/index.cgi/Tutorial

Answered By: Goran B.