tomcat user python module not found - python

tomcat user or for that matter any user using python2 or python3 is unable to find boto3 module, whereas in running python2 or 3 from root works fine.
-bash-4.2$ python
Python 2.7.5 (default, Nov 16 2020, 22:23:17)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named boto3
>>>
-bash-4.2$ whoami
tomcat
root user works
[root#server-name]# python
Python 2.7.5 (default, Nov 16 2020, 22:23:17)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
>>>

Related

Error finding the python modules/libraries from the /home/ubuntu location

I have been trying on setup PIL module on my Ubuntu System and it has been giving a lots of error. Finally , i am getting issue as:
when i try to run python from /home/ubuntu, it gives me error as:
ubuntu#ip-<server>:~$ python
Python 2.7.12 (default, Apr 15 2020, 17:07:12)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "PIL/Image.py", line 90, in <module>
from . import _imaging as core
ImportError: cannot import name _imaging
but if I run the code from /usr/local, it does not return any error:
ubuntu#ip-<server>:~$ cd /usr/local/
ubuntu#ip-<server>:/usr/local$ python
Python 2.7.12 (default, Apr 15 2020, 17:07:12)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>>
there might be an issue with the path or the permission of the required libraries. But i am not sure how to fix this.
I am executing my script from Jenkins and it throws error over there. Please guide how to fix.

Twilio only runs from my Python 3.7 directory on OS X

I installed Twilio:
pip3 install twilio
But it will run only from the Python 3 Applications folder.
// ♥ python3
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more
information.
>>> import twilio
>>> print(twilio.__version__)
6.21.0
Here is what I get from any other folder:
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import twilio
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/davidtannenbaum/Dropbox (Personal)/pythonpractice/twilio.py", line 2, in <module>
print(twilio.__version__)
AttributeError: module 'twilio' has no attribute '__version__'
Anyone know why it works in the Python 3.7 directory and gives an error anywhere else? How do I fix this?

python-whois , difference between python 2.7.6 and 2.7

I have bellow function running on Python 2.7.6 and python 2.7.5
This is 2.7.6
[root#NMCT-MSL-116-1 python_whois-0.2-py2.6.egg-info]# python
Python 2.7.6 (default, Sep 26 2014, 13:25:30)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import whois as wh
>>> wh.whois('199.96.57.7').emails
['mathew#twitter.com', 'sleibrand#twitter.com', 'noc#twitter.com', 'sconnor#twitter.com',
'rjohnson#twitter.com', 'fawad#twitter.com', 'net-abuse#twitter.com']
This is 2.7.5
Python 2.7.5 (default, Jun 17 2014, 18:11:42)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import whois as wh
>>> wh.whois('199.96.57.7').emails
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/whois/__init__.py", line 11, in whois
domain = extract_domain(url)
File "/usr/lib/python2.7/site-packages/whois/__init__.py", line 35, in extract_domain
return socket.gethostbyaddr(url)[0]
socket.herror: [Errno 1] Unknown host
It is same code 2 different Centos versions. First one is 6.5, custom python installation of 2.7.6. Second one is Centos 7 and 2.7.5 default installation. When i manually check both servers can find this host with whois cli tool.
I got stuck and I could not find what is the difference between both machines. They are based on same Network subnet, using same network config except IP addresses.
Does this a difference between versions ? Does anybody has an idea about this ?

Cannot use Python select.poll in Mac OS?

$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import select
>>> select.poll
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'poll'
Instead of using poll, use select.kqueue() on OSX. It's similar to 'epoll' on Linux in that you can more efficiently register for types of file-descriptor / file system events which can be used in asynchronous code. Much more efficient than polling.
Otherwise, the equivalent is just running a blocking select.select() inside a while True: loop with some sort of timeout?
If you want to use poll in order to not rewrite a bunch of code for kqueue, it is built in to the python compiled from macports (macports.org). You just must specify that python instance explicitly (/opt/local/bin/python2.7 in my case) because OSX's python (/usr/bin/python) will by default be earlier in the search path.
Interestingly for future reference, this only comes up with a limited subset of the versions of python
user#hostname:~/ws/engine$ python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import select
>>> select.poll()
<select.poll object at 0x102415cc0>
>>> exit()
user#hostname:~/ws/engine$ python --version
Python 2.7.9
user#hostname:~/ws/engine$ workon py_2_7_10
(py_2_7_10) user#hostname:~/ws/engine$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[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 select
>>> select.poll()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'poll'
>>>
~/ws/engine$ uname -a
Darwin hostname 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64

Non-reproducible ImportError

I get an ImportError when I run a script that I can't reproduce in a Python interpreter.
$ head -6 bin/taglint
#!/usr/bin/env python
#
import re
from lsaf.lsaf import file_info, error, exit
$ taglint
Traceback (most recent call last):
File "/home/ernest/bin/taglint", line 5, in <module>
from lsaf.lsaf import file_info, error, exit
ImportError: No module named lsaf
However, the import works fine in an interpreter:
$ /usr/bin/env python
Python 2.7.3rc2 (default, Apr 22 2012, 22:30:17)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from lsaf.lsaf import file_info, error, exit
>>>
What is happening here?
Additional info:
Python 2.7.3rc2 (default, Apr 22 2012, 22:30:17)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lsaf; print(lsaf)
<module 'lsaf' from '/home/ernest/lib/python/lsaf/__init__.pyc'>
The PYTHONPATH environment variable is set to PYTHONPATH=/home/ernest/lib/python.
It might be an issue with sys.path
check your lsaf
May beYou didn't name your script by lsaf.py
rename it and it will work, your script tries to import itself, but there is no package in lsaf in your own script. importception

Categories