Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Alteryx Python Import Error, How to install module in alteryx python?

wonka1234
10 - Fireball

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.

11 REPLIES 11
IraWatt
17 - Castor
17 - Castor

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: 

IraWatt_0-1669731529163.png

There is a good blog on the topic here: How To: Use Alteryx.installPackages() in Python to... - Alteryx Community

 

wonka1234
10 - Fireball

@IraWatt 

 

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)
IraWatt
17 - Castor
17 - Castor

@wonka1234 you may need to run Alteryx in Admin mode to allow package installs (you will only need to do this once):

IraWatt_0-1669732053055.png

 

wonka1234
10 - Fireball

@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..

IraWatt
17 - Castor
17 - Castor

@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_0-1669732632387.png

 

wonka1234
10 - Fireball

@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 

 

IraWatt
17 - Castor
17 - Castor

@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)
wonka1234
10 - Fireball

@IraWatt 

 

there are several sheets and I want to read them and concat them!

IraWatt
17 - Castor
17 - Castor

@wonka1234,

What does the error message say at the bottom? Does my code work at least, that way you know it is a dataframe issue?

Labels
Top Solution Authors