Why are python-modules not working as superuser? - python

I have trouble running a (working) python-script as the user www-data on a standard Raspi4-Debian-installation, which is necessary, since I want to run it from a php-file. I found a lot of questions regarding the same here, but I can't get it to work sadly. I'd be happy if somebody could help.
So, when I run my python-script on the commandline as myself it works perfectly.
When I start it with "sudo" oder "sudo -u www-data" I get the following error:
File "/usr/local/lib/python3.9/dist-packages/firebase_admin/firestore.py", line 22, in <module>
from google.cloud import firestore # pylint: disable=import-error,no-name-in-module
File "/usr/local/lib/python3.9/dist-packages/google/cloud/firestore.py", line 18, in <module>
from google.cloud.firestore_v1 import __version__
File "/usr/local/lib/python3.9/dist-packages/google/cloud/firestore_v1/__init__.py", line 30, in <module>
from google.cloud.firestore_v1._helpers import GeoPoint
File "/usr/local/lib/python3.9/dist-packages/google/cloud/firestore_v1/_helpers.py", line 22, in <module>
from google.api_core import gapic_v1 # type: ignore
File "/usr/local/lib/python3.9/dist-packages/google/api_core/gapic_v1/__init__.py", line 16, in <module>
from google.api_core.gapic_v1 import config
File "/usr/local/lib/python3.9/dist-packages/google/api_core/gapic_v1/config.py", line 23, in <module>
import grpc
File "/usr/local/lib/python3.9/dist-packages/grpc/__init__.py", line 22, in <module>
from grpc import _compression
File "/usr/local/lib/python3.9/dist-packages/grpc/_compression.py", line 15, in <module>
from grpc._cython import cygrpc
ImportError: /usr/local/lib/python3.9/dist-packages/grpc/_cython/cygrpc.cpython-39-arm-linux-gnueabihf.so: undefined symbol: __atomic_exchange_8
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/www/html/private/./weddingr_uploader2.py", line 26, in <module>
from firebase_admin import credentials, initialize_app, storage, firestore
File "/usr/local/lib/python3.9/dist-packages/firebase_admin/firestore.py", line 28, in <module>
raise ImportError('Failed to import the Cloud Firestore library for Python. Make sure '
ImportError: Failed to import the Cloud Firestore library for Python. Make sure to install the "google-cloud-firestore" module.
So I researched and thought: "okay, the user www-data" can't access the module google-cloud-firestore". I tried to deinstall it with
sudo pip3 uninstall google-cloud-firestore"
and installing it again with
sudo pip3 install google-cloud-firestore"
Although it tells me uninstall is successfull, when I install it again, it tells me, the requirement is already satisfied:
...
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /usr/local/lib/python3.9/dist-packages (from pyasn1-modules>=0.2.1->google-auth<3.0dev,>=1.25.0->google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.5->google-cloud-firestore) (0.4.8)
Installing collected packages: google-cloud-firestore
Successfully installed google-cloud-firestore-2.5.3
I am running out of ideas, how to deinstall the module as my user and install it with su-rights in the correct path. Has somebody a hint in the right direction for me? Thanks!

Related

Importing pysftp issue

I am facing this error every time I try to import pysftp in my training.py in the ml.azure.com pipelines. I am using Conda to create the environment for the workspace.
Traceback (most recent call last):
File "start_training.py", line 18, in <module>
import pysftp
File "/azureml-envs/azureml_8b4da5162aa2d3fe6990b8afc7945879/lib/python3.7/site-packages/pysftp/__init__.py", line 12, in <module>
import paramiko
File "/azureml-envs/azureml_8b4da5162aa2d3fe6990b8afc7945879/lib/python3.7/site-packages/paramiko/__init__.py", line 22, in <module>
from paramiko.transport import SecurityOptions, Transport
File "/azureml-envs/azureml_8b4da5162aa2d3fe6990b8afc7945879/lib/python3.7/site-packages/paramiko/transport.py", line 89, in <module>
from paramiko.dsskey import DSSKey
File "/azureml-envs/azureml_8b4da5162aa2d3fe6990b8afc7945879/lib/python3.7/site-packages/paramiko/dsskey.py", line 37, in <module>
from paramiko.pkey import PKey
File "/azureml-envs/azureml_8b4da5162aa2d3fe6990b8afc7945879/lib/python3.7/site-packages/paramiko/pkey.py", line 31, in <module>
import bcrypt
File "/azureml-envs/azureml_8b4da5162aa2d3fe6990b8afc7945879/lib/python3.7/site-packages/bcrypt/__init__.py", line 25, in <module>
from . import _bcrypt # type: ignore
ImportError: libffi.so.7: cannot open shared object file: No such file or directory
What I tried and failed:
I also tried to import the older version of pysftp which doesn't have dependency on libffi.so,
I tried with several versions of pysftp.
I tried installing the dependencies of pysftp.
I tried installing paramiko separately with current and older version.
I tried installing the bcrypt with current and older version.
I tried installing libffi.so with current and older version.
I tried creating new environments.
I tried by updating conda and pip also.
I tried to create simlink between libffi.so.6 and libffi.so.7 also.
So far, nothing works.
Help needed on this.

"No module named zlib" error anytime I use pip

I'm using terminal on mac, and anytime I attempt to use pip, I get the following error message telling me that it cannot find a module named zlib:
$ pip --version
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/__init__.py", line 27, in <module>
from . import urllib3
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 42, in <module>
from .response import HTTPResponse
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/response.py", line 3, in <module>
import zlib
ModuleNotFoundError: No module named 'zlib'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/bin/pip", line 7, in <module>
from pip import main
File "/usr/local/lib/python3.6/site-packages/pip/__init__.py", line 21, in <module>
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/__init__.py", line 62, in <module>
from .packages.urllib3.exceptions import DependencyWarning
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/__init__.py", line 29, in <module>
import urllib3
File "/usr/local/lib/python3.6/site-packages/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 36, in <module>
from .response import HTTPResponse
File "/usr/local/lib/python3.6/site-packages/urllib3/response.py", line 3, in <module>
import zlib
ModuleNotFoundError: No module named 'zlib'
I've read several SO posts with the same error message, and have tried their solutions, including attempting to install zlib using homebrew, which fails, and updating my Xcode developer tools. I also installed pip earlier using python get-pip.py, and it said it installed successfully.
The reason I need pip is to install a package for use on python 2.7, but doing $ pip install "package-name" produces the same error as above. I have both Python 2 and 3 installed on my machine, if that helps. I'm kind of new to pip and using the command line in general, and I'm super confused; if anyone could help me out I'd really appreciate it.
This is the OP. I was able to fix the issue, and wanted to post my solution here in case it would help others.
Essentially I believe it occurred because Python2 is default on my machine, but pip is by default pointing to resources pertaining to Python3, or something like that. Doing pip2 --version instead provided the expected response.

pip commands return a TypeError

I needed to install hashlib for one of my projects, and used easy_install hashlib (as was stated by this Stack Exchange post) to do so. However, right after I installed this package, I haven't been able to use pip at all. Whenever I type a command with pip (like pip install), I get the following error message:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 37, in <module>
import email.parser
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/feedparser.py", line 27, in <module>
from email import message
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/message.py", line 16, in <module>
import email.charset
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/charset.py", line 13, in <module>
import email.base64mime
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/base64mime.py", line 40, in <module>
from email.utils import fix_eols
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/utils.py", line 27, in <module>
import random
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 49, in <module>
import hashlib as _hashlib
File "build/bdist.macosx-10.13-intel/egg/hashlib.py", line 115, in <module>
"""
TypeError: 'frozenset' object is not callable
This also now occurs when I'm using easy_install- same error. I'm also not able to uninstall pip and reinstall- any command with pip results in the error above. Even executing
pip --version yields the same error. I know it's something to do with the hashlib package, but I'm not sure how to delete it and reinstall without messing up my entire Python configurations. My hypothesis is that the version of hashlib I installed is either too old or too new for my Python 2.7, and doesn't play well with it.
Does anyone know what exactly is going on behind the scenes here in this stack trace, and how I can fix pip?
Is the best thing to do to literally go in and delete hashlib.py from my lib/python2.7 folder?
So, this doesn't solve the issue with hashlib, but it does get you a working pip again: literally download and reinstall Python 2.7 all over again from the source. If anyone comes up with a better, more elegant solution for fixing pip, I am all for it.
However, at least I can use pip again...

failed to install hashlib in python3.5 - error code 1

I am trying to install hashlib on my mac. pip doesn't work, and easy_install also does not work.
Here is the error:
Collecting hashlib
Using cached hashlib-20081119.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/setuptools/__init__.py", line 12, in <module>
import setuptools.version
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/setuptools/version.py", line 1, in <module>
import pkg_resources
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pkg_resources/__init__.py", line 36, in <module>
import email.parser
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/feedparser.py", line 27, in <module>
from email import message
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/message.py", line 16, in <module>
from email import utils
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/utils.py", line 28, in <module>
import random
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/random.py", line 45, in <module>
from hashlib import sha512 as _sha512
File "/private/var/folders/nw/flrm4y0d499fk5xr2ppxk4sr0000gn/T/pip-build-lv720o4k/hashlib/hashlib.py", line 80
raise ValueError, "unsupported hash type"
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/nw/flrm4y0d499fk5xr2ppxk4sr0000gn/T/pip-build-lv720o4k/hashlib/
Any further suggestions would be great. Thanks in advance!
I know this question is very old, but I stumbled upon it on Google because I had the same problem just now. In my case, I was working with an AWS Elastic Beanstalk, and my environment got that exact same cryptic error message about a syntax error inside hashlib.
For AWS, the trick is NOT including all your imports in the requirements.txt file, but only things you would normally have to pip install. That includes modules like hashlib, string, and random.
So for others who stumble upon this question: there is no need to install hashlib, just import it and you're ready to go!
sudo apt-get install libffi-dev g++ libssl-dev
via https://github.com/bigchaindb/bigchaindb/issues/24#issuecomment-183370814

Ansible is not working on mac

I'm trying to execute ansible in my system. I guess I messed up something and unable to run ansible. When I run ansible --version, I see the following error:
krishnapatamset:bin krishna.patamsetti$ ansible --version
[WARNING]: log file at /var/log/ansible/ansible.log is not writeable and we cannot create it, aborting
ERROR! Unexpected Exception: No module named markupsafe
the full traceback was:
Traceback (most recent call last):
File "/usr/local/bin/ansible", line 80, in <module>
from ansible.cli.adhoc import AdHocCLI as mycli
File "/usr/local/lib/python2.7/site-packages/ansible/cli/adhoc.py", line 28, in <module>
from ansible.executor.task_queue_manager import TaskQueueManager
File "/usr/local/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 29, in <module>
from ansible.executor.play_iterator import PlayIterator
File "/usr/local/lib/python2.7/site-packages/ansible/executor/play_iterator.py", line 30, in <module>
from ansible.playbook.block import Block
File "/usr/local/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 27, in <module>
from ansible.playbook.play import Play
File "/usr/local/lib/python2.7/site-packages/ansible/playbook/play.py", line 27, in <module>
from ansible.playbook.base import Base
File "/usr/local/lib/python2.7/site-packages/ansible/playbook/base.py", line 29, in <module>
from jinja2.exceptions import UndefinedError
File "/usr/local/lib/python2.7/site-packages/jinja2/__init__.py", line 33, in <module>
from jinja2.environment import Environment, Template
File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 13, in <module>
from jinja2 import nodes
File "/usr/local/lib/python2.7/site-packages/jinja2/nodes.py", line 19, in <module>
from jinja2.utils import Markup
File "/usr/local/lib/python2.7/site-packages/jinja2/utils.py", line 531, in <module>
from markupsafe import Markup, escape, soft_unicode
ImportError: No module named markupsafe
Can anyone please help me with this situation. Thanks in advance
I even tried pip install markupsafe but still I am unable to get ansible working
Ansible is based on python and there is a python module that's missing called markupsafe
install it via pip, you may need to escalate privileges
pip2 install -I markupsafe
pip2 for python 2.x
-I to ignore and reinstall package if it's already installed
I uninstalled pip and installed it again.
brew uninstall pip
brew doctor
brew install pip

Categories

Resources