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

Cannot load CLoader #108

Closed
lucj opened this issue Dec 8, 2017 · 7 comments
Closed

Cannot load CLoader #108

lucj opened this issue Dec 8, 2017 · 7 comments

Comments

@lucj
Copy link

lucj commented Dec 8, 2017

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.

@jonas-eschle
Copy link

jonas-eschle commented Feb 8, 2018

Any news on this one? I experience the same error, CLoader does not exist.

I think the whole cyaml is missing. Why is that?

@immerrr
Copy link

immerrr commented Mar 5, 2018

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..>

@jonas-eschle
Copy link

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.

@XiaoshanLin9701
Copy link

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

boehmseb added a commit to se-sic/VaRA-Tool-Suite that referenced this issue Oct 22, 2019
To use pyyaml's CLoader, the package `libyaml-dev` is needed on debian based systems according to yaml/pyyaml#108
vulder pushed a commit to se-sic/VaRA-Tool-Suite that referenced this issue Oct 22, 2019
To use pyyaml's CLoader, the package `libyaml-dev` is needed on debian based systems according to yaml/pyyaml#108
@EricCousineau-TRI
Copy link

EricCousineau-TRI commented Jun 24, 2020

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

@cliffxuan
Copy link

This is the minimum to get CLoader compiled and installed as of July 2020.
https://stackoverflow.com/a/62543781/243431

@nitzmahone
Copy link
Member

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.

bryan-bar added a commit to bryan-bar/edb-terraform that referenced this issue Mar 20, 2023
…and might require a manual install with the use of 'python setup.py --with-libyaml install' when using python virtual enviroments.

When manual install is skipped, the virutal enviroment might fail to detect libyaml, 'CLoader' is then not available within PyYAML and fails with an 'ImportError' if 'CLoader' is imported.

Error message - ERROR: could not read file /home/user/Projects/edb-terraform/infrastructure-examples/aws-all.yml (module 'yaml' has no attribute 'CLoader')
Ref: yaml/pyyaml#108
bryan-bar pushed a commit to bryan-bar/edb-terraform that referenced this issue Mar 20, 2023
…and might require a manual install with the use of 'python setup.py --with-libyaml install' when using python virtual enviroments.

When manual install is skipped, the virutal enviroment might fail to detect libyaml, 'CLoader' is then not available within PyYAML and fails with an 'ImportError' if 'CLoader' is imported.

Error message - ERROR: could not read file /home/user/Projects/edb-terraform/infrastructure-examples/aws-all.yml (module 'yaml' has no attribute 'CLoader')
Ref: yaml/pyyaml#108
bryan-bar added a commit to bryan-bar/edb-terraform that referenced this issue Mar 20, 2023
…and might require a manual install with the use of 'python setup.py --with-libyaml install' when using python virtual enviroments.

When manual install is skipped, the virutal enviroment might fail to detect libyaml, 'CLoader' is then not available within PyYAML and fails with an 'ImportError' if 'CLoader' is imported.

Error message - ERROR: could not read file /home/user/Projects/edb-terraform/infrastructure-examples/aws-all.yml (module 'yaml' has no attribute 'CLoader')
Ref: yaml/pyyaml#108
bryan-bar added a commit to EnterpriseDB/edb-terraform that referenced this issue Mar 20, 2023
Issue:
When manual install is skipped, the virtual environment might fail to detect `libyaml`, `CLoader` is then not available within `PyYAML` and fails with an `ImportError` if `CLoader` is imported.

Error message - `ERROR: could not read file /home/user/Projects/edb-terraform/infrastructure-examples/aws-all.yml (module 'yaml' has no attribute 'CLoader')`
Ref: yaml/pyyaml#108

Fix:
Use `safe_load` instead of using `CLoader`, which depends on `libyaml` and might require a manual install with the use of `python setup.py --with-libyaml install` when using python virtual environments.

Other Changes:
* Removed unused `security_group_ids` variable from AWS modules root variable file
* added `ImportError` to `try/except` import
bryan-bar added a commit to EnterpriseDB/edb-terraform that referenced this issue Mar 21, 2023
Issue:
When manual install is skipped, the virtual environment might fail to detect `libyaml`, `CLoader` is then not available within `PyYAML` and fails with an `ImportError` if `CLoader` is imported.

Error message - `ERROR: could not read file /home/user/Projects/edb-terraform/infrastructure-examples/aws-all.yml (module 'yaml' has no attribute 'CLoader')`
Ref: yaml/pyyaml#108

Fix:
Use `safe_load` instead of using `CLoader`, which depends on `libyaml` and might require a manual install with the use of `python setup.py --with-libyaml install` when using python virtual environments.

Other Changes:
* Removed unused `security_group_ids` variable from AWS modules root variable file
* added `ImportError` to `try/except` import
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

7 participants