Cannot load CLoader
Closed this issue ยท 7 comments
Hi, I'm using pyyaml in a Docker container based on bitnami/minideb:jessie, where python version is 2.7.9.
The original code is using CLoader and I cannot change it. Any reason CLoader fails to load but Loader is fine ?
>>> import yaml
>>> yaml.__version__ '3.12'
>>> from yaml import Loader
>>> from yaml import CLoader Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: cannot import name CLoader
>>>
I cannot figure out what I'm missing here. Any idea ?
Running it from the Docker image python:2.7.9 does not raise any error then:
$ docker run -ti python:2.7.9 bash
#/ python
>>> from yaml import CLoader
>>> from yaml import Loader
>>>
Thanks for your help.
Any news on this one? I experience the same error, CLoader does not exist.
I think the whole cyaml is missing. Why is that?
This is because cyaml is optional and requires build dependencies, such as cython
and yaml.h
to be available upon building the package (yaml.h
comes from libyaml-dev
package in Debian/Ubuntu):
This is what it prints when libyaml-dev
is not found when running $ pip --no-cache-dir install --verbose --force-reinstall -I pyyaml
<....>
running build_ext
creating build/temp.linux-x86_64-2.7
checking if libyaml is compilable
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/immerrr/.conda/envs/loc-des/include/python2.7 -c build/temp.linux-x86_64-2.7/check_libyaml.c -o build/temp.linux-x86_64-2.7/check_libyaml.o
build/temp.linux-x86_64-2.7/check_libyaml.c:2:18: fatal error: yaml.h: No such file or directory
compilation terminated.
libyaml is not found or a compiler error: forcing --without-libyaml
(if libyaml is installed correctly, you may need to
specify the option --include-dirs or uncomment and
modify the parameter include_dirs in setup.cfg)
<..finishes up right away..>
And this is what you'll see if everything is set up fine:
<....>
checking if libyaml is compilable
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/immerrr/.conda/envs/loc-des/include/python2.7 -c build/temp.linux-x86_64-2.7/check_libyaml.c -o build/temp.linux-x86_64-2.7/check_libyaml.o
checking if libyaml is linkable
gcc -pthread build/temp.linux-x86_64-2.7/check_libyaml.o -L/home/immerrr/.conda/envs/loc-des/lib -lyaml -o build/temp.linux-x86_64-2.7/check_libyaml
building '_yaml' extension
<..proceeds to build the extension..>
Thanks for the fix! This worked. But I would propose to add such a statement directly in the error message. So if cyaml cannot be compiled but is accessed, it should not just be an attribute not found
-error but rather a message telling the above.
Met with the same problem after installing the pyyaml using"pip3 install pyyaml". So I install yaml from source and fix the problem. See https://github.com/yaml/pyyaml.
Download the source code, run
python3 setup.py install --record record.txt
If you met with problems like Permission denied: '/usr/local/lib/python3.5/dist-packages/cython.py'
run
python3 setup.py install --record record.txt --user
If you want to uninstall, run
cat record.txt | xargs rm -rf
Ran into the same issue as well. I did bad searching, so did not come across this until after I (re) solved it on my own:
https://gist.github.com/EricCousineau-TRI/15cbc5a7ee7223871e384b5ab3e92e62#gistcomment-3352386
This is the minimum to get CLoader compiled and installed as of July 2020.
https://stackoverflow.com/a/62543781/243431
Closing, as this isn't really a pyyaml bug, just missing deps to the builds... We might accept docs PRs to update the native extension build deps for various distros, but it'll be an endless game of whack-a-mole.