no module named error

J

Joe

I am trying to write/run a python script which imports from another
script which is located in my /usr/lib64/python2.6/site-packages/ dir,
but getting the following error.

$ python ./mytest.py
Traceback (most recent call last):
File "./mytest.py", line 45, in <module>
from moda import *
File "/usr/lib64/python2.6/site-packages/moda.py", line 7, in
<module>
import _moda
ImportError: No module named _moda


The script moda.py exists. My script is:

#!/usr/bin/python

import sys

from moda import *

def main(args = sys.argv[1:]):
print 'test'

if __name__ == '__main__' :
main()

Any idea what I'm doing wrong?
 
D

Diez B. Roggisch

Joe said:
I am trying to write/run a python script which imports from another
script which is located in my /usr/lib64/python2.6/site-packages/ dir,
but getting the following error.

$ python ./mytest.py
Traceback (most recent call last):
File "./mytest.py", line 45, in <module>
from moda import *
File "/usr/lib64/python2.6/site-packages/moda.py", line 7, in
<module>
import _moda
ImportError: No module named _moda


The script moda.py exists. My script is:

But it's searching for _moda.*, most probably a binary extension. Does that
exist, and if yes, has it the proper architecture or is it maybe 32 bit?

Diez
 
J

Joe

But it's searching for _moda.*, most probably a binary extension. Does that
exist, and if yes, has it the proper architecture or is it maybe 32 bit?

I'm just going by an example script. moda is a package I was given that
is written in C and has some python bindings and does run 64-bit. I'm on
gentoo. I'm not sure it's installed correctly, but it did come w/ a
setup.py, and I ran 'setup.py install' and it seemed to have installed
correctly.

$ sudo python ./setup.py install
running install
running build
running build_py
running install_lib
running install_egg_info
Removing /usr/lib64/python2.6/site-packages/moda-2.1-py2.6.egg-info
Writing /usr/lib64/python2.6/site-packages/moda-2.1-py2.6.egg-info
 
D

Diez B. Roggisch

Joe said:
I'm just going by an example script. moda is a package I was given that
is written in C and has some python bindings and does run 64-bit. I'm on
gentoo. I'm not sure it's installed correctly, but it did come w/ a
setup.py, and I ran 'setup.py install' and it seemed to have installed
correctly.

$ sudo python ./setup.py install
running install
running build
running build_py
running install_lib
running install_egg_info
Removing /usr/lib64/python2.6/site-packages/moda-2.1-py2.6.egg-info
Writing /usr/lib64/python2.6/site-packages/moda-2.1-py2.6.egg-info

You didn't answer my question. Did it install the _moda.* file the moda.py
is searching for?

Diez
 
J

Joe

Diez said:
You didn't answer my question. Did it install the _moda.* file the moda.py
is searching for?

Diez


Yeah, that's what I meant when I said the file exists above. There's a
moda.py in /usr/lib64/python2.6/site-packages/moda.py.
 
D

Diez B. Roggisch

Joe said:
Yeah, that's what I meant when I said the file exists above. There's a
moda.py in /usr/lib64/python2.6/site-packages/moda.py.

Please, read my post *carefully*. moda.py imports a file _moda.* (most
probably _moda.so), which seems *not* to be there.

Please verify that it exists and has the proper architecture.

This is your output:

"""
        File "/usr/lib64/python2.6/site-packages/moda.py", line 7, in
<module>
            import _moda
            ImportError: No module named _moda
"""
^^^^^

_moda, *not* moda.


Diez
 
J

Joe

Please verify that it exists and has the proper architecture.


Ah, ok, I thought those were one in the same. But I do have that file in
another directory elsewhere and I have that directory in my
LD_LIBRARY_PATH var.

Shouldn't that be enough to do it?
 
J

Joe

Just to clarify, I have "_moda.la" sitting in another directory which is
included in my LD_LIBRARY_PATH. And it is built for the 64bit arch.
 
D

Diez B. Roggisch

Joe said:
Just to clarify, I have "_moda.la" sitting in another directory which is
included in my LD_LIBRARY_PATH. And it is built for the 64bit arch.

No, the import-mechanism of python doesn't take LD_LIBRARY_PATH into
account, and even if it did - _moda.la is a simple archive-file, not a
shared library. It can't be dynamically loaded. Something in your
build-process is not working.

I suggest you

- clean out the source package from everything in there except the original
distribution - maybe simply removing & unpacking is the best idea.

- build the package again, and post the *full* output. This might give us a
clue.

Alternatively, if it's possible to share the module, do that.

Diez
 
J

Joe

No, the import-mechanism of python doesn't take LD_LIBRARY_PATH into
account, and even if it did - _moda.la is a simple archive-file, not a
shared library. It can't be dynamically loaded. Something in your
build-process is not working.

So how should my stuff find these libs?

Here's what I've recently learned ...

