Select to view content in your preferred language

Not able to set workspace using standalone Python script for ArcGIS

5890
28
08-21-2018 11:51 PM
HarshalGharat
Emerging Contributor

I am facing a very weird issue in setting the workspace. When I setup the workspace inside python window in ArcMap/ArcCatalog, it just works fine. But the moment I do the same in a standalone python script, the things do not work at all. I tried other options like creating connection file in scratch folder and then setting it as a workspace but still no luck. I am facing this issue on ArcGIS Desktop 10.2.1 and my database is 64 bit Oracle.

I had ArcGIS Pro 2.1 installed on the same machine hence I also tried the same thing after uninstalling ArcGIS Pro but still no luck.

0 Kudos
28 Replies
HarshalGharat
Emerging Contributor

Option1

Import arcpy

arcpy.env.workspace = r‘Database Connections\Connection to sde.sde’

print arcpy.ListDatasets()

Option2

Import arcpy

arcpy.env.workspace = r‘C:\Users\<MyUserName>\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\Connection to sde.sde’

print arcpy.ListDatasets()

 

Result in Python Window within ArcMap : [‘dataset1’, ‘dataset2’]

Result in Pyscripter : None

0 Kudos
JoeBorgione
MVP Emeritus

I don't have pyscripter but I can run this in an idle shell:

That should just about do it....
0 Kudos
HarshalGharat
Emerging Contributor

Here how it happens even when I try the same in IDLE

0 Kudos
JoeBorgione
MVP Emeritus

I wonder if it's bombing on the spaces in your actual paths.

Dan Patterson‌ ; care to comment?

That should just about do it....
0 Kudos
DanPatterson_Retired
MVP Emeritus

I zone out whenever I see SDE anywhere

0 Kudos
NeilAyres
MVP Alum

Ha, ha,

But I also zone out when I see this sort of stuff...

>>> X, Y = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]>>> positions = np.vstack([X.ravel(), Y.ravel()])>>> values = np.vstack([m1, m2])

What does it mean.....

0 Kudos
JoeBorgione
MVP Emeritus

Just numpy messing with you Neil.

Dan- I think because SDE isn't pc any more.  It's really Enterprise Geodatabse....

That should just about do it....
0 Kudos
HarshalGharat
Emerging Contributor

Tried after getting rid of spaces as well, same result. This is driving me crazy since a week!

0 Kudos
NeilAyres
MVP Alum

Can you also try arcpy.Exists(r"path to sde connection file.sde")

0 Kudos
HarshalGharat
Emerging Contributor

Yes, I did this test as well. It conforms that the path does exists.

0 Kudos