VanDee
VanDee

Reputation: 27

Why can't my Mac's Terminal find the xlwings command?

I installed xlwings with pip3. It says:

% pip3 install xlwings
Requirement already satisfied: xlwings in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (0.33.4)
Requirement already satisfied: psutil>=2.0.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from xlwings) (6.1.0)
Requirement already satisfied: appscript>=1.0.1 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from xlwings) (1.3.0)
Requirement already satisfied: lxml>=4.7.1 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from appscript>=1.0.1->xlwings) (5.3.0)

I'm not sure what to expect but I don't see any problems.

When I type xlwings in a macOS Terminal window, it says:

% xlwings
zsh: command not found: xlwings

It should print a list of xlwings' commands.

In order to verify the installation, I entered the following program in a main.py file in Pycharm:

import xlwings as xw
wb = xw.Book('data.xlsx')
wks = xw.sheets
print("Available sheets :\n", wks)
ws = wks[0]
val = ws.range("A1").value
print("A value in sheet1 :", val)

Then I opened Excel, created a new workbook, entered "zyd" in Sheet1!A1, saved it as data.xlsx in the same folder as the Pycharm project and ran the Python program. It compiled and ran without complaint and displayed:

Available sheets :
 Sheets([<Sheet [data.xlsx]Sheet1>])
A value in sheet1 : zyd

so I think the package is installed correctly.

What else do I need to do to make the Terminal command work?

My configuration is:
iMac M1
macOS Sequoia 15.1.1 with all updates
Python 3.12.0

Edit 12/11/2024: I don't know much about the macOS/Unix file structure or where the xlwings executable should be. My PATH looks like:

% echo $PATH

/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin

I entered the Terminal command:

sudo find / -name 'xlwings*.*' > ~/Desktop/find.txt

Then I opened find.txt in Excel and filtered out trash, time machine, and pycharm directories. The only thing left was the xlwings folder in Python3.12/site-packages. I don't see a xlwings executable anywhere.

Upvotes: -1

Views: 71

Answers (1)

VanDee
VanDee

Reputation: 27

Appending /Library/Frameworks/Python.framework/Versions/3.12/bin to the PATH fixed the problem. I'm surprised the Installation section at xlwings.org doesn't say to do this (sigh).

Upvotes: 0

Related Questions