Skip to main content
Solved

How do I set the import path in FME's Python interpreter?


Forum|alt.badge.img

I have a module . in a folder (called '/wscloud/email_automation/wsa/lib')

I can import it if I append the path explicitly, but this seems like a very clumsy way to do this. Is there a way I can configure the import path in settings?

Thanks,

 

Fuad.

-----

import fmeobjects

 

import sys

 

sys.path.append('/wscloud/email_automation/wsa/lib') #ew!

 

import wsa

Best answer by carsonlam

Instead of modifying sys.path, paths can also be specified in the PYTHONPATH environment variable.

View original
Did this help you find an answer to your question?

9 replies

carsonlam
Safer
Forum|alt.badge.img
  • Safer
  • Best Answer
  • August 2, 2017

Instead of modifying sys.path, paths can also be specified in the PYTHONPATH environment variable.


Forum|alt.badge.img
  • Author
  • August 2, 2017
carsonlam wrote:

Instead of modifying sys.path, paths can also be specified in the PYTHONPATH environment variable.

Ah, thanks! Do you know how/where I do this on a Mac (macOS Sierra) so the change is permanent?

 

 


carsonlam
Safer
Forum|alt.badge.img
  • Safer
  • August 2, 2017
fkhan wrote:
Ah, thanks! Do you know how/where I do this on a Mac (macOS Sierra) so the change is permanent?

 

 

I think you can modify ~/.bash_profile and add 'export PYTHONPATH=foo'.

Forum|alt.badge.img
  • Author
  • August 2, 2017
carsonlam wrote:

Instead of modifying sys.path, paths can also be specified in the PYTHONPATH environment variable.

I did that and it works if I run python in Terminal

 

 

>>> import wsa

 

>>> import sys

 

>>> print sys.path

 

['', '/wscloud/email_automation/wsa/lib', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Sy...

 

..

 

 

but it still fails to import in FME

 

My command-line python path is very different from the one FME gives me if I print sys.path from each.

 

 

I think that successfully initialized bash, but not FME (but I'm out of my depth here)

carsonlam
Safer
Forum|alt.badge.img
  • Safer
  • August 2, 2017
fkhan wrote:
I did that and it works if I run python in Terminal

 

 

>>> import wsa

 

>>> import sys

 

>>> print sys.path

 

['', '/wscloud/email_automation/wsa/lib', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Sy...

 

..

 

 

but it still fails to import in FME

 

My command-line python path is very different from the one FME gives me if I print sys.path from each.

 

 

I think that successfully initialized bash, but not FME (but I'm out of my depth here)
After modifying .bash_profile, you may need to restart your machine for the change to fully take hold.

 

 


Forum|alt.badge.img
  • Author
  • August 2, 2017
carsonlam wrote:

Instead of modifying sys.path, paths can also be specified in the PYTHONPATH environment variable.

I shutdown and restarted but I have the same problem - Python in Terminal is good, but FME python does not know about PYTHONPATH :(

 

 


carsonlam
Safer
Forum|alt.badge.img
  • Safer
  • August 2, 2017
fkhan wrote:
I shutdown and restarted but I have the same problem - Python in Terminal is good, but FME python does not know about PYTHONPATH :(

 

 

I asked around, and unfortunately it turns out Macs behave differently here, and Workbench won't pick up environment variables this way. You might have to stick with doing it the ugly way. You can also try putting the Python module and its dependenciesin the same directory as the FME workspace, if that's possible in your use case.

Forum|alt.badge.img
  • Author
  • August 2, 2017
carsonlam wrote:

Instead of modifying sys.path, paths can also be specified in the PYTHONPATH environment variable.

Thanks for digging in - as a recovering PC guy and now Mac guy, usually things go the other way! I will try a sym link and if that fails, and an actual copy as fallback.

 

 


Forum|alt.badge.img
  • Author
  • August 3, 2017

Yup - putting a sym link to the include path in the folder that contains the workspace solves this. Thanks Carson!!!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings