Python scripting inside PowerBI - python

I am reproducing a simple example from here to run Python into Power BI desktop :
https://learn.microsoft.com/en-us/power-bi/connect-data/desktop-python-scripts
import pandas as pd
data = [['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=['Name','Age'],dtype=float)
print (df)
I do not know where to begin to solve this error:
Details: "ADO.NET: Python script error.
<pi>Traceback (most recent call last):
File "PythonScriptWrapper.PY", line 2, in <module>
import os, pandas, matplotlib
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 174, in <module>
_check_versions()
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 159, in _check_versions
from . import ft2font
ImportError: DLL load failed while importing ft2font: The specified module could not be found.
</pi>"

This works :
pip uninstall matplotlib
pip install --upgrade matplotlib
pip uninstall pandas
pip install --upgrade pandas
pip uninstall pillow
pip install --upgrade pillow

Related

ImportError: Failed to import the Cloud Firestore library for Python. Make sure to install the "google-cloud-firestore" module

Trying to integrate the Google firestore API in my python program
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/firestore.py", line 22, in <module>
from google.cloud import firestore # pylint: disable=import-error,no-name-in-module
File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/firestore/__init__.py", line 18, in <module>
from google.cloud.firestore_v1 import __version__
File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/firestore_v1/__init__.py", line 30, in <module>
from google.cloud.firestore_v1._helpers import GeoPoint
File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/firestore_v1/_helpers.py", line 22, in <module>
from google.api_core import gapic_v1
File "/home/pi/.local/lib/python3.7/site-packages/google/api_core/gapic_v1/__init__.py", line 16, in <module>
from google.api_core.gapic_v1 import config
File "/home/pi/.local/lib/python3.7/site-packages/google/api_core/gapic_v1/config.py", line 23, in <module>
import grpc
File "/usr/local/lib/python3.7/dist-packages/grpc/__init__.py", line 22, in <module>
from grpc import _compression
File "/usr/local/lib/python3.7/dist-packages/grpc/_compression.py", line 15, in <module>
from grpc._cython import cygrpc
ImportError: /lib/arm-linux-gnueabihf/libm.so.6: version `GLIBC_2.29' not found (required by /usr/local/lib/python3.7/dist-packages/grpc/_cython/cygrpc.cpython-37m-arm-linux-gnueabihf.so)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Code/main.py", line 10, in <module>
from firebase_admin import firestore
File "/home/pi/.local/lib/python3.7/site-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.
I have this error and have tried every option I have found
I installed the firebase-admin module:
pip3 insstall --upgrade -t libs firebase-admin
I installed grpc:
pip3 install grpcio
I installed google-cloud-core and google-cloud-firestore:
pip3 install google-cloud-core
pip3 install google-cloud-firestore
I even tried uninstalling and reinstalling all of these modules. But nothing seems to be working. Any advice would be appreciated.
Generally, it advised to install packages using python -m command instead of simply pip or pip3.
Try installing as follows:
python3.7 -m pip install google-cloud-firestore
Additionally, I would recommend using a virtual environment.
# Create a virtual environment using Python3.7
$ python3.7 -m venv env
# Activate the virtual environment
$ source env/bin/activate
# Install dependencies
(env) $ python3.7 -m pip install google-cloud-firestore

"RuntimeError: implement_array_function method already has a docstring", trying to import numpy. How do I solve this?

I am trying to run a script importing numpy, and it shows this error:
Traceback (most recent call last):
File "C:/Users/<user>/pycharm/<my_project>/../examples/<my_file>.py", line 5, in <module>
import numpy as np
File "C:\Users\<user>\pycharm\<myproject>\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\<user>\pycharm\<myproject>\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\<user>\pycharm\<myproject>\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\Users\<user>\pycharm\<myproject>\lib\site-packages\numpy\core\overrides.py", line 47, in <module>
""")
RuntimeError: implement_array_function method already has a docstring
Process finished with exit code 1
I googeled and my results are
that it might have to do with importing numpy multiple times and
that it might be related to some software called usgwi that python may run under.
I am using python 3.7 and numpy 1.18.5.
Thank you!
I think issue with numpy.
See https://github.com/numpy/numpy/issues/14384
I had issue in VSCode using python AREPEL. I fixed with:
python3 -m pip install --user numpy -U
$ python3 -m pip freeze | grep numpy
numpy==1.19.4
$ python3 --version
Python 3.8.6
Downgrading numpy to numpy==1.15.4 will solve this issue.
pip install --no-cache-dir -I numpy==1.15.4

Installation of nltk and scikit-learn

I have been trying to install and use scikit-learn and nltk. However, I get the following error while importing anything:
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/site-packages/sklearn/init.py", line 57, in
from .base import clone
File "/usr/local/lib/python2.7/site-packages/sklearn/base.py", line 11, in
from .utils.fixes import signature
File "/usr/local/lib/python2.7/site-packages/sklearn/utils/init.py", line 10, in
from .murmurhash import murmurhash3_32
File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling
I did a pip uninstall numpy followed by a pip install numpy and also a pip uninstall scikit-learn and again reinstalled it. But the error persists.
I met the same problem today. Now I have solved it.
Because I have installed numPy manually, and I use the command "pip" to install the else package.
Solve way:
find the old version of numPy.
You can import numPy and print the path of it.
delete the folder.
use pip to install again.

ImportError: No module named 'numpy.ma'

The full error:
import matplotlib
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import matplotlib
File "R:\Python34\lib\site-packages\matplotlib\__init__.py", line 180, in <module>
from matplotlib.cbook import is_string_like
File "R:\Python34\lib\site-packages\matplotlib\cbook.py", line 34, in <module>
import numpy.ma as ma
ImportError: No module named 'numpy.ma'
numpy is imported normally.
How do I install numpy.ma?
I also faced the same situation today. I found that I had saved a file as numpy.py, so check the filenames in your folder.
Re-install the correct version of numpy.
download correct .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
pip install C:\Path\To\Wheel\Filename.whl # for example: numpy-1.9.2+mkl-cp34-none-win_amd64.whl
Use Your (via terminal) package manager and search.
Example on Ubuntu:
aptitude search numpy
and install package.
In my case:
apt-get install python-numpy

dateutil.tz package apparently missing when using Pandas?

My python 2.7 code is as follows:
import pandas as pd
from pandas import DataFrame
DF_rando = DataFrame([1,2,3])
...and then when I execute, I get a strange error regarding dateutil.tz.
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/mattobrien/pandas_test.py
No module named dateutil.tz
Traceback (most recent call last):
File "/Users/mattobrien/pandas_test.py", line 2, in <module>
import pandas as pd
File "/Library/Python/2.7/site-packages/pandas/__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "pandas/tslib.pyx", line 37, in init pandas.tslib (pandas/tslib.c:76999)
ImportError: No module named dateutil.tz
Process finished with exit code 1
Very strange. I checked an indeed dateutil.tz is indeed installed. I uninstalled Pandas and reinstalled it to be sure. No issues there.
Why am I getting this error?
Needed these 2 lines.
sudo pip install python-dateutil --upgrade
sudo pip install pytz --upgrade

Categories