I'm writing a script in python to update some YAML config files containing jinja2. I found this answer showing how to do it using ruamel.yaml and ruamel.yaml.jinja2 packages and it works absolutely fine on windows10 using this configuration:
$ python -V
Python 2.7.5
$ python -m pip list
[...]
ruamel.ordereddict 0.4.13
ruamel.yaml 0.15.94
ruamel.yaml.jinja2 0.2.2
[...]
and this code:
from ruamel.yaml import YAML
yamlLoader = YAML(typ='jinja2')
But when I try to use it on a CentOS virtual machine, which is the target environment for this script, I get this error:
File "/opt/salt/mig/cnamts_migrate.py", line 17, in <module>
yamlLoader = YAML(typ='jinja2')
File "/usr/lib64/python2.7/site-packages/ruamel/yaml/main.py", line 138, in __init__
'typ "{}"not recognised (need to install plug-in?)'.format(self.typ)
NotImplementedError: typ "jinja2"not recognised (need to install plug-in?)
I can't find any difference in neither Python configuration nor packages' version.
On CentOS VM:
$ python -V
Python 2.7.5
$ pip list
Package Version
---------------------------- -----------
pip 19.1
ruamel.ordereddict 0.4.13
ruamel.yaml 0.15.94
ruamel.yaml.jinja2 0.2.2
setuptools 41.0.1
This path
/usr/lib64/python2.7/site-packages/ruamel/yaml/main.py
in the error message gives me the impression that you are using a system wide Python installation. You should (IMHO even in a VM) use python virtualenv for any utility (and preferaby one per non-related utility). You don't show the output of pip for your CentOS machine, which is way more interesting than the one on your Windows box.
$ more /etc/centos-release
CentOS Linux release 7.3.1611 (Core)
$ /opt/python/3.7/bin/python -m venv /tmp/so-55900745
$ source /tmp/so-55900745/bin/activate
(so-55900745) $ pip install ruamel.yaml.jinja2
Collecting ruamel.yaml.jinja2
Downloading https://files.pythonhosted.org/packages/4f/b4/9676d4fa53d921f98f40dcda2ecfdb9fba2b68fbdccec3d9d4d2c87d96a7/ruamel.yaml.jinja2-0.2.2-py2.py3-none-any.whl
Collecting ruamel.yaml>=0.15.10 (from ruamel.yaml.jinja2)
Downloading https://files.pythonhosted.org/packages/bb/e3/8c06f90dab796bd5baf5da2482cf919bab3145389196814ec3180d4c7bd5/ruamel.yaml-0.15.94-cp37-cp37m-manylinux1_x86_64.whl (647kB)
100% |████████████████████████████████| 655kB 9.3MB/s
Installing collected packages: ruamel.yaml, ruamel.yaml.jinja2
Successfully installed ruamel.yaml-0.15.94 ruamel.yaml.jinja2-0.2.2
(so-55900745) $ pip list
Package Version
------------------ -------
pip 19.1
ruamel.yaml 0.15.94
ruamel.yaml.jinja2 0.2.2
setuptools 40.8.0
(so-55900745) $ python
Python 3.7.3 (default, Apr 3 2019, 11:33:06)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ruamel.yaml import YAML
>>> yamlLoader = YAML(typ='jinja2')
>>> exit()
(so-55900745) $ deactivate
$ rm -rf /tmp/so-55900745/
$ virtualenv -p /opt/python/2.7/bin/python /tmp/so-55900745
Running virtualenv with interpreter /opt/python/2.7/bin/python
New python executable in /tmp/so-55900745/bin/python
Installing setuptools, pip, wheel...
done.
$ source /tmp/so-55900745/bin/activate
(so-55900745) $ pip install ruamel.yaml.jinja2
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.
Collecting ruamel.yaml.jinja2
Using cached https://files.pythonhosted.org/packages/4f/b4/9676d4fa53d921f98f40dcda2ecfdb9fba2b68fbdccec3d9d4d2c87d96a7/ruamel.yaml.jinja2-0.2.2-py2.py3-none-any.whl
Collecting ruamel.yaml>=0.15.10 (from ruamel.yaml.jinja2)
Downloading https://files.pythonhosted.org/packages/a2/59/e8cb144511e47e068efdb71a85f35d00b32fc5f05a9e9a17df265ec252b5/ruamel.yaml-0.15.94-cp27-cp27mu-manylinux1_x86_64.whl (600kB)
|████████████████████████████████| 604kB 2.0MB/s
Collecting ruamel.ordereddict; platform_python_implementation == "CPython" and python_version <= "2.7" (from ruamel.yaml>=0.15.10->ruamel.yaml.jinja2)
Downloading https://files.pythonhosted.org/packages/f3/2c/fa6d75dc459b371ed3b88fdbf8042785ce1655073c884fd97bdbb9f48e01/ruamel.ordereddict-0.4.13-cp27-cp27mu-manylinux1_x86_64.whl (99kB)
|████████████████████████████████| 102kB 12.7MB/s
Installing collected packages: ruamel.ordereddict, ruamel.yaml, ruamel.yaml.jinja2
Successfully installed ruamel.ordereddict-0.4.13 ruamel.yaml-0.15.94 ruamel.yaml.jinja2-0.2.2
(so-55900745) $ python
Python 2.7.15 (default, Aug 10 2018, 11:41:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ruamel.yaml import YAML
>>> yamlLoader = YAML(typ='jinja2')
>>> exit()
(so-55900745) $ deactivate
I ran into the same error message. but with python3.6.
The fix for me was to pip instead of easy_install.
Here's the easy_install related output:
(env) $ easy_install -q ruamel.yaml.jinja2
(env) $ easy_install -q ruamel.yaml
(env) $ python
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ruamel.yaml import YAML
>>> yamlLoader = YAML(typ='jinja2')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "REDACTED/env/lib/python3.6/site-packages/ruamel.yaml-0.15.96-py3.6-linux-x86_64.egg/ruamel/yaml/main.py", line 138, in __init__
'typ "{}"not recognised (need to install plug-in?)'.format(self.typ)
NotImplementedError: typ "jinja2"not recognised (need to install plug-in?)
Here's the same thing installing with pip:
(env) $ pip -q install ruamel.yaml.jinja2
(env) $ pip -q install ruamel.yaml
(env) $ python
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ruamel.yaml import YAML
>>> yamlLoader = YAML(typ='jinja2')
>>> print("¯\_(ツ)_/¯")
¯\_(ツ)_/¯
If you are using a setup.py in your project, check out Can I use `pip` instead of `easy_install` for `python setup.py install` dependency resolution?
Related
I want to install python2.7 by conda as follows command:
conda create -n tensorflow python=2.7 anaconda
But it is missing of dbm module.
$ python
Python 2.7.15 | packaged by conda-forge | (default, Jul 2 2019, 00:39:44)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named dbm
>>> import Tkinter
>>>
Then I try to install python-gdbm suggestion by google and stackoverflow.
$ conda install -n tensorflow -c anaconda python-gdbm
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /public/home/miniconda2/envs/tensorflow
added / updated specs:
- python-gdbm
The following packages will be downloaded:
package | build
---------------------------|-----------------
certifi-2019.11.28 | py27_0 156 KB anaconda
python-gdbm-1.1 | py27_0 21 KB anaconda
------------------------------------------------------------
Total: 177 KB
The following NEW packages will be INSTALLED:
gdbm anaconda/linux-64::gdbm-1.12-0
python-gdbm anaconda/linux-64::python-gdbm-1.1-py27_0
The following packages will be UPDATED:
openssl conda-forge::openssl-1.1.1d-h516909a_0 --> anaconda::openssl-1.1.1-h7b6447c_0
The following packages will be SUPERSEDED by a higher-priority channel:
ca-certificates conda-forge::ca-certificates-2019.11.~ --> anaconda::ca-certificates-2019.11.27-0
certifi conda-forge --> anaconda
Proceed ([y]/n)? y
Downloading and Extracting Packages
python-gdbm-1.1 | 21 KB | ################################################################################################################################ | 100%
certifi-2019.11.28 | 156 KB | ################################################################################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Unfortunately, I still have the same error when import dbm.
Any help is much appreciated.
Thanks.
AFAIK, there are no Anaconda (or Conda Forge) Python 2.7 builds that support the dbm module for Linux (e.g., see this issue). The anaconda::python-gdbm package should provide the functionality, but the import will be:
import gdbm
In order to install the Python module hidapi: I installed python 2.7 with home-brew:
brew install python2
I think it installed 2.7.15. Python information:
Users-MacBook-Air:~ user$ python -V
Python 2.7.10
Users-MacBook-Air:~ user$ which python
/usr/bin/python
I believe 2.7.10 was already installed (Apple OEM?).
The OS X command:
pip install hidapi
Indicates:
Requirement already satisfied: hidapi in
/usr/local/lib/python2.7/site-packages (0.7.99.post21) Requirement
already satisfied: setuptools>=19.0 in
/usr/local/lib/python2.7/site-packages (from hidapi) (39.1.0)
Attempts to import HID from the Python command line results in error:
>>> import hid
Traceback (most recent call last): File "", line 1, in
ImportError: No module named hid
There may be more than one version of 2.7 installed (2.7.15?).
How can I test if a newer (second Python instance of 2.7.X) was installed today?
How can I invoke Python 2.7.15 if was installed today?
How can 2.7.10 be granted visibility to the hid module?
It I can invoke Python 2.7.15 and try to import the hid module, that should inch the troubleshooting process along.
UPDATE
Users-MacBook-Air:~ user$ python2
Python 2.7.15 (default, May 1 2018, 16:44:14)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import hid
>>>
ONLY 2.7.15 has 'hid' visibility: the other two versions return an error.
Users-MacBook-Air:~ user$ python -V
Python 2.7.10
Users-MacBook-Air:~ user$ python2 -V
Python 2.7.15
Users-MacBook-Air:~ user$ python2.7 -V
Python 2.7.10
All pip references lead to the same place:
Users-MacBook-Air:~ user$ pip -V
pip 10.0.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
Users-MacBook-Air:~ user$ pip2 -V
pip 10.0.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
Users-MacBook-Air:~ user$ pip2.7 -V
pip 10.0.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
I think you've figured out the other questions, but
How can 2.7.10 be granted visibility to the hid module
You would need to install it using pip via easy_install however adding libraries into your system Python is usually frowned upon, which is why virtualenv's exist, but, you would need to install that module as well
Besides that, Python3 should generally be used for any new Python development
I installed anaconda2 over python 2.7 and i am on Windows 10.
when I am trying to use pip , Syntax error is coming. I am using basic cmd to access pip , even without the environment variable thing , it's not working .
Can anybody explain what am I doing wrong ?
Error:
C:\Users\Yash gupta\Anaconda2\Scripts>python
Python 2.7.13 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:17:26) [MSC v.1500 64 bit (AMD64)] on win32
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
>>> pip install bs4
File "<stdin>", line 1
pip install bs4
^
SyntaxError: invalid syntax
>>>
you are using pip in python environment.
You must quit python and run pip install bs4 with the shell.
If you want to install the library only in a specific anaconda environment, lunch the source activate <yourEnv> command and then use pip install.
I have various versions of python (python2.4 and python2.7) installed on the CentOS machine. I installed MySQL-python, but I can only import the MySQLdb module on python2.4 but not python2.7
root# python2.7
Python 2.7.11 |Continuum Analytics, Inc.| (default, Dec 6 2015, 18:08:32)
[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 MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
root# python
Python 2.4.3 (#1, Mar 5 2011, 21:26:05)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>
I've tried alias'ing python to /usr/bin/python2.7 and then doing a 'yum remove MySQL-python' and then doing a 'yum install MySQL-python' but no luck. Any clues/insights? Thanks.
The yum will install the MySQL-python to the system default python's directory.
maybe you can try virtualenv and pip.
install the pip
pip install virtualenv
virtualenv -p /the/localtion/of/python27 python27
active the new python envirement, and pip install MySQL-python
I have installed eventlet library in python using : pip install eventlet. But when I tried to import eventlet this error occured:
$python
Python 2.7.10 (default, Oct 23 2015, 18:05:06)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import eventlet
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named eventlet
I tried to install it again but I got this :
$pip install eventlet
Requirement already satisfied (use --upgrade to upgrade): eventlet in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/eventlet-0.18.1-py3.5.egg
Requirement already satisfied (use --upgrade to upgrade): greenlet>=0.3 in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/greenlet-0.4.9-py3.5-macosx-10.6-intel.egg (from eventlet)
How to rectify this error?
P.S : I am using Python 2.7
This question is not specific to Eventlet, it's just about managing multiple versions of Python on OSX.
Your pip command installed eventlet into /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5, see version.
It means you actually have two Python versions installed: 2.7 and 3.5 and pip works with 3.5.
Your options:
(recommended) use separate virtualenv [1] for every project, explicitly specify python version when creating virtualenv using virtualenv --python=python2.7 /path/to/new/venv
run python3 and use eventlet in latest Python
run pip2 install eventlet
symlink pip to pip2 ln -snf $(which pip2) $(which pip)
[1] http://docs.python-guide.org/en/latest/dev/virtualenvs/
You may also use
$py -2 -m pip install eventlet
It worked for me in Windows 10.
$pip install eventlet
This worked for me in windows10