Brysinnbo
Brysinnbo

Reputation: 1

Powershell cannot find module, but can find others in the same folder

I am trying to create a batch file that launches a python script which uses openpyxl and pyexcel. Powershell is fine with openpyxl but can't seem to find pyexcel even though they are in the same folder.

I can confirm the python script works and can import both modules.

Here is a snippet of the code. Let me know if I need to provide more.

ECHO ON
REM A batch script to execute a python script
SET PATH=%PATH%;C:\User\username\AppData\Roaming\Python\Python313-32\site-packages
python formatter.py
PAUSE

I get the following error:

ModuleNotFoundError: No module named 'pyexcel'

Here is the folder structure of the site-packages

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        02/14/2025     11:09                click
d-----        02/14/2025     11:09                click-8.1.8.dist-info
d-----        02/14/2025     11:09                colorama
d-----        02/14/2025     11:09                colorama-0.4.6.dist-info
d-----        02/14/2025     10:03                et_xmlfile
d-----        02/14/2025     10:03                et_xmlfile-2.0.0.dist-info
d-----        02/14/2025     11:09                lml
d-----        02/14/2025     11:09                lml-0.1.0.dist-info
d-----        02/14/2025     10:03                openpyxl
d-----        02/14/2025     10:03                openpyxl-3.1.5.dist-info
d-----        02/14/2025     11:09                pyexcel
d-----        02/14/2025     11:09                pyexcel-0.7.1.dist-info
d-----        02/14/2025     11:09                pyexcel_cli
d-----        02/14/2025     11:09                pyexcel_cli-0.0.3.dist-info
d-----        02/14/2025     11:09                pyexcel_io
d-----        02/14/2025     11:09                pyexcel_io-0.6.7.dist-info
d-----        02/14/2025     11:09                pyexcel_xls
d-----        02/14/2025     11:09                pyexcel_xls-0.7.0.dist-info
d-----        02/14/2025     11:09                pyexcel_xlsx
d-----        02/14/2025     11:09                pyexcel_xlsx-0.6.0.dist-info
d-----        02/14/2025     11:09                texttable-1.7.0.dist-info
d-----        02/14/2025     11:04                xlrd
d-----        02/14/2025     11:04                xlrd-2.0.1.dist-info
d-----        02/14/2025     11:09                xlwt
d-----        02/14/2025     11:09                xlwt-1.3.0.dist-info
d-----        02/14/2025     11:09                __pycache__
-a----        02/14/2025     11:09          22851 texttable.py

Here is the start of the python script which runs without issue

from openpyxl import load_workbook
import openpyxl.utils.cell
import pyexcel 
import os.path
import time

I ran pip show openpyxl and pip show pyexcel and both commands output the same folder location

PS C:\Users\username\AppData\Roaming\Python\Python313-32\site-packages> pip show openpyxl
Name: openpyxl
Version: 3.1.5
Summary: A Python library to read/write Excel 2010 xlsx/xlsm files
Home-page: https://openpyxl.readthedocs.io
Author: See AUTHORS
Author-email: [email protected]
License: MIT
Location: C:\Users\username\AppData\Roaming\Python\Python313-32\site-packages
Requires: et-xmlfile
Required-by: pyexcel-xlsx


PS C:\Users\username\AppData\Roaming\Python\Python313-32\site-packages> pip show pyexcel
Name: pyexcel
Version: 0.7.1
Summary: A wrapper library that provides one API to read, manipulate and writedata in different excel formats
Home-page: https://github.com/pyexcel/pyexcel
Author: C.W.
Author-email: [email protected]
License: New BSD
Location: C:\Users\username\AppData\Roaming\Python\Python313-32\site-packages
Requires: lml, pyexcel-io, texttable
Required-by: pyexcel-cli

Thanks!

Upvotes: 0

Views: 58

Answers (1)

Sean Wheeler
Sean Wheeler

Reputation: 21

When you run a CMD file from PowerShell, it's run by CMD.exe not by PowerShell. The error message is coming from Python.

This is not a PowerShell problem.

Upvotes: 0

Related Questions