-
Notifications
You must be signed in to change notification settings - Fork 517
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
【v5.4】partially initialized module 'yaml' has no attribute '__with_libyaml__' #478
Comments
Seeing the same issue when using docker compose:
|
Hi, I'm seeing the same issue in some CI builds that run on Linux (GitHub Actions). FWIW, I'm not able to reproduce on my macOS machine (running Python 3.8.5): $ python
Python 3.8.5 (default, Aug 13 2020, 15:19:10)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>> yaml.__version__
'5.4' For anyone passing by, a workaround for now would be to pin to Is there anything I can do to help resolve this? |
upgrading pyyaml version in |
For me actually going from PyYAML==5.2.1 to 5.4 broke my ansible. The solution was to revert to 5.3. Sample of problem: $ ansible --version
Traceback (most recent call last):
File "/usr/local/bin/ansible", line 62, in <module>
import ansible.constants as C
File "/home/<user>/.local/lib/python3.8/site-packages/ansible/constants.py", line 15, in <module>
from ansible.config.manager import ConfigManager, ensure_type, get_ini_config_value
File "/home/<user>/.local/lib/python3.8/site-packages/ansible/config/manager.py", line 17, in <module>
from yaml import load as yaml_load
File "/home/<user>/.local/lib/python3.8/site-packages/yaml/__init__.py", line 13, in <module>
from .cyaml import *
File "/home/<user>/.local/lib/python3.8/site-packages/yaml/cyaml.py", line 7, in <module>
from _yaml import CParser, CEmitter
File "/usr/local/lib/python3.8/dist-packages/_yaml/__init__.py", line 8, in <module>
if not yaml.__with_libyaml__:
AttributeError: partially initialized module 'yaml' has no attribute '__with_libyaml__' (most likely due to a circular import)
$ sudo -H python3 -m pip install PyYAML==5.3
Collecting PyYAML==5.3
Installing collected packages: PyYAML
Found existing installation: PyYAML 5.4
Uninstalling PyYAML-5.4:
Successfully uninstalled PyYAML-5.4
Successfully installed PyYAML-5.3
$ python3 -V
Python 3.8.7
$ ansible --version
ansible 2.10.4
config file = /home/<user>/cookbook/ansible.cfg
configured module search path = ['/home/<user>/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/<user>/.local/lib/python3.8/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.8.7 (default, Dec 21 2020, 20:10:35) [GCC 7.5.0] Hope this helps. |
Same with python 3.8 and PyYAML 5.4. Try to build with libyaml and install. Get same error:
|
@sdn0303 , did you install with any pip options or is any info possibly excluded there? Here is a $ docker container run -it --rm --entrypoint=bash python:3.8-slim
root@11a5089d68cf:/# python3 -m pip install 'PyYAML==5.4'
Collecting PyYAML==5.4
Downloading PyYAML-5.4-cp38-cp38-manylinux1_x86_64.whl (662 kB)
|████████████████████████████████| 662 kB 6.4 MB/s
Installing collected packages: PyYAML
Successfully installed PyYAML-5.4
root@11a5089d68cf:/# python3 -c 'import yaml; print(yaml.__with_libyaml__)'
True
root@11a5089d68cf:/# python3 -m pip install 'ansible==2.9.*'
Collecting ansible==2.9.*
Downloading ansible-2.9.17.tar.gz (14.3 MB)
|████████████████████████████████| 14.3 MB 6.7 MB/s
Requirement already satisfied: PyYAML in /usr/local/lib/python3.8/site-packages (from ansible==2.9.*) (5.4)
root@11a5089d68cf:/# ansible --version
ansible 2.9.17
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.8.7 (default, Jan 12 2021, 17:16:32) [GCC 8.3.0] Ok also with Ansible 2.10.5. |
Also having trouble reproducing with root@3323cf48a2d3:/# apt-get update -yq
root@3323cf48a2d3:/# apt-get install -yq --no-install-recommends gcc libc6-dev linux-libc-dev
root@3323cf48a2d3:/# python3 -m pip install --no-binary=:all: PyYAML
root@3323cf48a2d3:/# python3 -c 'import yaml; print(yaml.__with_libyaml__)'
False |
@bsolomon1124 I use pipenv to manage my dependencies and install them with the 'pipenv install --system' command defined in the Dockerfile. |
@thanos1983 at a glance, it looks like your issue is a mixed install- it appears to be loading the |
@florimondmanca can you poke around on the filesystem a bit for one of those failures? I'm curious if there's a |
I guess the other possibility is that there's an old system/distutils-owned |
Yes, I was wondering if this might be due to a prior/existing install of @sdn0303, if you are able to share more specific detail to help reproduce what's happening here, that would help to get things solved all that much faster. |
Yeah, I'm pretty sure that's exactly what's happening, but unless it's a half uninstalled module or something, it's unclear how they're not getting |
I'm going to try and contrive an install like that with just |
Confirmed it does not seem to be a pipenv issue. (did not suspect it would be, but looks like that can be crossed off.) |
I think I know what's happening- it's a little more contrived than what we thought, but a variation on a theme (old |
Yep, that's it- I have a local repro, and will play with a fix right now. |
The underlying failure here should only occur in a mixed version environment where an old version of pyyaml sees a new version of the stub |
Release 5.4.1 in flight with the fix. |
@nitzmahone Thank you! |
@florimondmanca it looks like PyYAML 5.4.1 is up on PyPI, are you able to confirm that |
@nitzmahone @bsolomon1124 |
I can confirm the issue is resolved in the new release. Thanks @nitzmahone for the quick fix. Sample of resolution: $ sudo -H python3 -m pip install PyYAML -U
Collecting PyYAML
Downloading https://repo/api/pypi/pypi-remote/packages/packages/70/96/c7245e551b1cb496bfb95840ace55ca60f20d3d8e33d70faf8c78a976899/PyYAML-5.4.1-cp38-cp38-manylinux1_x86_64.whl (662kB)
100% |████████████████████████████████| 665kB 1.7MB/s
Installing collected packages: PyYAML
Found existing installation: PyYAML 5.3
Uninstalling PyYAML-5.3:
Successfully uninstalled PyYAML-5.3
Successfully installed PyYAML-5.4.1
$ ansible --version
ansible 2.10.4
config file = /home/<user>/cookbook/ansible.cfg
configured module search path = ['/home/<user>/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/<user>/.local/lib/python3.8/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.8.7 (default, Dec 21 2020, 20:10:35) [GCC 7.5.0] |
To fix py3.6 issue: yaml/pyyaml#478
Hi there, Thank you for releasing the new version 5.4.
When I imported version 5.4, I found the following error and would like to report it.
2021-01-20 12:23:20 import yaml 2021-01-20 12:23:20 File "/root/.local/lib/python3.8/site-packages/yaml/__init__.py", line 13, in <module> 2021-01-20 12:23:20 from .cyaml import * 2021-01-20 12:23:20 File "/root/.local/lib/python3.8/site-packages/yaml/cyaml.py", line 7, in <module> 2021-01-20 12:23:20 from _yaml import CParser, CEmitter 2021-01-20 12:23:20 File "/usr/local/lib/python3.8/site-packages/_yaml/__init__.py", line 8, in <module> 2021-01-20 12:23:20 if not yaml.__with_libyaml__: 2021-01-20 12:23:20 AttributeError: partially initialized module 'yaml' has no attribute '__with_libyaml__' (most likely due to a circular import)
The reproduced environment is python: 3.8-slim docker image.
The text was updated successfully, but these errors were encountered: