Introduction
PyCharm Community Edition is a free, easy-to-use IDE for Python projects that can be configured 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, then choose the desired Python Interpreter by selecting the Previously configured interpreter button and Add Local Interpreter from the Add Interpreter drop-down.
The Python interpreter version must be one that is supported by the FME version used. The versions of Python supported can be found by going to <FME install>\python folder and looking for any "python3x" folders (eg. python36, python37, etc.) 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.exeEnter this path in the Interpreter field of the Add Python Interpreter dialog. Select OK to confirm these changes.
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 supported by the FME installation. You will need to modify the article's instructions 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.
Click on the Project Interpreter drop-down menu, then choose Show All... to bring up the Project Interpreters dialog window.
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 '+' 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 selected Python interpreter version.
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=1There 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.
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 (i.e., 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 fmeobjectsSelect Invalidate Caches… from the File menu and then restart PyCharm to update settings.
Using PyCharm
This section assumes the environment variables were added using PyCharm’s Edit/Debug Configuration option.
- Open the project created above.
- Add FMEBootStrap reference: import fmebootstrap
- Add FMEObjects reference: import fmeobjects
- PyCharm will be able to import FMEObjects