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

Documentation not explicit on dependency on "libclang-dev", not having it results in "'NoneType' object has no attribute 'encode'" #4

Open
axsaucedo opened this issue Nov 2, 2020 · 10 comments

Comments

@axsaucedo
Copy link

axsaucedo commented Nov 2, 2020

Documentation not explicit on dependency on "libcmake-dev", not having it results in "'NoneType' object has no attribute 'encode'".

Tested on master, on this file: https://github.com/EthicalML/vulkan-kompute/blob/master/single_include/kompute/Kompute.hpp

I also tried on a simpler file (https://github.com/EthicalML/vulkan-kompute/blob/master/src/include/kompute/Manager.hpp) but still get the same error:

Processing "Manager.hpp" ..
Waiting for jobs to finish ..
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/home/alejandro/miniconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/home/alejandro/miniconda3/lib/python3.7/site-packages/pybind11_mkdoc/mkdoc_lib.py", line 232, in run
    tu = index.parse(self.filename, self.parameters)
  File "/home/alejandro/miniconda3/lib/python3.7/site-packages/clang/cindex.py", line 2722, in parse
    self)
  File "/home/alejandro/miniconda3/lib/python3.7/site-packages/clang/cindex.py", line 2816, in from_source
    args_array = (c_char_p * len(args))(*[b(x) for x in args])
  File "/home/alejandro/miniconda3/lib/python3.7/site-packages/clang/cindex.py", line 2816, in <listcomp>
    args_array = (c_char_p * len(args))(*[b(x) for x in args])
  File "/home/alejandro/miniconda3/lib/python3.7/site-packages/clang/cindex.py", line 109, in b
    return x.encode('utf8')
AttributeError: 'NoneType' object has no attribute 'encode'

Is this due to my environment? I'm testing in Ubuntu 18, Python3. Happy to provide further details.

@axsaucedo
Copy link
Author

Ok I have just tested with the sample file and still get an error https://github.com/pybind/pybind11_mkdoc/blob/master/tests/sample_header_docs/sample_header.h.

The error is the same, is this something to do with my environment?

@axsaucedo
Copy link
Author

Was able to replicate in docker image:

root@3f433f7e0613:/workspace# uname -a
Linux 3f433f7e0613 4.19.76-linuxkit #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

I also tested with branch v2.6 and seems to cause the same issue even with sample file.

It seems that this error tends to happen when particular libraries are not found numba/llvmlite#537, but a guess from the cmake python lib similar issue.

Are there any particular libraries that this depends on?

@axsaucedo
Copy link
Author

Looking at the code it seems to fail when trying to find libclang, so installed libclang-dev, now I am facing the same issue as #2

@matthewhagraphcore
Copy link

The 'NoneType' object has no attribute 'encode' issue comes from these lines here. If you have an empty or incompletely installed llvm / clang then you get an None for the directory.

The stdlib.h issue I am yet to fix completely. Though I was able to fix this temporarily by changing the #include_next directives to #include in /usr/include/c++/9/cstdlib e.g. #include_next <stdlib.h> -> #include <stdlib.h>. Do at you own risk and keep backups!

@axsaucedo
Copy link
Author

oh wow @matthewhagraphcore that worked... why?

@matthewhagraphcore
Copy link

I believe it occurs due to multiple gcc versions, some of which may be incorrectly installed. The #include_next directive will try and look for the next stdlib.h file, but can't find it (possibly it's looking for a newer version which isn't there, not sure).

Changing this to #include forces it to look in the same folder where we know the stdlib.h file is present.

Maybe removing all gcc installs and reinstalling might fix it, but I am on a shared server so was unwilling to try.

@axsaucedo
Copy link
Author

@matthewhagraphcore thank you for the explanation. I see, that would make sense. I completely agree that requiring configuring the gcc setup is not really something reasonable even on a personal computer. Hopefully the issue that you raised results in the package being updated to support multiple versions of gcc. I will change the title of this issue to focus primarily on outlining that the "libcmake-dev" dependency not being made explicit in the setup seciton of the readme.

@axsaucedo axsaucedo changed the title 'NoneType' object has no attribute 'encode' Documentation not explicit on dependency on "libcmake-dev", not having it results in "'NoneType' object has no attribute 'encode'" Nov 5, 2020
@henryiii
Copy link
Collaborator

henryiii commented Nov 5, 2020

Now I'm confused - why does libcmake-dev affect this? It's not using CMake at all. Is installing libcmake-dev triggering some other dependency to be installed forcing a valid dev environment, where otherwise parts were missing?

@axsaucedo
Copy link
Author

Oh my bad, I meant libclang-dev not libcmake

library_file = sorted(glob("/usr/lib/llvm-*/lib/libclang.so.1"), reverse=True)[0]

@axsaucedo axsaucedo changed the title Documentation not explicit on dependency on "libcmake-dev", not having it results in "'NoneType' object has no attribute 'encode'" Documentation not explicit on dependency on "libclang-dev", not having it results in "'NoneType' object has no attribute 'encode'" Nov 16, 2020
@lujobi
Copy link

lujobi commented Apr 1, 2021

I just had the same problem using some std libraries (iostream among others). I found a solution which is by no means optimal but I was not comfortable at all editing /usr/include.

My idea is to add an extra Macro which is only defined when running pybind11_mkdoc. Thus clang doesn't try to import the library. I can live with the error error: use of undeclared identifier 'std' as long as the docstrings are created correctly.

#ifndef PYBIND11_MKDOC_EXTRACT_DOCSTRING
#include <iostream>
#endif

/**
 * Some docstring
 */
class ExampleClass {};

running with the following flag:

python3 -m pybind11_mkdoc -DPYBIND11_MKDOC_EXTRACT_DOCSTRING -o  ${DOCSTRING_FILE} ${FILES}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants