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

6137
12
12-22-2014 02:37 AM
Highlighted
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.

Reply
0 Kudos
12 Replies
Highlighted
MVP Esteemed Contributor

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)

Reply
0 Kudos
Highlighted
New Contributor III

Yes I have already included import arcpy.

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

Reply
0 Kudos
Highlighted
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?

Reply
0 Kudos
Highlighted
Esteemed Contributor

Gauri:

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

Reply
0 Kudos
Highlighted
New Contributor III

I am having 32 bit.

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

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?

Reply
0 Kudos
Highlighted
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.

Reply
0 Kudos
Highlighted
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?

Reply
0 Kudos
Highlighted
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

Reply
0 Kudos