vagrant/ansible: ImportError: No module named site - python

I am trying to start a vagrant vm and provision it using its ansible provisioner;
config.vm.provision "ansible" do |ansible|
ansible.limit = "all"
ansible.compatibility_mode = "2.0"
ansible.playbook = "ansible/install.yml"
end
the box is ubuntu/xenial64
Provisioning fails as follows:
==> default: Running provisioner: ansible...
default: Running ansible-playbook...
ImportError: No module named site
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
Host is Ubuntu 16.04.05 with ansible 2.7.0
I even tried to run a shell provisioner that installs python-minimal on the guest before executing ansible, but with no luck.
edit: in the mean time, on my controller:
/home/pkara/Desktop
$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>>
/home/pkara/Desktop
$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>>

Related

Ansible module issue with python3

Good afternoon, I have a pymongo module that I installed via pip3 and now I am trying to use it
- name: Create role for pbm
community.mongodb.mongodb_shell:
login_host: 10.0.44.40
eval: 'db.getSiblingDB ("admin"). createRole ({"role": "pbmAnyAction", "privileges": [{"resource": {"anyResource": true}, "actions": ["anyAction"] }], "roles": []}); '
vars:
ansible_python_interpreter: / usr / bin / python3
ignore_errors: yes
when: groups.mongodb.index (inventory_hostname) == 0
and everything works well on my local vagrant vm, but when I run it on the production vm, an error appears
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named pymongo.errors
fatal: [mongodb-01]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (pymongo) on superproduction-mongo-01's Python / usr / bin / python. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter "}
OS versions for vagrant and production are the same (centos 7)
python3 version output and import pymongo.errors from production vm
python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo.errors
>>>
from vagrant vm
python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo.errors
>>>
as you can see output the same
worked even though I didn't do anything

Emacs Doom Run Python in MacOS

System: macOS Mojave 10.14.6
Python3: Python 3.7.4
My emacs config ( according to https://github.com/hlissner/doom-emacs/issues/212 );
(setq python-shell-interpreter "/usr/local/bin/python3" flycheck-python-pycompile-executable "/usr/local/bin/python3")
Trying to use run-python in emacs doom. Having:
Python 3.7.4 (v3.7.4:e09359112e, Jul 8 2019, 14:54:52)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> python.el: native completion setup failed, <class 'ModuleNotFoundError'>: No module named 'readline'
Warning (python): Your ‘python-shell-interpreter’ doesn’t seem to support readline, yet ‘python-shell-completion-native-enable’ was t and "python3" is not part of the ‘python-shell-completion-native-disabled-interpreters’ list. Native completions have been disabled locally.
import readline works perfectly in python3 in terminal.
Default python 2.7.10 doesn't work too (no my emacs config).
Python 2.7.10 (default, Feb 22 2019, 21:55:15)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import codecs, os;__pyfile = codecs.open('''/var/folders/y3/g447wqxd4l97rk7th2fszwb00000gn/T/pyQo4DAR''', encoding='''utf-8''');__code = __pyfile.read().encode('''utf-8''');__pyfile.close();os.remove('''/var/folders/y3/g447wqxd4l97rk7th2fszwb00000gn/T/pyQo4DAR''');exec(compile(__code, '''/var/folders/y3/g447wqxd4l97rk7th2fszwb00000gn/T/pyQo4DAR''', 'exec'));
python.el: native completion setup failed, <type 'exceptions.Exception'>: libedit based readline is known not to work,
see etc/PROBLEMS under "In Inferior Python mode, input is echoed".
>>>
How to make emacs doom run python3 right?

Python logging module platform differences: OSX vs. Linux

Can anyone help me understand why python's logging module creates a StreamHandler on import, but only on some distributions? weird.. (note: happens on any python3)
On Mac
Python 3.5.6 (default, Dec 19 2019, 14:59:39)
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.8)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.getLogger().handlers
[<logging.StreamHandler object at 0x108fc2630>]
Linux:
Python 3.7.4 (default, Jan 3 2020, 19:27:19)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.getLogger().handlers
[]
>>>
I can't seem to find any explanation about this behavior difference!
EDIT:
A bit more investigation suggests that some module installed in the virtualenv is causing this behavior mismatch. I created a fresh one with the same python interpreter and no handler gets made. I'm trying to investigate which module seems to cause this.
This isn't actually a platform difference, but was a result of an installed library.
I filed the issue upstream https://github.com/stuaxo/vext/issues/63

How come I cannot run satchmo_check?

I'm stuck on step 1 of test and install the data here: http://www.satchmoproject.com/docs/dev/settings.html
When I try to run the command, I get the following error:
(pyweb27)user#mint ~/Documents/workspace/python/site $ python manage.py satchmo_check
Unknown command: 'satchmo_check'
Type 'manage.py help' for usage.
I do have satchmo installed:
(pyweb27)user#mint ~/Documents/workspace/python/site $ python
Python 2.7.5+ (default, Sep 19 2013, 13:48:49)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django; import satchmo_store;
>>> satchmo_store.get_version()
'0.9.3-pre hg-2553:76b7dccafc76'
Am I doing something wrong? How can I resolve this?

libsvm on linux - how to add path

I downloaded the tar file for libsvm, navigated to the python directory and ran the make command. This words and when I run python inside that same directory,
import svm
works just fine. But not in any other directory. What can I do to make this library accessible from any where? I know it has some thing to do with copying the path some where, but not sure since I'm a newbie at linux.
what linux distro are you on? on my Ubunto I just:
$ sudo apt-get install python-libsvm
...
$ python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import svm
>>>
$ cd /tmp
$ python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import svm
>>>

Categories