开发者

Python module installed or not installed?

How can I check if my Python module is successfully installed.

I did:

python setup.py install

inside the folder where my module was downloaded.

Now, I can see that this resulted in a folder inside this location:

/usr/lib/python2.4/site-packages (I can开发者_C百科 see my module folder is inside here)

Now I am using PHP to execute a script from this module:

exec("/usr/bin/python /usr/lib/python2.4/site-packages/MyModule/myModule script.py -v pixfx.xml 2>&1", $output, $return);

This runs the script.py file but does not load modules which this script requires. This script has code like this:

#! /usr/bin/env python 
import sys 
import os 
import getopt 
import re 
from myModule.ttLib import TTFont // this is line60 as I have removed comments

I get this error:

Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/MyModule/myModule/script.py", line 60, in ? from myModule.ttLib import TTFont ImportError: No module named myModule.ttLib

Does this mean there could be some problem with the way my module was installed. or How do I check if the module is installed correctly....

I also tried to do this in SSH terminal:

help('modules')

This listed a load of modules but my module name was missing.

Any help?

****** EDIT {Solved} ****** Reinstalling the module solved it. Its funny that what I used online SSH tool provided by Mediatemple, it didnt install the module correctly. Later when I installed using Terminal from my Mac computer, everything worked.

Just thought I will add this for other who might face similar problem.

Thanks


You can check that the Python interpreter that you are calling sees your module by doing:

/usr/bin/python -c "import MyModule"

This command should simply import MyModule/__init__.py and not complain about MyModule not being found.

Since there are many modules in your code, you actually want to create a package, not a module.

To do so, you can simply add an empty __init__.py file in MyModule/ and all its subpackages, so as to indicate that you have a package (i.e. is a folder that contains many modules).

If your ttLib is in MyModule/myModule/ttLib/, you can do the same and add an empty __init__.py file in MyModule/ and MyModule/myModule/, so as to declare that MyModule and MyModule/myModule are packages; you can then simply do:

from MyModule.myModule.ttLib import …

Hope this helps! The full documentation for packages can be found on the official site.


I am not an expert in Python, but one way to debug this is to launch the python prompt, and do import myModule then, some simple command that uses that module's constructs. If this works then your module installation is not the issue. If not your module wasnt installed.


You should see more than just the directory creation /usr/lib/python2.4/site-packages.


I reinstalled the module and everything works fine. It seems the module was not installed correctly.


Did you tell python to look under /usr/lib/python2.4/site-packages/MyModule/ for your module(s)? (You need to put a *.pth file in /usr/lib/python2.4/site-packages/ for that, or maybe you should not put them into an extra directory.)

Try the following in a python shell:

>>> import sys
>>> sys.path

What does that print? Does it include '/usr/lib/python2.4/site-packages/MyModule'?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