Working on a cluster with CENTOS and Python 2.6.6
Trying to add modules to a python function
The function some_func.py looks like:
#!/usr/bin/env python
from __future__ import division
import sys
sys.path.append('/Users/username/modules')
import some_module as sm
In the /Users/username/modules I have two files: __init__.py and some_module.py
It works when I do it on my Mac, but does not work when I run it the CENOS machine.
I get the error: Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named some_module
Any ideas what might be going on?
Adding /Users/username/modules
to your path and then trying to import some_module
means that Python is actually looking for a directory named /Users/username/modules/some_module
, which would contain (at a minimum) a file named __init__.py
.
I don't know why it worked on your Mac computer. Perhaps you have another copy of some_module
laying around in another place, and it's finding that copy?
Try this on your Mac:
import some_module
print (some_module.__file__)
And see what it reports as the full pathname.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.