Question: ImportError: No module named pymol (Mac)
1
gravatar for lqdo2000
5.1 years ago by
lqdo200020
Australia
lqdo200020 wrote:

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 !

pymol python • 10.0k views
ADD COMMENTlink modified 5.1 years ago • written 5.1 years ago by lqdo200020
2
gravatar for João Rodrigues
5.1 years ago by
João Rodrigues2.5k
Stanford University, U
João Rodrigues2.5k wrote:

Hi,

In MacOSX with a default installation of MacPymol you cannot use the API because there is no _cmd.so file. What I usually do it to install pymol via fink/macports or compile it from source somewhere. Not the best solution but then you can get the file you are missing. 

If you manage to find a better solution, it'd be great to share !

ADD COMMENTlink written 5.1 years ago by João Rodrigues2.5k
0
gravatar for lqdo2000
5.1 years ago by
lqdo200020
Australia
lqdo200020 wrote:

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:

$ pymol -q
Detected OpenGL version 2.0 or greater. Shaders available.
Detected GLSL version 1.20.
Adjusting settings to improve performance for ATI cards.

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?

Under MacOS X, PYMOL_PATH is self-defining.  Under Windows, this
environment variable is stored in the registry during installation.
Under Unix, PYMOL_PATH needs to be defined prior to startup, usually
by "pymol.com".

=======================================================
Suggested File Locations (for package managed installs)
=======================================================

== pymol package ==

modules/pymol  -> /usr/lib/pythonX.X/site-packages/pymol
modules/chempy -> /usr/lib/pythonX.X/site-packages/chempy
modules/pmg_tk -> /usr/lib/pythonX.X/site-packages/pmg_tk

scripts     -> /usr/share/pymol/scripts (RUNTIME REQUIREMENT)
data        -> /usr/share/pymol/data (RUNTIME REQUIREMENT)

examples    -> /usr/share/doc/pymol/examples
doc         -> /usr/share/doc/pymol/doc
LICENSE     -> /usr/share/doc/pymol/LICENSE
CHANGES     -> /usr/share/doc/pymol/CHANGES
README      -> /usr/share/doc/pymol/README

== pymol-devel package ==

test        -> /usr/share/pymol/test (TESTING RUNTIME REQUIREMENT)

DEVELOPERS  -> /usr/share/doc/pymol/DEVELOPERS
PACKAGING   -> /usr/share/doc/pymol/PACKAGING
ADD COMMENTlink modified 5.1 years ago • written 5.1 years ago by lqdo200020

It's not the binary you should be linking! 

After you installed PyMOL from macports, look in /opt for the location of _cmd.so.

find /opt/ -name '_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 the PYTHONPATH. Then try to import. Make sure that no other folder with pymol is in the PYTHONPATH, to avoid conflicts.

ADD REPLYlink written 5.1 years ago by João Rodrigues2.5k

Fixed !

I exported the path to the parent folder of the one containing _cmd.so to PYTHONPATH in my ~/.bash_profile. Works like a charm !

Thanks a lot João for your help !

ADD REPLYlink written 5.1 years ago by lqdo200020
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1614 users visited in the last hour