最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Powershell cannot find module, but can find others in the same folder - Stack Overflow

programmeradmin3浏览0评论

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: 
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: 
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!

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/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!

Share Improve this question asked yesterday BrysinnboBrysinnbo 1 New contributor Brysinnbo is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 5
  • Where is load_workbook? When the file to see what directories are being used. – jdweng Commented yesterday
  • 1 I don't think this has anything to do with PowerShell. What happens under the command (cmd.exe) prompt? – iRon Commented yesterday
  • @jdweng the load_workbook is a function within the openpyxl folder. I can't find the specific file that has it but I believe it is somewhere in the reader folder. – Brysinnbo Commented yesterday
  • @iRon I'm not sure what you mean by what happens under the cmd prompt. Are you talking about the output when I run the python script or the batch file from within the cmd prompt? Or maybe something else? – Brysinnbo Commented yesterday
  • Load_Workbook is a python script and needs a filename (pythonexcel/openpyxl-load-workbook-function.php). I do not know python so I'm not sure what file is being used. – jdweng Commented yesterday
Add a comment  | 

1 Answer 1

Reset to default 0

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.

发布评论

评论列表(0)

  1. 暂无评论