Repository navigation
python:3.12.0 name not defined error #7992
Copy link
Copy link
Closed
Labels
Description
scipy stats module report name 'obj' not defined
Context information (for bug reports)
-
Output of
pyinstaller --version:6.0.0 -
Version of Python: 3.12.0
-
Platform: Windows (zh-CN)
-
How you installed Python: conda
-
Did you also try this on another platform? Does it work there?: have tried ubuntu22.04, the same error reported
- start with clean installation
- use the latest development version
- Run your frozen program from a command window (shell) — instead of double-clicking on it
- Package your program in --onedir mode
- Package without UPX, say: use the option
--noupxor setupx=Falsein your .spec-file - Repackage you application in verbose/debug mode. For this, pass the option
--debugtopyi-makespecorpyinstalleror useEXE(..., debug=1, ...)in your .spec file.
A minimal example program which shows the error
from scipy.stats import weibull_min
if __name__ == '__main__':
cc = weibull_min(c=2.5, loc=0, scale=1)
print(cc.cdf(0.001))Stacktrace / full error message
Traceback (most recent call last):
File "main.pyw", line 15, in <module>
File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 929, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 391, in exec_module
File "scipy\stats\__init__.py", line 608, in <module>
File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 929, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 391, in exec_module
File "scipy\stats\_stats_py.py", line 46, in <module>
File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 929, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 391, in exec_module
File "scipy\stats\distributions.py", line 8, in <module>
File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 929, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 391, in exec_module
File "scipy\stats\_distn_infrastructure.py", line 360, in <module>
NameError: name 'obj' is not defined
[26600] Failed to execute script 'main' due to unhandled exception!
I read the source code in scipy, the 'obj' located at scipy.stats._distn_infrastructure.py line 360. 'obj' is not defined before but only in some comprehensive list.
It totally ok when python vesion=3.11, but when i change to python 3.12, it report error. I was wondering if its a python 3.12 import system problem. Seems pyinstaller + python 3.11 won't import this 'del obj', but pyinstaller + python 3.12 will do.
# clean up all the separate docstring elements, we do not need them anymore
for obj in [s for s in dir() if s.startswith('_doc_')]:
exec('del ' + obj)
del objReactions are currently unavailable
Activity
rokm commentedon Oct 8, 2023
Hmm, this definitely looks like a bug, although I will need to dig further to see if it is ours or python's (or some weird combination of both).
rokm commentedon Oct 8, 2023
The behavior is definitely bizarre, as demonstrated by following minimal program:
The codepaths that call either
dir()orlocals()end up withmyobjundefined when we try to delete it.So far, all evidence points towards
PyInstaller.building.utils.strip_paths_in_codebeing the culprit. Making that no-op makes both the above example and animport scipy.statsprogram work. So there's probably some incompatibility with 3.12 in there that will need to be investiagted and fixed.CyberQin commentedon Oct 9, 2023
https://docs.python.org/3.12/whatsnew/3.12.html#pep-709-comprehension-inlining
maybe python3.12 pep709 affect it?
rokm commentedon Oct 9, 2023
Looks like a bug in python's
code.replace(), which we use instrip_paths_in_code. I've opened a bug report with python.CyberQin commentedon Oct 12, 2023
although it's not pyinstaller's bug, but should pyinstaller treat python 3.12.0 as a not full compability py version.
bwoodsend commentedon Oct 12, 2023
We can add a sentence saying as much in the readme but that's all we can do. It's impossible to withdraw support for a Python version once we've marked one release as supporting it. I'll pin the issue for now – that tends to keep people from raising duplicate issues.
tests: xfail scipy tests on python 3.12
tests: xfail scipy tests on python 3.12
jeffheaton commentedon Oct 18, 2023
FYI, Running into this one as well. Only see it in Pyinstaller too, only in 3.12. Will revert Python versions.
noahyoah commentedon Oct 31, 2023
Good day everyone!
I am reaching out to determine if anyone has found a work around for this issue. I am attempting create an executable using auto-py-to-exe and unfortunately it is failing due to 'obj' not defined.
Additionally, I believe that this same issue is happening with the module statsmodels.api as well.
Any information you provide would be greatly appreciated.
rokm commentedon Oct 31, 2023
The obvious work-around would be not to use python 3.12 until they fix
code.replace(), would it not?Other than that, you could also:
obj(here)strip_paths_in_codeno-op, i.e., immediately return originalco(if non-anonymized paths are not a problem for you)noahyoah commentedon Oct 31, 2023
Rokm,
I appreciate your response. I used an older version of python and was able to create the executable. Thank you for pointing me in the correct direction.
CyberQin commentedon Nov 9, 2023
Good News, A bug fix have been merged to python:main and python:3.12 branch 9 hours ago, maybe 3.12.1 will sove this problem! python/cpython#111866 .
[-]python3.12 name not defined error[/-][+]python:3.12.0 name not defined error[/+]Version `0.1.10`
CyberQin commentedon Dec 11, 2023
python 3.12.1 released , this bug has been fixed ,pls upgrade your python version to avoid this issue.
Actually pyinstaller not work well only with python=3.12.0
Update supported Python versions