Python Forum

Full Version: Openpyxl module breaking my code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was working on a discord bot and wanted to scrape data from an excel spreadsheet so I installed the pandas library and imported it into my file. I wrote up a simple script and tried to run the file but nothing happened. I was confused so I tried to retrace my steps and eventually came to just editing out the import statement and my code ran again. I thought maybe just something wrong with the library so I moved to openpyxl and same thing. I then created a new file, imported openpyxl and ran a simple print statement. Nothing once more. So I commented out the import statement and then it worked. I don't get any errors when trying to run the code, it just simply does nothing. The terminal looks normal as if I had nothing to run in my file, when I clearly have a print statement.

import openpyxl

print("Hello")
That's what my code looks like when it doesn't work, and simply by commenting out the import statement and running again, the print statement executes. I really have no idea how to fix this problem or what might be going on.
Could you do
import openpyxl
print(openpyxl.__file__)
(May-26-2023, 10:58 AM)buran Wrote: [ -> ]Could you do
import openpyxl
print(openpyxl.__file__)

Hmm I tried that and still nothing. I also tried uninstalling the library and reinstalling it but no difference
My guess is that you have some openpyxl.py file that waits for input and shadows the package, although in this case pandas would probably raise some error. How do you run the scripts - inside IDE, from terminal?
Can you share some screenshot of running some script that imports openpyxl?
(May-26-2023, 04:16 PM)buran Wrote: [ -> ]My guess is that you have some openpyxl.py file that waits for input and shadows the package, although in this case pandas would probably raise some error. How do you run the scripts - inside IDE, from terminal?
Can you share some screenshot of running some script that imports openpyxl?

I run it straight from VS code. I also tried using a virtual environment but no difference.
[Image: image.png?width=1025&height=417]
Image do not show what's important which interpreter usage down in right corner.
Look at this Post and the start in Thread.
So this was for using Virtual environment,it just a interpreter change in VS Code if want to use Python that you has install on OS.
Test that all work on command line first,so you know Python version and where pip install.