Search code examples
python-2.7pypypyyaml

Pypy(Window10) ImportError: No module named yaml


I am working under Anaconda environment(using Anaconda Prompt) and activate snakes (C:\Users\Acer\Anaconda3\envs\snakes). I have done the 'conda install pip' and 'pip install yaml', why I still face import error on yaml module?

(C:\Users\Acer\Anaconda3) C:\Users\Acer\pypy2.7-v7.0.0-win32>activate snakes

(snakes) C:\Users\Acer\pypy2.7-v7.0.0-win32>conda install pip
Fetching package metadata .............
Solving package specifications: .

# All requested packages already installed.
# packages in environment at C:\Users\Acer\Anaconda3\envs\snakes:
#
pip                       19.0.3                   py27_0

(snakes) C:\Users\Acer\pypy2.7-v7.0.0-win32>pip install pyyaml
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already satisfied: pyyaml in c:\users\acer\anaconda3\envs\snakes\lib\site-packages (5.1)

(snakes) C:\Users\Acer\pypy2.7-v7.0.0-win32>pypy
Python 2.7.13 (9112c8071614, Feb 06 2019, 23:10:08)
[PyPy 7.0.0 with MSC v.1500 32 bit] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>> import yaml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named yaml

Solution

  • You may have installed PyYAML succesfully, but since a computer can have multiple installations of a python interpreters, that only helps if you use the pip executable, associated with the python interpreter that you want o use, to install it.

    In your case you start pypy, by first cd-ing to the C:\Users\Acer\pypy2.7-v7.0.0-win32, try using the command bin\pip install pyyaml while in that directory instead of using some pip that happens to be in your PATH.

    You should invest the time to learn about using virtualenv at some point, so that you can keep the versions of libraries for various projects seperated. Installing into the some Python versions global site-packages directory unfortunately seems to work at the beginning, but to unravel the mess you create once things start to fall apart (which can take years) is cumbersome and always comes at the wrong moment.