Hi,
I have updated to the newest version 5.1 but yaml module is not available:
yaml version: 5.1
python version: Python 3.7.1
OS version: macOS Sierra 10.13.6
Any idea? Thanks!
yaml version: 5.1
How have you determined this? How did you install PyYAML?
Hi,
pip install pyyaml
Looking in indexes: https://pypi.python.org/simple/
Requirement already satisfied: pyyaml in /Users/marcos/.virtualenvs/pyinstamation/lib/python3.6/site-packages (5.1)
Then I run to the python shell and try to import the module:
In [1]: import yaml
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-38c9922a026e> in <module>
----> 1 import yaml
ModuleNotFoundError: No module named 'yaml'
Thanks for the answer!
The same issue:
➜ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.4
BuildVersion: 18E226
➜ python --version
Python 2.7.15
➜ pip show pyyaml
Name: PyYAML
Version: 5.1
Summary: YAML parser and emitter for Python
Home-page: https://github.com/yaml/pyyaml
Author: Kirill Simonov
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python2.7/site-packages
Requires:
Required-by:
>>> import yaml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named yaml
The module was installed using - pip install pyyaml
Hi, I got same issue. Already installed with pip install pyyaml but got error when import yaml.Could someone give an advice for this?
I had the same issue, pyyaml showing as installed but throwing the "no module" error.
This fix worked for me :)
sudo easy_install pip
sudo python -m pip install pyyaml
This is a common issue with Macs that has nothing to do with pyyaml- need to read up on system Python vs user Python and make sure you're using the right tools for the right Python version.
Hi @nitzmahone ,
is it just macs? As I'm getting this error on Ubuntu 16 when trying to run a cmake file.
I also ran python3 -m pip install pyyaml to install it but it said the requirement has already been satisfied.
Any advice would be appreciated! Thanks for your help so far!
Hi @nitzmahone,
I was having the issue on Raspbian Stretch, the fix I posted above might help you. :)
Im having the same issue too on CentOS 7.7
This isn't just a Mac issue; this probably shouldn't have been closed - this happens on epel yum-based environments as well, using virtualenv. I cannot, and will not, install this at the root level. I'm using --user, and it "successfully" installs, but still can't be found.
I had the same issue, pyyaml showing as installed but throwing the "no module" error.
This fix worked for me :)
sudo easy_install pip
sudo python -m pip install pyyaml
@tsal well I didn't say it would work for everyone LOL ! Agreed it should be still open
It's not just a Mac issue, but it's extremely common on Macs (thanks Homebrew Python!), and has nothing to do with pyyaml. The issue is mismatched Python tools, where different tools are targeting different site-packages directories (eg, your easy_install probably targets a different Python environment than python does). Go look at any well-used Python library's issue list, and you'll find people asking this same question. There's nothing the projects can do to improve the situation, so the issues get closed.
Hi guys, I had to do some digging (trial and error honestly), and by ripping out pyyaml multiple times, I finally found a version that works for my specific project.
My suggestion: if the specific pyyaml version is specified by the project that you are working on, you should install it via pip, pip3 or conda via the command:
pip install pyyaml==X.XX
pip3 install pyyaml==X.XX
conda install pyyaml==X.XX
Replacing the "X.XX" with the version you need.
I really hope this helps anyone that might be suffering with the same issue. Also if the version is not specified, then work you way backwards from the newest version until you find the one that works.
Note that @mvmnt means == not = in the following:
pip install pyyaml=X.XX
pip3 install pyyaml=X.XX
conda install pyyaml=X.XX
Replacing the "X.XX" with the version you need.
This still did not work for me though (using venv on macOS Catalina via PyCharm IDE)
Hi @PsiPhiTheta, good spot as I totally made that same mistake myself, and still am.
Not certain how much help this would be for you but I was using a google cloud environment, Ubuntu os 16.04, One k80 Tesla gpu, intel broadwell processor, terminal based.
Hope this Helps.
sudo pip3 install pyyaml worked for me on the Raspberry Pi
I had this same error on Google Cloud Shell where I was running a pip install on a requirements file. The file had a typo on the final module and it seemed to mess up the install. Once I fixed the requirements and re-installed, the yaml import worked fine.
So I did some digging following what @nitzmahone said. This is how I fixed mine [There's obviously variations to this, the deal is to make sure the install location is included in your sys.path]:
Find out where pyyaml is currently installed. If you run pip install pyyaml, and it tells you where it's currently installed. E.g. for me it was /opt/anaconda3/lib/python3.7/site-packages, for OP it seems to be /Users/marcos/.virtualenvs/pyinstamation/lib/python3.6/site-packages
Add export PYTHONPATH='wherever pyyaml is currently installed' to your .bash_profile (I'm on mac)
Restart your terminal
Optional, confirm that path is now part of your sys.path through python repl for example
Retry whatever you were trying to do again.
So I did some digging following what @nitzmahone said. This is how I fixed mine [There's obviously variations to this, the deal is to make sure the install location is included in your
sys.path]:
- Find out where pyyaml is currently installed. If you run
pip install pyyaml, and it tells you where it's currently installed. E.g. for me it was/opt/anaconda3/lib/python3.7/site-packages, for OP it seems to be/Users/marcos/.virtualenvs/pyinstamation/lib/python3.6/site-packages- Add
export PYTHONPATH='wherever pyyaml is currently installed'to your.bash_profile(I'm on mac)- Restart your terminal
- Optional, confirm that path is now part of your
sys.paththrough python repl for example- Retry whatever you were trying to do again.
@hafbau Thank you. this worked
I saw in another post that it should be written like this, and it worked for me.
pip install PyYAML
For windows:
python -m pip install PyYAML
@DavidChuks @hafbau Yikes, please don't do it that way... That solution is just papering over the underlying configuration problem, and will break hard and weird, especially if the site-packages you munge into your PYTHONPATH is for a different Python version and includes native-compiled extensions (eg pyyaml + libyaml). You're basically saying "hey Python, if you can't find stuff in your own library dir, go dig around in this other random Python library dir", because the wrong pip was invoked when you originally installed it. Call the right pip and life is good.
For Python distributions that have a built-in pip (most, these days), the easiest way to make sure you're installing to the same place as the Python you're running is to invoke pip from the Python you're running, eg, if you're using /home/foo/bin/python3, do:
/home/foo/bin/python3 -m pip install pyyaml. That ensures that you're not running a pip from some other random place on your PATH that targets a different python, and that /home/foo/bin/python3 -c 'import yaml' will properly import the thing you just installed.
Also, read up on the use of --user with pip to avoid the need for global installation via sudo (unless that's really what you want to do). Again, none of this is specific to PyYAML, this is just standard Python packaging fun...
I'm going to lock this issue, since this really isn't the forum for debugging broken Python configs...
Most helpful comment
I had the same issue, pyyaml showing as installed but throwing the "no module" error.
This fix worked for me :)
sudo easy_install pipsudo python -m pip install pyyaml