No module named yaml (brew broke my python, again)

£可爱£侵袭症+ 提交于 2020-01-11 12:00:31

问题


homebrew has again broken python for about third time. Im now having issues getting dependencies to work again. At this point I am unable to install yaml.

Collecting yaml Could not find a version that satisfies the requirement yaml (from versions: ) No matching distribution found for yaml

Some other suggestions have said to try pyaml, which again simply tries to import yaml and fails Traceback (most recent call last): File "script.py", line 13, in <module> import pyaml File "/~/virtualenv/project/lib/python2.7/site-packages/pyaml/__init__.py", line 6, in <module> import os, sys, io, yaml ImportError: No module named yaml

Anyone have an idea how to get this sorted out?


回答1:


There are two packages with somewhat unfortunate naming in the Python Package Index.

  • pip install pyyaml lets you import yaml. This package enables Python to parse YAML files.
  • pip install pyaml lets you import pyaml. This package allows pretty-printing of YAML files from Python, among other things. It requires pyyaml to be installed.

So the way forward for you is:

  1. Install pyyaml, preferably using pip
  2. Install pyaml
  3. Profit

Step 0 would be to run everything from a virtual environment to prevent homebrew from messing with your Python ever again. This option also lets you run multiple versions of Python, not just the one required by homebrew.




回答2:


The solution for me turned out to be homebrew changing python to python2, which I believe precludes using the brew version instead of the system version

eg python script.py >> python2 script.py

Additionally, linking the system version of python to the brew python2 version helped as well:

cd /usr/local/bin && ln -s ../Cellar/python/2.7.13_1/bin/python2 python

I'm also hesitant the accepted answer will work, as pyaml is still attempting to import yaml, via __init__.py; which does not exist even after installing both packages

$ pip install pyaml 
Collecting pyaml
  Using cached pyaml-17.7.2-py2.py3-none-any.whl
Requirement already satisfied: PyYAML in ~/Library/Python/2.7/lib/python/site-packages (from pyaml)
Installing collected packages: pyaml
Successfully installed pyaml-17.7.2
$ pip install yaml 
Collecting yaml
  Could not find a version that satisfies the requirement yaml (from versions: )
No matching distribution found for yaml

eg

  File "/~/virtualenv/project/lib/python2.7/site-packages/pyaml/__init__.py", line 6, in <module>
    import os, sys, io, yaml


来源:https://stackoverflow.com/questions/45619886/no-module-named-yaml-brew-broke-my-python-again

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!