简体   繁体   English

qsub和python,导入.py模块,但为.pyf返回ImportError

[英]qsub and python, imports .py modules but returns ImportError for .pyf

I am trying to submit a job via qsub myScript.sh -cwd , where the shell script runs a Python-2.7 script, myPython.py . 我试图通过qsub myScript.sh -cwd提交作业,其中shell脚本运行Python-2.7脚本myPython.py

    # myScript.sh
    python2.7 myPython.py

Now, myPython.py needs to import a Python package that is stored in my local directory so the script starts with 现在, myPython.py需要导入存储在本地目录中的Python包,因此脚本以

    # myPython.py
    import sys
    sys.path.append('/file/path/for/package')
    import package

After submitting the job, the log file contains the following output from Python: 提交作业后,日志文件包含Python的以下输出:

    ImportError: No module named problem_c

This error occurs after several modules have been imported from *.py files without returning errors, so I am fairly certain that this is not a problem with the path. *.py文件导入了几个模块而没有返回错误之后,就会发生此错误,因此,我可以肯定这不是路径问题。 The only difference I find is that the problem_c file ends in .pyf (ie problem_c.pyf ). 我发现的唯一区别是problem_c文件以.pyf (即problem_c.pyf )。 It is stored in the same directory as the the modules ending in .py . 它与以.py结尾的模块存储在同一目录中。

When I run the script locally, as python2.7 myPython.py , this error does not occur when the package loads. 当我在本地运行脚本(如python2.7 myPython.py时,在加载程序包时不会发生此错误。 However, the job is too memory intensive to complete without submitting it to queue. 但是,该作业占用大量内存,因此无法将其提交到队列中。 Why are modules written as .pyf files being treated differently when I use qsub , and how can I import them in this case? 为什么当我使用qsub ,以.pyf文件形式编写的模块会受到不同对待,在这种情况下如何导入它们?

(If it matters, the cluster I'm working on was set up with Sun Grid Engine.) (如果很重要,我正在使用的群集是使用Sun Grid Engine设置的。)

Thanks for your thoughts. 感谢您的想法。

Or f2py. 或f2py。 It's obviously you didn't add the module on your cluster. 显然您没有在集群上添加模块。

Here's how you can import a module with its path: 这是导入路径及其模块的方法:

import imp
module_name = imp.load_source('module_name', '/abs/path/to/module/module_name.py')

# usage
module_name.function()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM