Error when executing python script in PowerBI - python

Error
Details: "ADO.NET: Python script error.
<pi>Traceback (most recent call last):
File "PythonScriptWrapper.PY", line 2, in <module>
import os, pandas, matplotlib
ModuleNotFoundError: No module named 'pandas'
</pi>"
I have imported data into PowerBi, I am now trying to execute some python script on the imported data, but I get the above error.
Please note that I have installed both numpy and pandas through the pip install function in cmd.
Also note that I am not using anaconda, I have installed python directly on my machine (most of the threads I've looked at reference solutions that are to do with Anaconda).
Thanks

Install python latest version using https://www.python.org/downloads/
In cmd, verify python installation using command ‘python –version’
Then install os,pandas,matplotlib,numpy using pip install.
import and load the required dataset in Powerbi Desktop. We can also create visualization graphs and plots using python script. in visualizations tab, select python visual(PY) and select required fields from the dataset. a python script editor will be displayed.
For example,
We used Iris dataset
The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:
dataset = pandas.DataFrame(Species, Id, PetalLengthCm, PetalWidthCm, SepalLengthCm, SepalWidthCm)
dataset = dataset.drop_duplicates()
import matplotlib.pyplot as plt
ax=plt.gca()
dataset.plot(kind='line',x='Species',y='SepalLengthCm',color='blue',ax=ax)
plt.show()
output

Related

Pandas Installed For All Python Versions But Module Can't Be Found

I am trying to modify an AI for a game on the steam store. The AI communicates through the game with the use of a mod called the communication mod. The AI is made using a python project. The package I am trying to modify is https://github.com/ForgottenArbiter/spirecomm and the mod is https://github.com/ForgottenArbiter/CommunicationMod.
I want to add the pandas package and the job lib package as imports so I can use a model I have made for the AI. When I try to run the game + mod after adding the pandas and joblib packages as imports I get this error in the error log.
Traceback (most recent call last):
File "/Users/ross/downloads/spirecomm-master/main.py", line 6, in <module>
from spirecomm.ai.agent import SimpleAgent
File "/Users/ross/Downloads/spirecomm-master/spirecomm/ai/agent.py", line 10, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
This issue only happens when the game is running and the mod tries to run. if I just run the file in terminal it is able to compile/run and send the ready signal
I have checked that I have these modules installed and it is installed. I am on an M1 Mac and I have several different versions of python installed but I have checked them all and it is installed for each of them. I have also opened the python package using pycharm and added pandas and joblib to the python interpreter as a package.
Another thing I have tried is modifying the setup.py file to say that pandas and joblib are required. I then ran it again but I am not sure if this had any effect because I have already run it before.
There is limited help that can be provided without knowing the framework that you are is using but hopefully this will give you some starting points to help.
If you are getting a "No module named 'pandas'" error, it is because you have imported pandas in your code but your python interpreter cannot find it. There are two major reasons this will happen, either it is not installed (which you say has definitely happened) or it is not in the location the interpreter expects (most likely).
The first thing you can do is make sure the pandas install is in the PYTHONPATH. To do this look at Permanently add a directory to PYTHONPATH?.
Secondly, you say you have several versions of python and have installed the module for all versions but you most likely have several instances of at least one version. Many IDEs, such as PyCharm, create a virtual environment when you create a new project and place in it a new instance of python interpreter, or more accurately a link to one version of python. Within this virtual environment, the IDE then loads the modules it has been told to load and thus makes them available for import to the code using that particular environment.
In your case I suspect you may be using a virtual environment that has not had pandas loaded into it. You need to investigate your IDEs documentation if you do not know how to load it. Alternatively you can instruct the IDE to use a different virtual environment (one that does have pandas loaded) - again search documentation for how to do this.
Finally, if all else fails, you can specifically tell your code where to look for the module using the sys.path.append command in your code.
import sys
sys.path.append('/your/pandas/module/path')
import pandas

Unable to import Pandas on Replit.com - Python

I'm unable to import pandas with import pandas as pd on replit.
I've already installed the package with pip install pandas and it can be seen in packages. I've successfully imported it to other projects on replit. Every time I try importing it into my code on this project, it gives me the following error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
import pandas as pd
File "/home/runner/thing/venv/lib/python3.8/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy:
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 "/home/runner/thing/venv/bin/python"
* The NumPy version is: "1.22.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: libz.so.1: cannot open shared object file: No such file or directory
You don't need to use pip to install packages on repl.it -- and in fact, you shouldn't! Using Nix derivations not only works better (as you're using their OS distro the way it's designed), but also keeps their storage costs low, by allowing packages to be used from a read-only, hash-addressed, shared store.
Binaries built for other distributions might assume that there will be libraries in /lib, /usr/lib, or the like, but that's not how NixOS works: Libraries will be in a path like /nix/store/<hash>-<packagename>-<version>/lib, and those paths get embedded into the executables that use those libraries.
The easiest thing to do here is to create a new bash repl, but to add a Python interpreter to it. (I suggest this instead of using a Python repl because the way they have their Python REPLs set up adds a bunch of extra tools that need to be reconfigured; a bash repl keeps it simple).
Create a new bash repl.
Click on the three-dots menu.
Select "Show Hidden Files".
Open the file named replit.nix
Edit the file by adding a Python interpreter with pandas, as follows:
{ pkgs }: {
deps = [
pkgs.bashInteractive
(pkgs.python38.withPackages (p: [p.pandas]))
];
}
...changing that to taste (as long as they're getting software from a channel that has binaries for Python 3.9 or 3.10, for example, you can change python38 to python39 or python310).
Click the "run" button
In the new shell that opens, run python, and see that you can import pandas without trouble.
If, after you add a Python file to your repl, you can also change the .replit hidden file to make it run that file automatically on startup. Note that on NixOS, you should use #!/usr/bin/env python as your shebang, as PATH lookups are essential.

install fastText Python library on Azure Machine Learning Studio

I would like to install the Python fastText wrapper of the Facebook C++ library on Azure ML Studio. This library is installed and works properly on my laptop.
I tried to follow the instructions in this Stack Overflow thread for the upload on Azure without success.
The code in my "Execute Python Script" is minimal: I am just unzipping and loading the fastText package that I installed locally on my machine and then calling a help function on the "train_supervised" attribute of the fastText module to verify that the package is imported correctly
# The script MUST contain a function named azureml_main
# which is the entry point for this module.
import fastText
# The entry point function can contain up to two input arguments:
# Param<dataframe1>: a pandas.DataFrame
# Param<dataframe2>: a pandas.DataFrame
def azureml_main(dataframe1 = None, dataframe2 = None):
print(help(fastText.train_supervised))
# Return value must be of a sequence of pandas.DataFrame
return dataframe1,
Upon running this minimal Azure experiment I get the following error:
Traceback (most recent call last): File "C:\server\invokepy.py", line 199, in batch odfs = mod.azureml_main(*idfs) File "C:\temp\e6acccec62994066a25e0d758090e749.py", line 44, in azureml_main print(help(fastText.train_supervised))AttributeError: module 'fastText' has no attribute 'train_supervised'Process returned with non-zero exit code 1---------- End of error message from Python interpreter ---------- Process exited with error code -2
I have also tried to create a virtual environment on my local machine (using conda) and to install fastText and its dependencies in it, but I did not manage. The goal would have been then to zip and upload those libraries to Azure. This is because, for compatibility with the Azure Python environment, I need the 3.5.1 Python version (Anaconda 4.0).
Any help/guidance appreciated!
There is a more completed answer for the SO thread post by me: Updating pandas to version 0.19 in Azure ML Studio.
And you should install Cypython and fasttext via pip in a virtualenv, then you need to package these modules below (list by pip freeze) to a zip file and upload it to Azure ML Studio.
Cython==0.29.10
fasttext==0.8.3
future==0.17.1
numpy==1.16.4
However, there are two issue in your code as below.
To import fasttext in Python, not fastText which will cause ModuleNotFoundError: No module named 'fastText'.
Actually, there is not an attribute named train_supervised, I got the error AttributeError: module 'fasttext' has no attribute 'train_supervised'. And I tried to find it via the online fastText API Reference All Functions & All Variables, it doesn't exist really, just supervised.
Hope it helps.

Python does not import installed external library

This is a rather weird problem. I'm on Windows and using Anaconda for Python. There is a financial tool library called TA_lib (Technical Analysis Library). Since this library is not officially supported, I had to install a whl version and I got it from here.
After installation I was able to use it. But sometimes, when I start Anaconda and Spyder, the import talib command yields "Talib has no functiona as ..." and I cannot import and use it. When this happens, I follow these steps:
I close Anaconda and Spyder
I install the library again through Anaconda prompt (I see requirement already satisfied messge)
I restart Anaconda and Spyder
If I'm lucky, I can import talib after first try. If not, I have to repeat these steps for a couple of times. What might be wrong?
EDIT 1:
Now it's not working. Here is the error log:
import pandas as pd
import talib
import numpy as np
Traceback (most recent call last):
File "<ipython-input-2-a3bb601353da>", line 2, in <module>
import talib
File "C:\Users\ismetb\Desktop\AlgoritmikFinans\Classifier 11-12-2018 1830 v2\talib.py", line 90, in <module>
upperband, middleband, lowerband = talib.BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=talib.MA_Type.T3)
AttributeError: module 'talib' has no attribute 'BBANDS'
There is a chance you've installed it wrong. Also consider that this is an unofficial library.
Make sure you installed the correct TA_lib for your Python version. What Python version are you using?
If it's 3.4, make sure you have downloaded the TA_lib cp34 for windows 64 bits or 32 bits. If it's another version, make sure you find the one appropriate to you.
Also another useful link to download TA_lib for 64bit is here.
I figured the problem. My Python file name was Talib_pure and then I renamed it to Talib. Since I import talib with import talib command, Python tried to import my own code isntead of talib library and therefore it got confused.
I renamed the file to ta_lib and now it works (so far at least).

Configuration of Ipython

I'm new to python and Ipython. I'm following the data analysis with pandas on youtube. the link
I installed Anaconda and then started to use Ipython on Windows 8.1
For several commands, it seems OK
In [2]: print 5
5
But when I tried to followe the tutorial online it seems that my Ipyhon has got some problems,
In [3]: %pylib inline
ERROR: Line magic function `%pylib` not found.
Also, I just copies the code from the tutorials, just very simple codes like this
In [4]:plot(arange(10))
NameError Traceback (most recent call last)
<ipython-input-6-353c92d67d6b> in <module>()
----> 1 plot(arange(10))
NameError: name 'plot' is not defined
After "imported matplotlib", it still didn't work.
Also, the code a = arange(10) didn't work. I have to use it like this:
import numpy as np
a = np.arange(10)
But the tutor in this video didn't use it like this.
I think it should be associated with the configuration with anaconda or Ipython?
But I'm not sure about this and I don't know how to figure it out. I'm using the latest version of anaconda on windows 64bit.
Any suggestions? Thanks!
use %pylab inline or %pylab to enable pylab mode. This will alter the event loop either to show plots inline (notebook) or to display them in different window without interfering the code execution (CLI).
Executing %pylab will set ipython to handle matplotlib nicely, and will also commit from pylab import * that will put numpy and matplotlib commands inside your default namespace.
equivalent way to that, when you invoke IPython, use `ipython --pylab [notebook|qtconsole|etc..]. In windows, you can either do that from console or alter a shortcut to add command line arguments.
You can change IPython system wide configuration to load pylab, see http://ipython.org/ipython-doc/stable/config/overview.html#flags
See this answer for more information: https://stackoverflow.com/a/21457629/3245308

Categories