|
POST
|
Multiprocessing is probably trying to use ArcGISPro.exe instead of python.exe to run the child processes. Either disable running the script 'in process' or use multiprocessing.set_executable(os.path.join(sys.exec_prefix, 'python.exe')) Note: don't use sys.executable to get the path to python.exe if running in-process as it will be pointing to ArcGISPro.exe, use sys.exec_prefix instead: >>> import os, sys
>>> print(sys.executable)
C:\Program Files\ArcGIS\Pro\bin\ArcGISPro.exe
>>> print(os.path.join(sys.exec_prefix, 'python.exe'))
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe
... View more
03-05-2019
08:26 PM
|
4
|
4
|
6935
|
|
POST
|
You state: I have the output parameter set to DEtable But your code shows: OutputTB = arcpy.Parameter(
displayName="OutputTB",
name="OutputTB",
datatype="DEArcInfoTable", # <======== ???
parameterType="Required",
direction="Output")
Are you really trying to create an INFO table? it seems like Arc wont create a table inherently like it will a feature class ArcMap won't inherently create a feature class either. If you're trying to create an empty feature class from scratch (rather than exporting or copying an existing one or as an output from a geoprocessing operation), you need to use the Create Feature Class tool, just like when you want to create an empty table, you need to use the Create Table tool.
... View more
02-24-2019
04:16 PM
|
1
|
4
|
3677
|
|
POST
|
In general yes. In this case I think was because arcpy messes with sys.stdout/stderr (from memory) so the print ' ' was supposed to help silence the error output. I can't check now as I can't get any addins at all to work (I think it's our locked down corp environment)
... View more
02-21-2019
02:24 PM
|
0
|
1
|
2703
|
|
POST
|
pass worked for me in 10.2 (it's been a while since I've worked with python addins...) but not for another user. https://community.esri.com/thread/160547#comment-534380 Meh, python addins are not supported in Pro so I stopped bothering with them.
... View more
02-21-2019
03:50 AM
|
0
|
0
|
2703
|
|
POST
|
It's a longstanding bug NIM089253. The workaround is just to wrap the call in a try block: try:
GPToolDialog(toolbox, tool_name)
except TypeError:
pass
... View more
02-21-2019
03:32 AM
|
0
|
6
|
2703
|
|
POST
|
A global var can be defined anywhere at the module level, i.e. in the same script file as your function and not inside a function or class. I recommend not using globals though. Just define it inside your zonal function or pass it in as an argument. def zonal_statistics(*argv):
"""
Calculates the Zonal statistics etc...
"""
fd = "whatever fd is...?" def zonal_statistics(fd, *argv):
"""
Calculates the Zonal statistics etc...
""" #etc... fd = "whatever fd is...?"
zonal_statistics(fd, rest of, your, args)
... View more
02-19-2019
07:00 PM
|
1
|
1
|
2432
|
|
POST
|
You can define fd in your function, or pass a previously defined fd in to the function as an argument, or define it as a global variable.
... View more
02-19-2019
02:15 AM
|
1
|
3
|
2432
|
|
POST
|
You haven't defined "fd" anywhere in that function.
... View more
02-19-2019
01:16 AM
|
0
|
5
|
2432
|
|
POST
|
Can you explain a bit more about what you want to do with this text data. Your errors are happening when you print it out and this is expected (in Python 2, though in Python 3 you don't need to worry as much as strings are unicode objects). For example: I can read in some data with non-ascii characters and write it out to another table with no issues, but if I try to print it (or write it to a text file/spreadsheet) without encoding it, I get the dreaded UnicodeEncodeError. If you want to print it/output it you need to encode it. table,field = 'c:/temp/default.gdb/test', 'testfield'
with arcpy.da.SearchCursor(table,field) as rows:
for row in rows:
data = row[0]
break
print('{} = tablename; {} = fieldvalue'.format(table,data))
# Runtime error
# Traceback (most recent call last):
# File "<string>", line 4, in <module>
# UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 8: ordinal not in range(128)
with open('c:/temp/test.txt', 'w') as t:
t.write(data)
# Runtime error
# Traceback (most recent call last):
# File "<string>", line 2, in <module>
# UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 8: ordinal not in range(128)
print('{} = tablename; {} = fieldvalue'.format(table,data.encode('utf-8')))
# c:/temp/default.gdb/test = tablename; It's -10°C here in Überwald and I'm sitting outside at the Café = fieldvalue
Hammers sometimes miss and hit you on the thumb. You can try and replace most of the usual non-ASCII characters, but you'll always run across another... Your best bet is deal with it as unicode then encode it on output. If you absolutely must force it to ascii, t ry the hammer (manual replacement), if that fails, just strip them out: data.encode('ascii', 'ignore') You could also look at a 3rd party library that takes Unicode data and tries to represent it in ASCII characters - Unidecode · PyPI
... View more
02-17-2019
05:40 PM
|
1
|
4
|
6643
|
|
POST
|
You can raise an exception (or try arcpy.AddError) and the window will stay up. But you'd be better using script validation to stop the script from running in the first place.
... View more
02-16-2019
10:08 PM
|
2
|
1
|
5562
|
|
POST
|
Mixing and matching is going to cause you grief and confuse us . I said it was Python 2.7 as I'd read you were running your code in in 10.6.1. You can install Spyder for Desktop (python 2.7) and Spyder for Pro (python 3)
... View more
02-13-2019
08:22 PM
|
0
|
3
|
6643
|
|
POST
|
And to avoid messing with sys.stdout at all: Python 2 from __future__ import print_function
with open('filename', 'w') as f:
print('some text', file=f) Python 3 with open('filename', 'w') as f:
print('some text', file=f)
... View more
02-12-2019
08:01 PM
|
2
|
0
|
6358
|
|
POST
|
# -*- coding: utf-8 -*- This only tells the python interpreter that string literals in your script are utf-8, it doesn't apply to string data that you use in the script. i.e status = "It's -10°C here in Überwald and I'm sitting outside at the Café"
print status C:\Python27\ArcGIS10.3\python.exe test.py
File "test.py", line 1
SyntaxError: Non-ASCII character '\xc2' in file test.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details # -*- coding: utf-8 -*-
status = "It's -10°C here in Überwald and I'm sitting outside at the Café"
print status C:\Python27\ArcGIS10.3\python.exe test.py
It's -10°C here in Überwald and I'm sitting outside at the Café
Process finished with exit code 0
... View more
02-12-2019
05:49 PM
|
1
|
0
|
6643
|
|
POST
|
Joe Borgione wrote: But from the spyder console it's running 3.x, no? No. Python 2.7. Though if you actually are using Python 3.6 and arcpy in spyder, you're using ArcGIS Pro arcpy, not ArcGIS Desktop arcpy.
... View more
02-12-2019
05:38 PM
|
0
|
5
|
10206
|
|
POST
|
I don't use spyder, but does using a context manager have the same issue? Actually, I bet it probably does. I think you should save and then reset sys.stdout after you rediredirect it to a file.. I would guess that you lose your prompt, because by closing the file, you've closed sys.stdout... import sys
logFile = r'C:\temp\test.txt'
stdout = sys.stdout #<== save original sys.stdout
with open(logFile, 'w') as logoutput:
sys.stdout = logoutput # lets me use print() statements
print('Blah')
sys.stdout = stdout #<== reset sys.stdout
print(logoutput.closed) # Check it's closed
print(open(logFile).read()) # Check what was written to it earlier
Output: True
Blah
... View more
02-12-2019
05:27 PM
|
1
|
0
|
6358
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 07-24-2022 03:08 PM | |
| 1 | 07-30-2025 03:00 PM | |
| 1 | 06-10-2025 08:06 PM | |
| 5 | 05-20-2025 07:56 PM | |
| 1 | 05-04-2025 10:34 PM |