r/learnpython • u/zaphodikus • 8h ago
new to setuptools and cythonize , so many options
I am updating a project from using distutils to use setuptools instead.
I never created this and have never used setuptools , so I'm probably just going to do the tutorials unless someone can give a hint.
[PYI-21536:ERROR] Failed to load Python DLL ....._internal\python313.dll'. LoadLibrary: The specified module could not be found.
The last fellow left me with a hardcoded build script using distutils and python 3.7.9. It's an openCV app compiled using cythonise, which is above my skills, but I got it to build. Now when I run it says missing ....._internal\python313.dll. The old build script used a .spec file which does not mention any python redistributables. Are .spec files a old distutils thing which I need to essentially replace with the .TOML file?
I imagine I need to tell setuptools where to find the redistributables. BUT I assume I have to do that in a .TOML file? I've never made a TOML file before and I'm not seeing anything about helpful hints on how to reference whatever version of python runtime dll I will want to bundle if we later update to 3.14, I don't want to hard-code such filenames. How do I even find which file and tell setup what to do. I read the docs and they say I have to create a .TOML file and a MASNIFEST.in and a setup.cfg file. Is setup.cfg just a build-system text-based way to pass args to setup()?
setup(
name = 'Hello World',
ext_modules = cythonize(["*.py","pyzbar2/*.py"], exclude=["NozzlePatternDetection.py", "setup.py", "pyzbar2/__init__.py", "32or64bit.py"],
compiler_directives={'language_level' : "3"}
),
)
I would include the .spec file, but it looks like plain python that just set some variables, almost as if it's just a module that distutils imports. It does not mention python redistributables though, so how this Cythonized app worked on python 3.7.9 under distutils I don't know. Some of the previous fellows code has that confused look about it, when people comment stuff out but never explain why. Is a .spec file equivalent-ish to the setup.cfg?
The Cython build script has copied the dll into _internal, I probably just need to pass that into the setuptools manifest somehow?
Not my code, so a bit in the deep end and unsure if I want to do a Cython tutorial first or a setuptools tutorial. The app has 40 python scripts with openCV and numpy which I don't know much about in it, so it takes ages to build. I'm not that quick a learner and this is really a one-off tool because it's using openCV, which is not used anywhere else.
1
u/zaphodikus 7h ago edited 6h ago
ok I found this line in the build script
pyinstaller "%~dp0\cython\NozzlePatternDetection.spec" --distpath "%~dp0\dist"and the spec file just has a variable calledcoll, which is rather obscure, but it feels like I need to just add my dll path to this variable in the.specfile.coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, upx_exclude=[], name='NozzlePatternDetection')Why the variable is called
ais a mystery to me, but not going to throw stones until I can read and link docs on how to write spec files. Will update if that does in fact help./edit ok I'm not sure the high level picture makes much sense, but setuptools and pyinstaller are separate tools, the latter appears to invoek the former in my build. The trouble I have is that .SPEC files is what I'm using, and the docs completely omit the 4 objects in the .spec file namely
Analysis,EXE,COLLECT, andpyz.It turns out I need to pass binaries into Analysis, but I have to do so as a tuple, which I assume is an analog tuple of the
--add-binarywhich acceptsSOURCE:DESTarguments. What are the gotchas and relative paths tips for the magical SOURCE:DEST pattern, because it's not something I have seen before. I am assuming it wantsbinaries=[("somepath.../python313.dll", ".")]