arcpy.ListTables() doesnt work in cmd but works in IDLE or arcmap python window,why?

7824
12
12-22-2014 02:37 AM
GauriDeshmukh
New Contributor III

Hello all,

  My python script runs well and returns all tables from mdb with arcpy.ListTables() command when i run a script in IDLE(default IDE) or python window from arcmap. But when I try to run the same script from cmd arcpy.ListTables() returns blank list []. What could be the problem?And what is the solution? As I am calling this script in my C# desktop application.

import xlrd
import datetime
import os
import sys
#sys.path.append("C:\Program Files\ArcGIS\Desktop10.0\arcpy")
import arcpy


#arcpy.ResetEnvironments()
arcpy.env.workspace = r"D:/Final/gdb_workspace/New Personal Geodatabase.mdb"
#Get and print a list of tables
tables = arcpy.ListTables()
print tables
for table in tables:
    print table

This is my simple code to list tables.I want to insert data from excel file to a particular table from this personal gdb.

When I run this script using cmd(out of arcgis environment) its not returning tables.

Is this possible to achieve and how? Or do I need to use any geoprocessing service?Any other way to achieve this?

I am able to insert data into mdb if i run the script in IDLE or python window from arcmap.

Please tell me the right way to do this task.

0 Kudos
12 Replies
RichelleSpry
New Contributor III

This might not fix your problem since you are on version 10, but this was my resolution to the same issue.

I have ArcGIS 10.2.2 and Python 2.7, and in C:\Python27\ I have ArcGIS10.2 (32bit) and ArcGISx6410.2 (64bit). I believe they are both included in the standard install. I cannot say for 32bit machines, but the default idle in the start menu is set to C:\Python27\ArcGISx6410.2 .

I ran the code in 32bit cmd (C:\Python27\ArcGIS10.2\python.exe) and arcpy.ListTables() worked, but didn't in 32bit Idle (C:\Python27\ArcGIS10.2\Lib\idlelib\idle.pyw ). I had a look at the path browser in the 32bit Idle and it's referencing a lot of files from the ArcGISx6410.2 folder (C:\Python27\ArcGISx6410.2\).

You might want to try re-running the code directly from 32bit cmd (C:\Python27\ArcGIS10.2\python.exe) and see how you go.

I am working in Visual Studio, so once I changed my default environment from ArcGISx6410.2 to ArcGIS10.2, arcpy.ListTables() worked.

Again, this might not fix your issue, and this post is a few months old, but might give you an idea that might. Good luck!

*note replace 10.2 references for 10

JoshuaBixby
MVP Esteemed Contributor

If you have the C:\Python27\ArcGISx6410.2 directory on your machine, then you installed 64-bit Background Geoprocessing (not part of the standard installation) or ArcGIS for Server.  Assuming the latter isn't the case, the former is what put the extra Python interpreter installation on your machine.

With regard to the OP's situation, 64-bit Background Geooprocessing wasn't introduced until ArcGIS 10.1 SP1.  That said, the information provided is useful for others that install 64-bit Background Geoprocessing and get confused over which Python interpreter they are using when.

RichelleSpry
New Contributor III

To be honest I couldn't remember if it was apart of the standard install or the 64-bit Background Geoprocessing. I did check before my post with a team member who I thought didn't have it installed, but this proves she did. Thanks for clarifying this Joshua.

0 Kudos