Posts: 13
Threads: 4
Joined: Dec 2017
Hi I've been trying to install and use OpenPyxl http://openpyxl.readthedocs.io/en/stable/index.html
I'm using v 3 of Python. If I use it to open a command window and enter from openpyxl import Workbook , then I get a >>> on the next line.
I'm not sure what this means. Was it successful in opening openpyxl?
The next command shown in the example on the openpyxl page is: wb = Workbook() But if I enter that, I get the error
"Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Workbook' is not defined"
What I'm hoping is that I can finally get to the point where I can use OpenPyxl to read and write to excel files using the examples on this page to guide me: ttp://openpyxl.readthedocs.io/en/stable/tutorial.html
So if anyone can help me here I'll appreciate it.
Posts: 4,488
Threads: 69
Joined: Jan 2018
(Jan-27-2018, 07:41 PM)kwfreverie Wrote: File "<stdin>", line 1, in <module> If the error happened in line 1, it means that there was no from openpyxl import Workbook before that. If you exit Python, it doesn't keep its state between sessions.
Posts: 13
Threads: 4
Joined: Dec 2017
Jan-27-2018, 11:00 PM
(This post was last modified: Jan-27-2018, 11:00 PM by kwfreverie.)
Thanks. I'm starting from scratch hoping to get this working. I installed python to my program files in W64 and included the checkbox to install pip with it.
When I run python --version from the windows cmd window, I get Python 3.7.0a4.
So I assume this means that python successfully installed.
But if I run python -m pip --version from windows cmd I get
python -m pip --version '-m' is not recognized as an internal or external command,
operable program or batch file. What am I doing wrong? Of course I assume these steps are necessary to begin installing openpyxl
Thanks
I got it working by installing get-pip.py,,, BUT, I'm still having trouble installing openpyxll. When I try this command:
from openpyxl import Workbook I get
'from' is not recognized as an internal or external command,
operable program or batch file. Any advice on what to do next?
Posts: 4,488
Threads: 69
Joined: Jan 2018
(Jan-27-2018, 10:39 PM)kwfreverie Wrote: What am I doing wrong? Really I don't know because this command works on my python, but I'm not in windows.
If you can do import openpyxl in python without seeing an error message, it means that openpyxl is already installed. Try this command in cmd
Output: python -c "import openpyxl; print(openpyxl)"
If it prints "module openpyxl etc", it means that it is already installed.
Posts: 13
Threads: 4
Joined: Dec 2017
OK, this is what I tried, and what I got: (PS in this forum, am I supposed to wrap this kind of code in python, or in regular [] code?
C:\Program Files\Python37>python -c "import openpyxl; print(openpyxl)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'openpyxl'
Posts: 4,488
Threads: 69
Joined: Jan 2018
(Jan-27-2018, 11:19 PM)kwfreverie Wrote: am I supposed to wrap this kind of code in python, Python is OK for me. Everybody here recognizes Exception Traceback messages.
So openpyxl is not installed. The following command in cmd should install it
Output: pip install openpyxl
Posts: 13
Threads: 4
Joined: Dec 2017
Yes, that worked. But it seems like I'm getting a new error for every step I'm taking.
The openpyxl site (here: https://openpyxl.readthedocs.io/en/stable/tutorial.html says to import the workbook class with these commands:
>>> from openpyxl import Workbook
>>> wb = Workbook() But when I try, I get this error:
'from' is not recognized as an internal or external command,
operable program or batch file. I also tried simply going to the openpyxl directory and trying import Workbook but either get the same error, or a syntax error.
Any thoughts?
Posts: 7,080
Threads: 122
Joined: Sep 2016
Jan-28-2018, 01:46 AM
(This post was last modified: Jan-28-2018, 01:46 AM by snippsat.)
(Jan-27-2018, 11:00 PM)kwfreverie Wrote: I got it working by installing get-pip.py,,, BUT, I'm still having trouble installing openpyxll. When I try this command: There no need for this if you install like this Python 3.6 and pip installation under Windows, part-2
Quote:but either get the same error, or a syntax error.
Any thoughts?
You are running from command line(cmd),you most run from Python interactive shell.
Here a run how it shall look.
Microsoft Windows [Version 10.0.16299.192]
(c) 2017 Microsoft Corporation. Med enerett.
C:\Windows\System32>cd\
# Check pip version
C:\>pip -V
pip 9.0.1 from c:\python36\lib\site-packages (python 3.6)
# Check python version
C:\>python -V
Python 3.6.2
# Intall
C:\>pip install --upgrade openpyxl
Collecting openpyxl
Downloading openpyxl-2.5.0.tar.gz (169kB)
100% |████████████████████████████████| 174kB 2.0MB/s
Requirement already up-to-date: jdcal in c:\python36\lib\site-packages (from openpyxl)
Requirement already up-to-date: et_xmlfile in c:\python36\lib\site-packages (from openpyxl)
Building wheels for collected packages: openpyxl
Running setup.py bdist_wheel for openpyxl ... done
Stored in directory: C:\Users\Tom\AppData\Local\pip\Cache\wheels\a7\88\96\29c1f91ba5a9b94dfc39a9f6f72d0eb92d6f0d917cf2341a3f
Successfully built openpyxl
Installing collected packages: openpyxl
Found existing installation: openpyxl 2.4.9
Uninstalling openpyxl-2.4.9:
Successfully uninstalled openpyxl-2.4.9
Successfully installed openpyxl-2.5.0
# Start interactive shell
C:\>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import openpyxl
>>> openpyxl.__version__
'2.5.0'
>>>
>>> from openpyxl import Workbook
>>> wb = Workbook()
>>> exit() # back to command line
C:\>
Posts: 13
Threads: 4
Joined: Dec 2017
Thank you. I opened the shell, and I see the >>>
so I type in
from openpyxl import workbook And the next line is good. It is >>>
so now I type
wb = Workbook() But the response is
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Workbook' is not defined Is this a bug, or is the problem that I should have done something else (such as actually stating: wb = abc.xlsx ?
Posts: 7,080
Threads: 122
Joined: Sep 2016
from openpyxl import w orkbook
To:
from openpyxl import W orkbook
|