FME Version
As of FME 2022.0, Python 2.7 has been deprecated and is no longer available within FME. Please see the Python 2.7 Deprecation article. This article has not yet been updated to use Python 3+, to continue with this article, please use FME 2020 or older.
Why use ArcPy in FME?
Adding a Python script that uses Esri's arcpy module to your workspace is a great way to extend the functionality of workbench. As Python is the default scripting language for ArcGIS, if you have a valid ArcGIS license on your machine you can make use of the many geoprocessing functions in the arcpy module in your Python scripts. You can also use ModelBuilder to create Python scripts from your models.
However, users may encounter the following error message when you run a workspace that attempts to use the arcpy module:
Python Exception <ImportError>: No module named arcpy
Troubleshooting
The following offers some troubleshooting suggestions that may help resolve the issue of not being able to import arcpy in FME.
1. Ensure the workspace's Python Compatibility parameter is set to the interpreter installed by ArcGIS.
In order to use the arcpy module you will need to use the Python interpreter that is installed by your ArcGIS client. To do so, follow the appropriate instructions for your FME version:
FME 2017 and higher: In FME Workbench, go to Navigator > Workspace Parameters > Scripting > Python Compatibility. Select the appropriate option for the ArcGIS client installed on the machine (eg. Esri ArcGIS Python 3.6+ if ArcPro is installed or Esri ArcGIS Python 2.7 if ArcGIS Desktop). This parameter is set per workspace--individual workspaces can have a different value for Python Compatibility parameter specified.
FME 2016 and older: In FME Workbench, go to Tools > FME Options and click on Translation. Under the Python Interpreter option, you will see an option to Use a Custom Python Interpreter. Clicking the browse button will allow you to navigate to the required interpreter.
If using 32-bit FME, the path to the ArcGIS Python Interpreter will resemble the following:
C:\Windows\System32\python27.dll
If using 64-bit FME, the path to the ArcGIS Python interpreter will resemble the following:
C:\Windows\SysWOW64\python27.dll
* It is important to note that if using 64-bit FME with ArcGIS (including arcpy), you will also need to have Esri's 64-bit background geoprocessing module. We highly recommend checking if the arcpy functionality you require is available with 64-bit background geoprocessing as some functionality is limited to 32-bit only. Remember: if you upgrade ArcGIS to a new version, make sure you also upgrade your Esri 64-bit background geoprocessing module. More on arcpy and 64bit can be found on this Esri documentation.
A more detailed explanation of Python interpreters can be found here: Choosing a different Python Interpreter (installation)
2. Check your System Path variable.
In a Python IDLE or Conda window, enter the following commands:
import sys print(sys.path)
This will print out the system path and show what Python libraries/directories your system is trying to access.
If you have ArcGIS 64-bit background geoprocessing installed on your system, Python 2.7 64-bit libraries will also be installed on your system (i.e. C:\Python27\ArcGISx6410.4). What this means is that the 64-bit libraries will most likely appear first in your system path. Though rare, there are instances where confusion can occur and FME attempts to load the 64-bit libraries when the 32-bit libraries are required. If you think this is what may be causing your arcpy error, you can try uninstalling the 64-bit background geoprocessing module from your system. If this does not work, you can try system path appending the required 32-bit libraries in your Python script before attempting to import the arcpy module (see suggestion #3). In a last ditch effort, you could try manually editing your system path variable; however, this is not recommended.
3. Add Path appends to your script before importing arcpy.
As alluded to above, the import arcpy error could be because the arcpy libraries have not been added to the path environment variable. To fix this, locate the DesktopXX.X.pth file found under C:\Python27\ArcGISXX.X\Lib\site-packages (where ArcGISXX.X references your installed version of ArcGIS), and append the file locations specified in its contents to the 'Path' Environment variable. Depending on your environment, you may also need to add C:\Python27\ArcGISXX.X\Lib\site-packages and C:\\Python27\\ArcGISXX.X\\lib as well.
An example script would begin as follows:
import sys sys.path.append("C:\\Python27\\ArcGISXX.X\\Lib\\site-packages") sys.path.append(r'C:\Program Files (x86)\ArcGIS\DesktopXX.X\arcpy') sys.path.append(r'C:\Program Files (x86)\ArcGIS\DesktopXX.X\ArcToolbox\Scripts') sys.path.append(r'C:\Program Files (x86)\ArcGIS\DesktopXX.X\bin') sys.path.append("C:\\Python27\\ArcGISXX.X\\lib") import arcpy
4. Do you have more than one version of Python installed on your machine (i.e. an independent installation of Python and the ArcGIS Installed version)?
If you have installed an independent installation of Python (same version as ArcGIS - i.e. Python 2.7) after installing your ArcGIS client you will have inadvertently overwritten the ArcGIS installed python interpreter (python27.dll) that FME needs to communicate with arcpy.
One possible way to avoid overwriting the python interpreter is to move the python27.dll installed by ArcGIS from the system default folder (i.e. C:\Windows\SysWOW64 or C:\Windows\System32) to the folder where the ArcGIS python executable is installed (i.e. C:\Python27\ArcGISXX.X). This MUST be done before any other installation of Python occurs. One would then install an independent version of Python 2.7 in a different installation folder (i.e. NOT C:\Python27). In FME, you would then need to point to where the ArcGIS python27.dll was moved by setting that path as the custom interpreter. In you Python script, you would need to system path append the needed arcpy libraries (See suggestion #3) before importing the arcpy module.
Please note, if you uninstall the independent version, your Python interpreter for ArcGIS may no longer work - You may receive a "no module named site" error. It may require manually removing remnants of the old interpreter from the system path or you can reinstall the independent version of Python (again - NOT in the C:\Python27 folder).
*Note - The same may apply for ArcGIS Pro and Python 3.x.
When all else fails, uninstalling all independent Python installations and then uninstalling and reinstalling your ArcGIS client could restore your Python instance and allow FME to use the arcpy module.
Comments
0 comments
Please sign in to leave a comment.