Use PyCharm as FMEObjects Python IDE

Debbi L
Debbi L
  • Updated

FME Version

Introduction

PyCharm Community Edition is a free and easy to use IDE for Python projects that can be setup to use FMEObjects.
 

Installation and Configuration

Download and install PyCharm Community edition from https://www.jetbrains.com/pycharm/download/

 

Python FMEObjects projects should not use FME's internal Python, so you may need to install a full version of Python from www.python.org. You can also use the Python interpreter installed by ArcGIS.

 

Configure Pycharm 2022.2 Community Edition for FMEObjects

1. Start PyCharm
Start PyCharm and go to File > New Project to bring up the Create Project dialog

2. Set Desired Python Interpreter
A New Project dialog window will open. Set the project location and choose the desired Python Interpreter by selecting the Previously configured interpreter button and selecting Add Local Interpreter from the Add Interpreter drop-down.
Configure Python interpreter when creating new project in Pycharm 2022.2 Community Edition

Note: The Python interpreter version must be one that is supported by the FME version used. The bit-version must also match.  For example, FME 2022.x supports 64-bit Python 3.6-3.9 as 32-bit support has been dropped starting in this version.

If you want to use the arcpy module within your script, select the ArcGIS Python interpreter. You may have to add the interpreter to the interpreter list if it has not already been previously configured.

In the Add Python Interpreter dialog, select Virtualenv Environment from the left sidebar and select the Existing button. The default ArcGIS Pro Python 3 environment’s interpreter is located at:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\argispro-py3\python.exe

Enter this path in the Interpreter field of the Add Python Interpreter dialog. Select OK to confirm these changes.

Configure ArcGIS Pro Python 3 interpreter as the project interpreter in Pycharm

Note: This article uses ArcGIS Pro 3.0’s Python 3.9 interpreter with FME 2022.0. However, you may choose to use a different Python interpreter version as long as it is one that the FME installed supports. You will need to modify the instructions in the article to match the Python version used.

 

3. Add Library Paths to Use FMEObjects

To use FMEObjects within the IDE, you will need to add library paths. To do so, go to File > Settings or enter Ctrl-Alt-S to bring up the Settings dialog. Click on Project:<YourProjectName> located on the left sidebar, then on Project Interpreter.Use the Settings option in the File menu to navigate to the project's Python Interpreter dialog
 
Click on the Project Interpreter drop-down menu, then choose Show All... to bring up the Project Interpreters dialog window.Click on Show All to access the Python Interpreters dialog
 
Select the project interpreter and then click on the file tree icon on the top right to bring up the Interpreter Paths
dialog.
Click on the file tree icon on the top right to bring up the Interpreter Paths dialog
 
Click on the '+' icon and add the following paths to the Interpreter Paths dialog. <FME install> is the FME installation folder, eg. C:\Program Files\FME and <pythonVersion> is the Python interpreter version.
  • <FME install>
  • <FME install>\python
  • <FME install>\python\<pythonVersion>
    •  
    • For example, if using Python 3.9, add <FME install>\python\python39. If using Python 3.10, add <FME install>\python\python310, etc.

If using FME 2023.1 and older, the following path must also be added:

  • <FME install>\fmeobjects\<pythonVersion>
      • For example, if using Python 3.9, add <FME install>\fmeobjects\python39. If using Python 3.10, add <FME install>\fmeobjects\python310, etc.
Ensure the correct paths are added based on the Python interpreter version selected.

Four FME paths should be added to the Interpreter Paths dialog

Click OK to close the Interpreter Paths dialog. Click OK to close the Project Interpreters and click OK to exit the Settings dialog.
 
4. Use fmebootstrap to Resolve Load-Time Dependencies
Due to changes introduced in Python 3.8 to stop looking through the PATH variable on Windows when searching for load-time dependencies, so the fmebootstrap library was created to help resolve load-time dependencies. It modifies the environment so FMEObject's load-time dependencies can be found by the interpreter.

In order to use fmebootstrap, one or more environment variables will need to be set when importing FME modules like fmeobjects in an external environment such as PyCharm.

FME_HOME = <FME install directory>

If the Python interpreter selected uses a Conda environment (eg. ArcGIS Pro Python, Spyder, etc.), the following environment variable will also need to be set:

CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1

 

There are two ways these environment variables can be set in PyCharm:

1) In the Run/Debug Configurations dialog for the Python script file

Select Edit Configurations from the Python file dropdown on the top right-hand corner. In the Run/Debug Configurations dialog, add the environment variables that need to be set in the Environment Variables field. This option is more suited if the script is only going to be run in Pycharm.

Set Environment Variables within Pycharm with the Run/Debug Configuration dialog

2) Within the Python script itself:

The Python script should have a section that imports the os module, sets the environment variables, imports fmebootstrap, and then imports fmeobjects. This option is more suitable if the script is planned to be run outside PyCharm (ie. PyCharm is only the test environment).

import os

# Modify the path if FME is installed in another location
os.environ['FME_HOME'] = r"C:\Program Files\FME"

os.environ['CONDA_DLL_SEARCH_MODIFICATION_ENABLE'] = str(1)

import fmebootstrap
import fmeobjects

Set environment variables required in the script


Select Invalidate Caches… from the File menu and then restart PyCharm to update settings.Invalide caches and restart Pycharm so the changes made takes effect

 

Using PyCharm

Note: this section assumes the environment variables were added using the PyCharm’s Edit/Debug Configuration option.

  1. Open project created above.
  2. Add FMEBootStrap reference: import fmebootstrap
  3. Add FMEObjects reference: import fmeobjects
  4. PyCharm will be able to import FMEObjects

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.