I'm attempting to figure out the mechanics of running Python scripts in Power BI for Reasons and I've hit a snag. I was running through the steps in this somewhat basic tutorial and I came to the section in which I am supposed to paste the script into they Python Script screen, which is Step 3 of the 'Run the Script and Import Data' section.
When I followed the steps, which are essentially to paste the example script into the window and hit Okay, I got this 'helpful' error:
`
Details: "ADO.NET: Python script error.
<pi>Traceback (most recent call last):
File "C:\Users\my.username\PythonScriptWrapper_aca634c7-30c3-4bf4-881b-d1e47bb0a919\PythonScriptWrapper.PY", line 2, in <module>
import os, pandas, matplotlib
File "C:\Users\my.username\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 109, in <module>
from . import _api, _version, cbook, docstring, rcsetup
File "C:\Users\my.username\Anaconda3\lib\site-packages\matplotlib\rcsetup.py", line 27, in <module>
from matplotlib.colors import Colormap, is_color_like
File "C:\Users\my.username\Anaconda3\lib\site-packages\matplotlib\colors.py", line 51, in <module>
from PIL import Image
File "C:\Users\my.username\Anaconda3\lib\site-packages\PIL\Image.py", line 89, in <module>
from . import _imaging as core
ImportError: DLL load failed while importing _imaging: The specified module could not be found.
</pi>"
`
I have verified that the matplotlib and pandas packages were installed via pip list, os doesn't show up, which surprised me but I know it's part of the standard library so I'm not stressing about it unless someone thinks I should. Is anyone an expert in this? Is there a better way? Am I doomed to scream into the Power BI void for all eternity?
The somewhat basic tutorial is based on using standard python from python.org. However, you are using the Anaconda distribution, which basically requires the environment to be activated before any modules - especially pandas' C-library - can be accessed.
You can achieve that in the cmd shell by running
conda activate
C:\Users\my.username\AppData\Local\Microsoft\WindowsApps\PBIDesktopStore.exe
which assumes that you are using the Power BI Desktop version from the Microsoft store.
Related
I've recently written some code to process some data which I need to be done every day at the same time. As a result I researched various methods and attempted to do this using the Windows Task scheduler. For the 'Start a program' field I entered the path to the python.exe file in my computer C:\Users...\Anaconda3\python.exe and in the 'add arguments' field I entered the file path of the .py file I want to be run every day "C:\Users..................\daily_python_file.py". This didn't work so I then I tried to run .py file from the command line using the same paths I entered in the fields of the task scheduler, and received the following error:
from . import _distributor_init
Traceback (most recent call last):
File "C:\Users\...\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
from . import multiarray
File "C:\Users\...\Anaconda3\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
from . import overrides
File "C:\Users\...\Anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\...\...\...\...\...\...\daily_python_file.py", line 7, in <module>
import numpy as np
File "C:\Users\...\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import core
File "C:\Users\...\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from "C:\Users\...\Anaconda3\python.exe"
* The NumPy version is: "1.19.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
It works fine to run the .py file when running it from the anaconda prompt command line. I also created a test python file which just contained a print function which ran no problem from the windows command line, (I'm assuming because this .py file has no dependencies (i.e. numpy, pandas etc). I'm aware that it might have something to do with where the modules are installed (which anaconda environment) but I'm not sure how to turn this into a solution. There are also a few questions similar to this online however I haven't found any concrete solutions.
For some background I am running Windows 10, and in the anaconda base environment python 3.8.5, numpy 1.19.2.
Any help on this matter will be massively appreciated.
UPDATE
I managed to solve this problem using a .bat file. I knew that once the anaconda base environment was activated then the python.exe file would run the .py file in question, so I compiled a .bat as follows:
call C:\Users\Stanley\Anaconda3\Scripts\activate base
C:\Users\...\Anaconda3\python.exe "C:\Users\...\...\...\...\...\...\daily_python_file.py"
Then used task scheduler to run this on a daily basis. The call line activates the base environment and then the python file runs no problem. This doesn't give a reason as to why it didn't work before however it does provide a good alternative.
I am trying to run a script which involves numpy through the terminal on WinSCP, but whenever I do, I get the following error:
import gensim
File "/data/work/worker/gensim/init.py", line 5, in
from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401
File "/data/work/worker/gensim/parsing/init.py", line 4, in
from .preprocessing import (remove_stopwords, strip_punctuation, strip_punctuation2, # noqa:F401
File "/data/work/worker/gensim/parsing/preprocessing.py", line 42, in
from gensim import utils
File "/data/work/worker/gensim/utils.py", line 38, in
import numpy as np
File "/data/work/worker/numpy/init.py", line 142, in
from . import core
File "/data/work/worker/numpy/core/init.py", line 50, in
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
The Python version is: Python2.7 from "/usr/bin/python"
The NumPy version is: "1.18.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named _multiarray_umath>
I suspect that the issue is that the version of Python being quoted here is outdated; however, after having done some searching, I cannot find any literature on how to update Python on WinSCP. I have Python 3.8 installed on my machine, and I have tried moving the installer and the .exe file into the WinSCP directory to no avail. Is there any way to update python directly in the terminal? Alternately, is this issue actually nothing to do with a stale version of Python at all?
I use Pydev and try to load numpy in my script. I installed Anaconda to be able to use it, following the Anaconda user guide concerning how to set it up as interpreter in Pydev.
I have tried installing Anaconda both with and without adding it to PATH (the recommended version is without). In both cases numpy shows up as an installed package in Pydev:
However, when I run my script I receive the following error:
File "Z:\Path\To\My\file.py", line 2, in <module>
import numpy as np
File "C:\Users\(username)\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\Users\(username)\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
I also noticed that in the manual from anaconda, in the shown picture a lot more library folders are added than what I am presented with. I couldn't find a list of those, though. Running numpy from the Anaconda prompt works fine.
Any ideas would be appreciated!
I am trying to use ryp with my arcpy scripts but I have the following error:
import rpy2.robjects as robjects Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module> import rpy2.robjects as robjects
File "C:\Python26\ArcGIS10.0\lib\site-packages\rpy2\robjects\__init__.py", line 12, in <module> import rpy2.rinterface as rinterface
File "C:\Python26\ArcGIS10.0\lib\site-packages\rpy2\rinterface\__init__.py", line 39, in <module> import win32api
ImportError: No module named win32api
This error comes even after the installation of the pywin32 for my version of python.
I've noticed that this seems to be a common error that is usually solved with the installation of pywin32.
I also have a problem with the matplotlib installation, every time i try to use it (import matplotlib.pyplot as plt), python crashes...
Versions:
Python 2.6.6
matplotlib installation: matplotlib-1.1.0.win32-py2.6.exe
You will need to run these scripts with PROPER Python. It seems to me that the ArcPy distribution does not include the win32api module (It also does not exist from example in Python on Mac or Linux).
I would install PythonXY which includes R bindings, and see if your scripts run there. If they run there, then I (guess) I am correct, and ArcPy does not include these modules.
A nice BONUS of PythonXY is it's an excellent Python IDE (Spyder), but the real bonus is what the commenter above me said:
different compiler versions can cause hell of a lot of Problems.
So, in PythonXY you get a whole bundle compiled with the same compiler.
Let us know if these made your RPy script run.
I'm new to matplotlib. My environment is WinXP, PythonWin 2.6.2, NumPy 1.3.0, matplotlib 0.98.5.3.
>>> import matplotlib.pylab as pylab
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "D:\Python26\lib\site-packages\matplotlib\pylab.py", line 253, in <module>
from matplotlib.pyplot import *
File "D:\Python26\lib\site-packages\matplotlib\pyplot.py", line 75, in <module>
new_figure_manager, draw_if_interactive, show = pylab_setup()
File "D:\Python26\lib\site-packages\matplotlib\backends\__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
File "D:\Python26\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 8, in <module>
import tkagg # Paint image to Tk photo blitter extension
File "D:\Python26\lib\site-packages\matplotlib\backends\tkagg.py", line 1, in <module>
import _tkagg
ImportError: DLL load failed: cannot find the module
I searched the web and it's said because lack of msvcp71.dll, but there is already one in my C:\windows\system32\
anyone can help?
Thanks.
try this, before using any other module
import matplotlib
matplotlib.use('Agg')
import matplotlib.pylab as pylab
see http://www.mail-archive.com/matplotlib-users#lists.sourceforge.net/msg05372.html for more details and other ways
matplotlib can use different backends for rendering, agg is pure draw with no UI, so you can only save images e.g.
plt.savefig("plt.png")
read http://matplotlib.sourceforge.net/faq/installing_faq.html#what-is-a-backend for more details, e.g. you can output to ps, pdf, wxagg, tkagg etc, so if you have wxpython installed use this
matplotlib.use('wxagg')
also i think tkagg backend should have been work, as tkinter(http://wiki.python.org/moin/TkInter) is default gui with python, did you install python from python.org?
I had the same problem installing activestat python 2.6 and pylab. After installing the sourceforge python 2.6.2 however it worked fine
I actually found the answer and the graphs are running great on my computer. If you are getting a DLL error like this, try downloading msvcp71.dll and msvcr71.dll in your computer and then copy paste these two in your System32 folder:
C:\Windows\System32
and also copy-paste these two dll's in SysWOW64 folder if you are working on 64bit operating System
C:\Windows\SysWOW64
Now try running your code file in Python and it will load the graph in couple of seconds. Here is the link which says how to copy-paste dll's to both folder, this might help
http://www.youtube.com/watch?v=xmvRF7koJ5E
Cheers...
I had this issue using iPython notebooks using Python 2.7. Apparently the latest Seaborn update does not play well with my local configuration settings, so I did "conda/pip install seaborn=0.5.1". It downgraded the necessary packages automatically, and my problem went away.