openpyxl

10611
16
Jump to solution
01-10-2018 01:24 PM
CCWeedcontrol
Frequent Contributor

I have the following script, i am trying to export sql table to an excel file. I have installed  the openpyxl library using. C:\Python27\ArcGISx6410.4\Scripts>pip install openpyxl. everything installed fine. I have the following folders openpyxl & openpyxl-2.4.9.dist-info  in C:\Python27\ArcGIS1040\Lib\site-packages. Any ideas on what i am doing wrong?

When i runt he following script i get the error.

line 3, in <module>
import openpyxl
ImportError: No module named openpyxl

Script

import pyodbc
import pandas as pd
import openpyxl

cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=csde18;Trusted_Connection=yes', autocommit=True)

cursor = cnxn.cursor()
script = """
SELECT * FROM dbo.Characteristics 
"""

df = pd.read_sql(script, cnxn)

writer = pd.ExcelWriter('C:\\Temp\\Characteristics.xlsx')
df.to_excel(writer, sheet_name='bar')
writer.save()

print 'Done'
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

sounds like you have 2 versions of 2.7 installed.  dump the 64 bit version, the one in the arcgis10.4 folder is the correct one, you will get conflicts that may be difficult to resolve until you move on to Pro and use the Anaconda distributions of python 3.x and can set up other installations of python.  Besides, you can install your module and others much more readily using a conda distribution.

View solution in original post

16 Replies
DanPatterson_Retired
MVP Emeritus

installed using the instructions from? https://openpyxl.readthedocs.io/en/default/ 

most links I have seen use

from openpyxl import Workbook

0 Kudos
CCWeedcontrol
Frequent Contributor

inst it just C:\Python27\ArcGISx6410.4\Scripts>pip install openpyxl?

if i try $ pip install openpyxl i get '$' is not recognized as an internal or external command.

0 Kudos
CCWeedcontrol
Frequent Contributor

So i uninstalled openpyxl with pip uninstall openpyxl. Then i tried to reinstall it with C:\Python27\ArcGISx6410.4\Scripts>pip install openpyxl. i get following, why is it referring to c:\python27\arcgis10.4?

C:\Python27\ArcGISx6410.4\Scripts>pip install openpyxl
Collecting openpyxl
Requirement already satisfied: et-xmlfile in c:\python27\arcgis10.4\lib\site-packages (from openpyxl)
Requirement already satisfied: jdcal in c:\python27\arcgis10.4\lib\site-packages (from openpyxl)
Installing collected packages: openpyxl
Successfully installed openpyxl-2.4.9

0 Kudos
DanPatterson_Retired
MVP Emeritus

sounds like you have 2 versions of 2.7 installed.  dump the 64 bit version, the one in the arcgis10.4 folder is the correct one, you will get conflicts that may be difficult to resolve until you move on to Pro and use the Anaconda distributions of python 3.x and can set up other installations of python.  Besides, you can install your module and others much more readily using a conda distribution.

CCWeedcontrol
Frequent Contributor

ya I do, i am trying to think why i installed 64 bit version. I think i have one script that benefited from the 64 bit but i can't remember. Wouldn't i want to keep the 64 bit version, 64 bit better than 32 bit? Dumb question but how do i remove a python version?

0 Kudos
DanPatterson_Retired
MVP Emeritus

uninstall the version not in the arcgis10.4 folder.  You should be able to uninstall it through windows install/uninstall in Windows Control panel

0 Kudos
CCWeedcontrol
Frequent Contributor

I have two folders in C:\Python27 - ArcGIS10.4 & ArcGISx6410.4.

I do see python in install/uninstall windows control panel. i have windows 10.

0 Kudos
DanPatterson_Retired
MVP Emeritus

C:\Python27\ArcGIS10.4  is the one that came with arcmap... you must have installed the one for 64 bit later.  If you need 64 bit, install Pro, everything is just better managed in Pro

0 Kudos
CCWeedcontrol
Frequent Contributor

Sorry Dan, i meant "I do not see Python in install/uninstall windows control panel". I haven't had any issues with 64 bit until now. I am not sure how to uninstall 64 bit if i don't see it in the install/uninstall windows control panel.

0 Kudos