So if I have the dir path of my c libs inside my exported
LD_LIBRARY_PATH (which includes the following files), along w/ the dir
to the *.la file ...

_moda.a
_moda.la -> ../_moda.la
_moda.lai
_moda.so -> _moda.so.2.0.1
_moda.so.2 -> _moda.so.2.0.1
_moda.so.2.0.1
_moda.so.2.0.1T
_moda_la-moda_wrap.o

I get the 'ImportError: No module named _moda' error as in previous
post. But as I think your saying above, this should not work because
LD_LIBRARY_PATH doesn't get used.

I was at the python command line '>>>' and I did the following command.

import sys
sys.path.append('/home/me/my/c/libs/path/.libs')
# this is the path to the above listed files, and then when I did ...

import moda

Everything worked just fine.

But I'm not quite sure how to fix it in my script or env.
 
B

Benjamin Kaplan

So how should my stuff find these libs?

Here's what I've recently learned ...

So if I have the dir path of my c libs inside my exported
LD_LIBRARY_PATH (which includes the following files),  along w/ the dir
to the *.la file ...

_moda.a
_moda.la -> ../_moda.la
_moda.lai
_moda.so -> _moda.so.2.0.1
_moda.so.2 -> _moda.so.2.0.1
_moda.so.2.0.1
_moda.so.2.0.1T
_moda_la-moda_wrap.o

I get the 'ImportError: No module named _moda' error as in previous
post. But as I think your saying above, this should not work because
LD_LIBRARY_PATH doesn't get used.

I was at the python command line '>>>' and I did the following command.

import sys
sys.path.append('/home/me/my/c/libs/path/.libs')
# this is the path to the above listed files, and then when I did ...

  import moda

Everything worked just fine.

But I'm not quite sure how to fix it in my script or env.

http://docs.python.org/library/sys.html
"""
sys.path

A list of strings that specifies the search path for modules.
Initialized from the environment variable PYTHONPATH, plus an
installation-dependent default.

As initialized upon program startup, the first item of this list,
path[0], is the directory containing the script that was used to
invoke the Python interpreter. If the script directory is not
available (e.g. if the interpreter is invoked interactively or if the
script is read from standard input), path[0] is the empty string,
which directs Python to search modules in the current directory first.
Notice that the script directory is inserted before the entries
inserted as a result of PYTHONPATH.

A program is free to modify this list for its own purposes.

Changed in version 2.3: Unicode strings are no longer ignored.

"""
Python uses the PYTHONPATH variable to find modules/libraries, not
LD_LIBRARY_PATH.
 
D

Diez B. Roggisch

Joe said:
So how should my stuff find these libs?

Here's what I've recently learned ...

So if I have the dir path of my c libs inside my exported
LD_LIBRARY_PATH (which includes the following files), along w/ the dir
to the *.la file ...

_moda.a
_moda.la -> ../_moda.la
_moda.lai
_moda.so -> _moda.so.2.0.1
_moda.so.2 -> _moda.so.2.0.1
_moda.so.2.0.1
_moda.so.2.0.1T
_moda_la-moda_wrap.o

I get the 'ImportError: No module named _moda' error as in previous
post. But as I think your saying above, this should not work because
LD_LIBRARY_PATH doesn't get used.

I was at the python command line '>>>' and I did the following command.

import sys
sys.path.append('/home/me/my/c/libs/path/.libs')
# this is the path to the above listed files, and then when I did ...

import moda

Everything worked just fine.

But I'm not quite sure how to fix it in my script or env.

Your installation process is botched (no idea why, you don't show us
setup.py or anything else I asked for).


All that is missing is what I've asked you now several times before:
_moda.so is *NOT* alongside moda.py inside your python's site-packages
directory. Copy it in there, and the import will work *without* any
sys.path-hackery.

Of course you shouldn't do this by hand every time you need to, but instead
fix the whole package do to this when

python setup.py install

is invoked.

Diez
 
J

Joe

Your installation process is botched (no idea why, you don't show us
setup.py or anything else I asked for).

Sorry, but I do know how it's currently installed is exactly the way I
need it to be installed.
All that is missing is what I've asked you now several times before:
_moda.so is *NOT* alongside moda.py inside your python's site-packages
directory. Copy it in there, and the import will work *without* any
sys.path-hackery.

Yeah, that's something I don't want to do. But you've given me enough
info to help me understand what's going on and how to fix it. Thanks.
 
D

Diez B. Roggisch

Joe said:
Sorry, but I do know how it's currently installed is exactly the way I
need it to be installed.

It is? It wasn't working until you fiddled with sys.path - which you
needed help to find out. How's that exactly the way it is needed?
Yeah, that's something I don't want to do. But you've given me enough
info to help me understand what's going on and how to fix it. Thanks.

So it's ok that the installation copies moda.py, but not that it copies
_moda.so to the same destination?

Looks all very strange to me. But then - it's your system. Glad it works
for you.

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top