Hi,
Being new to python scripting, I am facing a simple problem.
I am writing a python script "MyScript.py" in which I am calling the third-part program PyMOL through the import function.
Here is the simplified script (mainly inspired from this blog: http://doeidoei.wordpress.com/2009/02/11/pymol-api-simple-example/)
#! /usr/bin/python
# Usage: MyScript.py <input>
# launch PyMOL from the terminal
import __main__
__main__.pymol_argv = [ 'pymol', '-qc']
import sys
import pymol
pymol.finish_launching()
# Input
file = sys.argv[1]
#run PyMOL command
pymol.cmd.do("load %s" % file)
#Exit PyMOL
pymol.cmd.quit()
I get this error message:
Traceback (most recent call last):
File "./MyScript.py", line 10, in <module>
import pymol
ImportError: No module named pymol
My path to Python site-packages: /Library/Python/2.7/site-packages
My path to PyMOL: /Users/me/my_apps/MacPyMOL_1.3.app/Contents/MacOS/MacPyMOL
(I made an alias pymol='MacPyMOL'
in .bash_profile
)
I also tried to replace in the script:
import sys
import pymol
by
import sys
sys.path.append("/Users/me/my_apps/MacPyMOL_1.3.app/Contents/MacOS")
import MacPyMOL
but still the same.
I looked at other forums but it didn't solve the problem:
- https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=CCP4BB;24c8090b.1011
- https://www.mail-archive.com/pymol-users@lists.sourceforge.net/msg08176.html
If someone could direct me to a solution...
Thanks!
Hi João,
Thanks for your help !
I followed your advice and installed PyMOL and all the dependencies with MacPort (it installed it in
/opt/local/bin/pymol
). I also linked pymol binary to/Library/Python2.7/site-packages
. But still the same error (i.e.ImportError: no module named pymol
). I am clearly missing something. Do I have to modify$PYMOL_PATH
,$PYTHON_PATH
or something?Note1:
It opens the windows (python icon is jumping on the dock), but I can write anything I want, nothing happens
Note2:
In PyMOL source, there is a file "PACKAGING" mentioning the below information. Do I need to relocate the files after a MacPort installation?
It's not the binary you should be linking!
After you installed PyMOL from macports, look in
/opt
for the location of_cmd.so
.This should be in a folder somewhere. The parent of this folder ( e.g. if
/opt/xxx/pymol
then/opt/xxx
), should be added to thePYTHONPATH
. Then try to import. Make sure that no other folder with pymol is in thePYTHONPATH
, to avoid conflicts.Fixed !
I exported the path to the parent folder of the one containing
_cmd.so
toPYTHONPATH
in my~/.bash_profile
. Works like a charm !Thanks a lot João for your help!