Hi,
I am getting the error:
ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.
my code:
from ayx import Alteryx
import pandas as pd
import zipfile
archive = zipfile.ZipFile(r'O:\Alteryx\Original - All fields - October 2022.zip')
xlfile = archive.open('Original - All fields - October 2022.xls')
df = pd.concat(pd.read_excel(xlfile, header = 1, sheet_name=None), ignore_index=True)
Alteryx.write(df, 1)
However I have this module installed on my python on pc and the code runs fine locally.
Why doesnt this work in alteryx python tool?
Thanks.
Solved! Go to Solution.
Hey @wonka1234,
Alteryx has its own Python environment separate from the one on your PC. You can do the equivalent of a PIP install here:
There is a good blog on the topic here: How To: Use Alteryx.installPackages() in Python to... - Alteryx Community
getting an error on line Package.installPackages(['xlrd'])
getting an SSL error here
ERROR: Could not find a version that satisfies the requirement xlrd (from versions: none)
@wonka1234 you may need to run Alteryx in Admin mode to allow package installs (you will only need to do this once):
@IraWatt company will not allow admin priviledges :( . is there any console for alteryx similar to anaconda prompt I can run? I could try installing there..
@wonka1234 from reading the blog I think there are a few options. If you have already got the xlrd module on your computer, you can reference it with:
examplePackage = Alteryx.importPythonModule("C:\\ProgramData\\PythonLibs\\example")
@IraWatt seems to be working to install it, but now getting a new error! :(
KeyError: 0 The above exception was the direct cause of the following exception: KeyError Traceback (most recent call last) <ipython-input-2-f55c6e3a6b4a> in <module> 11 df = pd.concat(pd.read_excel(xlfile, header = 1, sheet_name=None), ignore_index=True) 12 ---> 13 Alteryx.write(df, 1) 14
@wonka1234 you will want to check the bottom of the error message for the useful information. I would guess pd.concat is returning a Series not a dataframe causing Alteryx.write to throw an error.
Why not write:
df = pd.read_excel(xlfile, header = 1, sheet_name=None)
Alteryx.write(df, 1)
What does the error message say at the bottom? Does my code work at least, that way you know it is a dataframe issue?