Google Cloud Logging in Python - ImportError - google-cloud-logging

I get the following error when trying to import Google Cloud Logging in Python:
from google.cloud import logging
File "/usr/local/lib/python3.6/site-packages/google/cloud/logging/__init__.py", line 21, in <module>
from google.cloud.logging.client import Client
File "/usr/local/lib/python3.6/site-packages/google/cloud/logging/client.py", line 32, in <module>
from google.cloud.client import ClientWithProject
ImportError: cannot import name 'ClientWithProject'
I have it running in a virtual environment
with this in requirements.txt:
google-cloud-logging>=0.20.0

I was able to get to the next error with:
pip3 install --upgrade google-cloud-logging
for Python 3 and:
pip install --upgrade google-cloud-logging
for Python 2.7

Try to update your google cloud components, run in terminal as admin:
gcloud components update

I had to install dataproc on top of the google-cloud-logging and google-cloud-storage.
Python3
pip3 install mrjob google-cloud-dataproc google-cloud-logging google-cloud-storage
Python2.7
pip3 install mrjob google-cloud-dataproc google-cloud-logging google-cloud-storage

Related

unable to load torchaudio even after installing

I'm trying to use torchaudio but I'm unable to import it. I have installed it and it is also visible through the pip list.
<ipython-input-6-4cf0a64f61c0> in <module>
----> 1 import torchaudio
ModuleNotFoundError: No module named 'torchaudio'
pytorch-lightning 1.2.0
torch 1.10.1
torchaudio 0.10.1
torchvision 0.11.2
WARNING: You are using pip version 21.1.2; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.
Since you are using linux and CPU, you should consider uninstalling every pytorch related packages and re-install them via:
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
as shown here.
I was stuck with the same error. Tried a lot of ways to install and use torchaudio.
This was worked for me (after uninstalling existing torchaudio):
import os
!git clone https://github.com/pytorch/audio.git
os.chdir("audio")
!git checkout 632ea67
!python setup.py install

'scipy' seems to be installed but can not be imported

Here is the error I am receiving when running python 3.10.1 in my terminal.
import scipy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'scipy'
I used
pip3 install scipy
and everything seemed to work. If I run it again I receive this
pip3 install scipy
Requirement already satisfied: scipy in /usr/local/lib/python3.9/site-packages (1.8.0)
Requirement already satisfied: numpy<1.25.0,>=1.17.3 in /usr/local/lib/python3.9/site-packages (from scipy) (1.22.3)
I also tried
brew install scipy
and that too seemed to work and if I run it again I get this message
brew install scipy
Warning: scipy 1.8.0 is already installed and up-to-date.
To reinstall 1.8.0, run:
brew reinstall scipy
Why wont python3 import scipy?
I ran this in terminal and now everything works
python3 -m pip install scipy
I am still unsure what the original issue was however it may be related to this post here.

basic mlxtend example giving invalid syntax error

