Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure in 'Looking for ctypes DLLs' when specifying 'ctypes' as a hidden import. #3825

Closed
Viech opened this issue Oct 23, 2018 · 6 comments · Fixed by #5663
Closed

Failure in 'Looking for ctypes DLLs' when specifying 'ctypes' as a hidden import. #3825

Viech opened this issue Oct 23, 2018 · 6 comments · Fixed by #5663

Comments

@Viech
Copy link

Viech commented Oct 23, 2018

With hiddenimports=["ctypes"], I get the following exception:

24 INFO: PyInstaller: 3.4
24 INFO: Python: 3.7.1
25 INFO: Platform: Linux-4.18.16-arch1-1-ARCH-x86_64-with-arch
26 INFO: UPX is not available.
26 INFO: Extending PYTHONPATH with paths
['…/snakes.py']
26 INFO: checking Analysis
28 INFO: Building because hiddenimports changed
28 INFO: Initializing module dependency graph...
31 INFO: Initializing module graph hooks...
31 INFO: Analyzing base_library.zip ...
2372 INFO: Analyzing hidden import 'ctypes'
2415 INFO: running Analysis Analysis-00.toc
2441 INFO: Caching module hooks...
2446 INFO: Analyzing snakes.py
2474 INFO: Loading module hooks...
2474 INFO: Loading module hook "hook-xml.py"...
2654 INFO: Loading module hook "hook-pydoc.py"...
2654 INFO: Loading module hook "hook-encodings.py"...
2699 INFO: Looking for ctypes DLLs
Traceback (most recent call last):
  File "/usr/bin/pyinstaller", line 11, in <module>
    load_entry_point('PyInstaller==3.4', 'console_scripts', 'pyinstaller')()
  File "/usr/lib/python3.7/site-packages/PyInstaller/__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/usr/lib/python3.7/site-packages/PyInstaller/__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/usr/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 838, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "/usr/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 784, in build
    exec(text, spec_namespace)
  File "<string>", line 21, in <module>
  File "/usr/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 241, in __init__
    self.__postinit__()
  File "/usr/lib/python3.7/site-packages/PyInstaller/building/datastruct.py", line 158, in __postinit__
    self.assemble()
  File "/usr/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 531, in assemble
    ctypes_code_objs = self.graph.get_co_using_ctypes()  # dict like:  {'module1': code_obj, 'module2': code_obj}
  File "/usr/lib/python3.7/site-packages/PyInstaller/depend/analysis.py", line 554, in get_co_using_ctypes
    r_ident =  r.identifier
AttributeError: 'NoneType' object has no attribute 'identifier'

On the other hand, when I needlessly import ctypes in my main script, everything works like a charm.

I want to set ctypes as a hidden import because it is required by bearlibterminal, a Python dependency that I add manually to work around #3584.

@mahadi
Copy link

mahadi commented Jun 5, 2019

@Shincham
Copy link

Perhaps this is related to: https://bitbucket.org/ronaldoussoren/altgraph/pull-requests/4/default/diff

This link is not public. Can't access it.

@Shincham
Copy link

Shincham commented Mar 22, 2021

I'm having this same issue. Project on python 2, getting this exception when importing this module. Anyone knows some workaround ?

rokm added a commit to rokm/pyinstaller that referenced this issue Mar 22, 2021
If `ctypes` is (manually) added to hidden imports under python 3.7,
one of `referers` entries processed in `get_co_using_ctypes()` method
of `PyiModuleGraph` ends up being None. This in turn causes error
when its `identifier` property is accessed, causing pyinstaller#3825.

Work around the problem by explicitly skipping `None` entries.

Fixes pyinstaller#3825.
@rokm
Copy link
Member

rokm commented Mar 22, 2021

@Shincham Python 2 is not supported anymore, and PyInstaller versions that support it are not supported anymore, either. But you can backport and apply the fix from the linked PR to your PyInstaller installation.

@Shincham
Copy link

Shincham commented Mar 22, 2021

@Shincham Python 2 is not supported anymore, and PyInstaller versions that support it are not supported anymore, either. But you can backport and apply the fix from the linked PR to your PyInstaller installation.

Thanks for the reply and for the workaround. I copied your change on the commit to my localfile and it solved my problem. Module was succesfully bundled and also stopped the runtime error.

But it's not possible to include this change in the pyinstaller 3.6 version ? This change will only go to the version 4+ ?

@rokm
Copy link
Member

rokm commented Mar 22, 2021

But it's not possible to include this change in the pyinstaller 3.6 version ? This change will only go to the version 4+ ?

Indeed, it will go only into next release. We don't do multi-version branching and releases.

bwoodsend pushed a commit that referenced this issue Mar 23, 2021
If `ctypes` is (manually) added to hidden imports under python 3.7,
one of `referers` entries processed in `get_co_using_ctypes()` method
of `PyiModuleGraph` ends up being None. This in turn causes error
when its `identifier` property is accessed, causing #3825.

Work around the problem by explicitly skipping `None` entries.

Fixes #3825.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants