I am seeing the following error:
Traceback (most recent call last):
File "generateLDA.py", line 14, in <module>
config = yaml.load(fp, Loader = yaml.FullLoader)
AttributeError: module 'yaml' has no attribute 'FullLoader'
The FullLoader class is only available in PyYAML 5.1 and later. Version 5.1 was released on March 13, 2019 and has probably not filtered down to many distributions yet.
You can check the version of PyYAML by inspecting yaml.__version__:
Python 2.7.15 (default, Oct 15 2018, 15:24:06)
[GCC 8.1.1 20180712 (Red Hat 8.1.1-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>> yaml.__version__
'3.13'
If you are managing packages with pip, you can upgrade to the current release by running:
pip install -U PyYAML
In case someone wants to use older version of yaml(3.1)
import yaml
with open('filename.yaml') as parameters:
my_dict = yaml.safe_load(parameters)
I stumbled upon it while using rospy to run my packages.
pip install --ignore-installed PyYAML
sudo su
pip install --ignore-installed PyYAML -r requirements.txt
It worked perfectly for fail2ban-geo-exporter
Took hours to figure it out, now it runs under root & systemd
pip3 install -U PyYAML
worked for me on Linux machine.
if it was working earlier then please check whether the indentation of the file is somehow messed-up or not.
Related
I have cloned a repo (visdom) from github in order to make some contributions. In order to test my contributions, I tried to install the module within a conda env:
$ which pip
/home/jkarimi91/Apps/anaconda2/envs/visdom/bin/pip
$ pip install -e .
Running pip list shows that the module successfully installed:
visdom (0.1.4, /home/jkarimi91/Projects/visdom)
However, when I try to import the module, I receive an import error:
$ which python
/home/jkarimi91/Apps/anaconda2/envs/visdom/bin/python
$ python
Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import visdom
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named visdom
>>>
You could use the -t flag is used to tell pip to install the packages into a particular location, however, there actually appears to be an open issue with -t not playing nice with various other flags (and I just confirmed this for the repo in question). Work around this by installing with the git URL syntax, e.g. pip install git+git://github.com/facebookresearch/visdom.git#master#egg=visdom
As pointed out by Jmills comment, the path /home/jkarimi91/Projects/ was not in my python path. Also, as noted by #Jmills answer, using -t does not seem to be a viable option at the moment.
To fix this issue, I did the following:
$ pip uninstall visdom
$ pip install .
This approach needs to be repeated every time I make a change to the code but at least it works.
I wrote a command line tool with cliff 2.3.0, tested on my laptop (Mac, Python 2.7.12). When I was tried to install it (python setup.py install) on a server (Linux, Python 2.7.2), I encountered this error:
Installed /private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-py2.7.egg
ERROR:root:Error parsing
Traceback (most recent call last): File "/private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-> py2.7.egg/pbr/core.py", line 111, in pbr
attrs = util.cfg_to_args(path, dist.script_args) File "/private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-py2.7.egg/pbr/util.py", line 248, in cfg_to_args
kwargs = setup_cfg_to_setup_kwargs(config, script_args) File "/private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-py2.7.egg/pbr/util.py", line 431, in setup_cfg_to_setup_kwargs
if pkg_resources.evaluate_marker('(%s)' % env_marker):
AttributeError: 'module' object has no attribute 'evaluate_marker' error: Setup script exited with error in setup command: Error parsing /private/tmp/easy_install-EGMO15/cliff-2.3.0/setup.cfg: AttributeError: 'module' object has no attribute 'evaluate_marker'
Any suggestions?
It looks like your server may have a (much) older version of the setuptools package installed (which provides the pkg_resources module). The evaluate_marker method looks as if it first showed up at the end of 2014, so if you're using an older system it is possible that method is not available.
Depending on your environment, you may be able to simply pip install -U setuptools, or you may need to see if your distribution has a newer isntallable package available.
If you can update your question to include details about your server's operating environment (what distribution and version are you running? What version of Python? What version of setuptools?), we can probably provide a more complete answer.
Update
For example, Ubuntu 12.04 only has setuptools 0.6, and the pkg_resources module (which is packaged in the python-pkg-resources package) does not have the evaluate_marker method:
# python
Python 2.7.3 (default, Jun 22 2015, 19:33:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.evaluate_marker
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'evaluate_marker'
In this environment, I can install pip:
# apt-get install python-pip
And then upgrade the installed version of setuptools:
# pip install -U setuptools
And now:
# python
Python 2.7.3 (default, Jun 22 2015, 19:33:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.evaluate_marker
<function evaluate_marker at 0x1535050>
>>>
NB Upgrading distribution packages (e.g., things installed by apt-get in this example) using pip can often lead to sadness and heartache, and you are much better off if you are able to upgrade the underlying environment to one where such workarounds are not necessary. Alternatively, running your code from a Python virtual environment (so that your upgraded packages do not override system packages) is also a technically better solution.
This all began when I set out to install the Requests library for Python 3 (I'm running on OSX Mavericks with Python 2.7.5 (installed by brew install python) and 3.4.2 (installed by brew install python3). When I run pip3 --version (or anything related to the pip3 command) I see this:
$ pip3 --version
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip import main
File "/usr/local/lib/python3.4/site-packages/pip/__init__.py", line 11, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/lib/python3.4/site-packages/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/local/lib/python3.4/site-packages/pip/download.py", line 22, in <module>
from pip._vendor import requests, six
File "/usr/local/lib/python3.4/site-packages/pip/_vendor/requests/__init__.py", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/usr/local/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py", line 49, in <module>
from ndg.httpsclient.ssl_peer_verification import SUBJ_ALT_NAME_SUPPORT
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/ndg/httpsclient/ssl_peer_verification.py", line 17
except ImportError, e:
^
SyntaxError: invalid syntax
When I run the Python 2.7.5 version I see this:
$ pip --version
pip 1.5.6 from /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg (python 2.7)
Just for sanity purposes Here is what when I see when I enter the interactive interpreters:
$ python3
Python 3.4.2 (default, Oct 19 2014, 17:52:17)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
A lot of the other answers related to updating pip3 suggest that I update pip3 with this commend pip3 install --upgrade pip which gives the same error, or I use easy_install -U pip but because of how brew sets up the Pythons, it only updates the Python 2.7.5 version (there is no easy_install3). Any ideas?
The root problem is that you somehow got a Python 2.x-only package installed into your 3.x site-packages.
Underlying that, you've actually got two different Python 2.7 installations (Apple's and Homebrew's) crossed with each other, which may have something to do with how you got a 2.7 package into 3.x as well…
Anyway, the reason this is breaking pip is that pip has various optional dependencies that it tries to import if present, and some of them do the same, and so on, and ultimately, starting up pip is importing the ndg-httpsclient package.
I'm not sure how you got that package. A standard Homebrew 3.x looks in two extra site-packages directories (fire up python3 then import sys; print(sys.path) to see all of the places it looks, both stdlib and site) beyond the one that pip3 installs into.
In this case, you've somehow installed the 2.x version of ndg-httpsclient into /usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages.
Since you didn't install it with pip—and, more to the point, since you can't run pip in the first place—you can't just pip uninstall it. So:
rm -rf /usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/ndg*
This could break some other packages that depend on it. Once you get things working, you can use pip3 list to see all the site packages you've installed and test them out. If you want to be paranoid, do something like this:
$ pip3 list > mypackages
$ rm -rf <each site-package directory>
$ brew uninstall python3
$ brew install python3
$ pip3 install -r mypackages
You might want to similarly clean up your Homebrew 2.7 (or just scrap it and only use Apple's—especially since I'm pretty sure you're running Apple's anyway), and the site-packages for the Apple 2.7 (but not Apple's Python itself, of course, because you can't uninstall that).
I’m sure this is obvious, but I’m missing it. I’ve installed PyAPNs via pip:
# pip install apns
Then when I try to use the “enhanced” flag in APNs, it’s not there.
# python
Python 2.7.6 (default, Nov 11 2013, 18:34:29)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from apns import APNs
>>> server = APNs(use_sandbox=True, cert_file=“/mydir/apns-dev-cert.pem", key_file=“/mydir/apns-dev-key.pem", enhanced=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'enhanced'
>>>
And sure enough the 1.1.2 version that pip installed doesn’t have that keyword. But I thought this was the latest released version in the PyAPNs repository https://github.com/djacobs/PyAPNs.
I want to use the ‘enhanced’ keyword, for error checking. Any ideas?
Version 1.1.2 that is currently available on PyPI doesn't provide an enhanced argument for APNs class (see source).
If you want this functionality, install the module directly from github (master branch):
pip install git+https://github.com/djacobs/PyAPNs.git
Note that they haven't updated the package version in setup.py, so, if you have this module installed already, uninstall it first, then install it from github:
pip uninstall apns
pip install git+https://github.com/djacobs/PyAPNs.git
if you want more error-free version, you may try this fork
pip install git+https://github.com/jimhorng/PyAPNs.git
which resolved errors from long idle connections:
https://github.com/djacobs/PyAPNs/issues/94
I am doing a course on udacity where I need need to install twilio for python. I have sucessfully installed but still i get import error
Any pointers or help will be useful:
abhinav#abhinav-HP-Pavilion-dv5-Notebook-PC:~$ which -a python
/usr/local/bin/python
/usr/bin/python
abhinav#abhinav-HP-Pavilion-dv5-Notebook-PC:~$ which -a pip
/usr/bin/pip
abhinav#abhinav-HP-Pavilion-dv5-Notebook-PC:~$ pip freeze|grep twilio
Warning: cannot find svn location for distribute==0.6.24dev-r0
twilio==3.6.6
abhinav#abhinav-HP-Pavilion-dv5-Notebook-PC:~$ pip install --upgrade twilio
abhinav#abhinav-HP-Pavilion-dv5-Notebook-PC:~$ sudo pip install --upgrade twilio
abhinav#abhinav-HP-Pavilion-dv5-Notebook-PC:~$ python
Python 2.7.6 (default, Mar 16 2014, 19:06:43)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
</code>
>>> import twilio
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named twilio
>>>
You have two python installs, your pip is pointing to /usr/bin so and your default python is in /usr/local/bin.
You can remove the /usr/bin/pip and install pip get-pip.py, which will use your now default /usr/local/bin/python.
It would probably be best to remove one of the python installs and set your paths accordingly.
Just be careful when removing python, it can be detrimental to your system if you mess up your python install.