Skip to main content
Question

Startup Python Script import error under command line


Forum|alt.badge.img
Hi all?

 

 

I import a customized module in the Startup Python Script?when I run it under the workbench ?it‘s all right. But when run it under the command line, it failed with python importerror ?No module named ...

 

 

Can any one tell me why?

 

Thanks

6 replies

david_r
Evangelist
  • July 17, 2014
Hi,

 

 

are you sure that the fme.exe called by the command line is the same as the one used inside the Workbench? Might you have more than one version of FME installed?

 

 

Try the following from the command line:

 

 

fme.exe python

 

>>> import your_module_here

 

 

What does it say?

 

 

David

Forum|alt.badge.img
  • Author
  • July 18, 2014
Hi David,

 

 

Thanks for your advice, I installed FME server and desktop. The default EnvironmentVariable set  server path variable  before  desktop's. I changed it and everything is ok!

 

 

Thanks a lot !

 

 

LarryDai

 

 

 


david_r
Evangelist
  • July 18, 2014
Good to hear you found a solution.

 

 

Tip: when using batch files, never rely on the PATH settings to find the executable, use a complete path reference to the executable, e.g.

 

 

c:\\apps\\fme\\fme.exe <parameters>

 

 

David

takashi
Influencer
  • July 18, 2014
Hi,

 

 

Another tip: module path searching can be also resolved in source code level. Add these lines before importing your module in the startup script.

 

-----

 

import sys

 

sys.path.append('your_module_directory_path')

 

import your_module_here

 

-----

 

 

FYI.

 

Takashi

david_r
Evangelist
  • July 18, 2014
Takashi, that is a good tip, but I'd be a bit careful since there is a slight risk that you'd end up pointing at Python modules compiled for a different version, as well as possible naming collisions with different versions of the standard modules, etc.

 

 

David

takashi
Influencer
  • July 18, 2014
David, thanks for the pointing out. Agree that there is such a risk.

 

Version management could be troublesome if adopting the approach.

Reply


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