I'm using Python 3.5.2 on Ubuntu 16.04.
I've installed sklearn using..
sudo apt install python-sklearn
and mlxtend using...
sudo pip3 install mlxtend
I'm trying to run the basic Iris example found on the Internet, but I am getting an error as soon as I try to import plot_decision_regions from mlxtend.plotting:
from mlxtend.plotting import plot_decision_regions
Traceback (most recent call last):
File "scripts/machine.learning.py", line 6, in <module>
from mlxtend.plotting import plot_decision_regions
File "/usr/local/lib/python3.5/dist-packages/mlxtend/plotting/__init__.py", line 15, in <module>
from .heatmap import heatmap
File "/usr/local/lib/python3.5/dist-packages/mlxtend/plotting/heatmap.py", line 74
raise AssertionError(f'len(row_names) (got {len(row_names)})'
^
SyntaxError: invalid syntax
I had the same error, just upgrade to python3.7 the real error is
python 3.5 does not support f prefix
upgrade using conda
conda install -c anaconda python=3.7
and then update all depencies
conda update --all
I'm not seeing the same error as you, but try remove legend=range(105, 150) from plot_decision_regions i.e.
plot_decision_regions(x_combined, y_combined, clf=tree)
I'm using the latest current sklearn, i.e.
import sklearn
sklearn.__version__
'0.21.3'
Perhaps remove that version
sudo apt-get remove python-sklearn
Then install via pip, i.e.
pip3 install scikit-learn

Installing works with easy_install but not pip for dogstatsd-python library

Installing library dogstatsd-python works using easy_install, but does not work using pip (in a virtual environment on Mac OS X)
Using easy_install:
$ easy_install dogstatsd-python
... (lot of output)
$ ls -alrt venv/lib/python2.7/site-packages/ | grep statsd
dogstatsd_python-0.5.2-py2.7.egg
Using pip:
$ pip install dogstatsd-python
Downloading/unpacking dogstatsd-python
Downloading dogstatsd-python-0.5.2.tar.gz
Running setup.py egg_info for package dogstatsd-python
Installing collected packages: dogstatsd-python
Running setup.py install for dogstatsd-python
Successfully installed dogstatsd-python
Cleaning up...
$ ls -alrt venv/lib/python2.7/site-packages/ | grep statsd
statsd.pyc
statsd.py
dogstatsd_python-0.5.2-py2.7.egg-info
Pip installed the .egg-info file, and then put the python files directly in the site-packages directory? (Note that the statsd.py file was not installed in any dogstatsd-python directory, but in the site-packages directory itself)
Is this an issue with the library or am I doing something wrong?
I have the following versions installed:
distribute 0.7.3
pip 1.4.1
setuptools 12.0.3
EDIT:
Here's the issue this is causing. The dogstatsd-python library works with the statsd libray.
Using pip:
$ pip install statsd
$ pip install dogstatsd-python
>>> from statsd import statsd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name statsd
Using easy_install:
$ pip install statsd
$ easy_install dogstatsd-python
>>> from statsd import statsd
>>>
More info: https://github.com/DataDog/dogstatsd-python
dogstatsd and statsd conflict. Both end up installing a top-level statsd module. You can install https://pypi.python.org/pypi/dogstatsd-python-fixed/0.5.0 to move dogstatsd to a different name:
% pip install dogstatsd-python-fixed
% python
>>> from dogstatsd import statsd
>>>

Ansible-galaxy throws ImportError: No module named yaml

When I try to install ansible role, I see this exception.
$ ansible-galaxy install zzet.postgresql
Traceback (most recent call last):
File "/Users/myHomeDir/.homebrew/Cellar/ansible/1.4.3/libexec/bin/ansible-galaxy", line 34, in <module>
import yaml
ImportError: No module named yaml
OS: Mac Os Maverick
Ansible: 1.4.3
Does anyone know how to fix it?
Based on the error message, it tries to import the python module yaml but cannot find it. The yaml module is called pyyaml when you install it with pip:
pip install pyyaml
If pip is not installed on your mac then you can install it as,
easy_install pip
For me pip install yaml doesn’t work in Mavericks.
pip install pyyaml works
I tried the pip install yaml answer, and it didn't work for me. I had to reinstall ansible in order for the command line to catch. IE,
failing
ansible-galaxy install bcen01.nodejs [43m] ✭
Traceback (most recent call last):
File "/usr/local/Cellar/ansible/1.4.3/libexec/bin/ansible-galaxy", line 34, in <module>
import yaml
ImportError: No module named yaml
reinstall
brew reinstall ansible
success
ansible-galaxy install bcen01.nodejs [43m] ✭
no version specified, installing master
- downloading role from https://github.com/bcen/ansible-nodejs/archive/master.tar.gz
- extracting bcen01.nodejs to /usr/local/etc/ansible/roles/bcen01.nodejs
bcen01.nodejs was installed successfully
Try installing with
sudo python -m easy_install pyyaml
The problem isn't in pyyaml, its in your version of setuptools. See http://codyaray.com/2011/12/pyyaml-using-easy_install-on-mac-os-x-lion for references
Run below commands to install latest yaml-
wget http://pyyaml.org/download/pyyaml/PyYAML-3.12.tar.gz
tar -xvzf PyYAML-3.12.tar.gz
cd PyYAML-3.12
python setup.py install
Python 2.7.12 (default, Sep 21 2017, 21:46:26)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>>

Resources