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

7811
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
DanPatterson_Retired
MVP Emeritus

import arcpy

arcpy is know to exist from python within arcmap, but not outside of it.  it needs to be imported in most languages (ie python running outside of arcmap, or separately from it)

0 Kudos
GauriDeshmukh
New Contributor III

Yes I have already included import arcpy.

Its not working in when i run script from command prompt. 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

How are you setting the workspace environment?  Can you post the functional part of the code that isn't working?

Do you have more than 1 Python install on the machine?

0 Kudos
MichaelVolz
Esteemed Contributor

Gauri:

Are you running this script in a 64-bit environment?

0 Kudos
GauriDeshmukh
New Contributor III

I am having 32 bit.

0 Kudos
DanPatterson_Retired
MVP Emeritus

probably has no effect but worth checking

r"D:/Final/gdb_workspace/New Personal Geodatabase.mdb"   raw notation is used when paths have backslashes and not foreslashes

table@@ I am not farmiliar with @@ is that a substitute for printing its name?

0 Kudos
GauriDeshmukh
New Contributor III

sorry its variable table only.

I tried by all way.. i.e. with r without r. I tried giving path in different way.but not working in cmd.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Are you sure the script is running at all when called from the command line by your other program?  If you try printing 'hello world' from the script, does that even work from the command line?

0 Kudos
GauriDeshmukh
New Contributor III

I have posted the functional part which is not working. I have only 1 python installed on my machine. python 2.6 for arcgis 10.0

0 Kudos