5

I have pymol downloaded and in use on my mac. I open it from the applications folder. I can successfully run a python script in it. However, I cannot import any libraries within that script. The way I currently know to add importable libraries to a python environment is through anaconda navigator. Is there a way to get anaconda to see the pymol application as a environment that I could then add libraries to?

Is there an easier way to add the libraries? I have tried to use pip install, but I don't understand it much, and I have been unable to find a way to pip install into my pymol environment.

Sorry, if this question has a very simple answer, I am new to programming.

Ben
  • 121
  • 8
  • maybe try to make a virtual environment first, in which you can install all your libs seperately – WiseDev Jul 05 '19 at 09:48
  • Forums seem to indicate that a version of Python is packaged within PyMOL.. Is there a `syspython` version of PyMOL? It says that would use the system Python version, and therefore system Python packages. – blueteeth Jul 05 '19 at 09:52
  • I managed to add pymol to anaconda as a library, but I am unable to launch it as a program from there. If I could figure out how to do so, it would also solve the problem. – Ben Jul 05 '19 at 09:56
  • In PyMol you could try `import sys` and then `print(sys.executable)` which should give you the Python executable it is using. Inside this folder there should be a folder `scripts` and there you should find `pip` for installing programs for your PyMol instance. – Maximilian Peters Aug 19 '19 at 19:29

2 Answers2

3
  • PyMol installer installs its own Python3.
  • To install PyMOL with your system anaconda you use conda install -c schrodinger pymol.
  • To install without Anaconda you have to compile it after installing python3-dev libglm-dev freeglut3-dev libglew-dev libpng12-dev libfreetype6-dev build-essential libxml++3.6-dev, so is notoriously hard.
  • Making a symbolic link from your system/conda python (say on a Mac ln -s /Applications/PyMOL.app/Contents/lib/python3.7/site-packages/pymol /Users/myname/anaconda3/lib/python3.7/site-packages/pymol) for pymol and for the egg file and the Schrödinger-made dependencies apbs freemol glew mengine mpeg_encode mtz2ccp4_px pdb2pqr pmw and pip the non-Schrödinger libopenblas or similar hacks do not seem to work for anyone —many have tried.

So if you want to use your script in PyMOL and install a library simply call the python within PyMOL, say /Applications/PyMOL.app/Contents/bin/python3.7 on a Mac. On a Linux you probably installed with conda install -c schrodinger pymol to not end up with 1.8 anyway, so this does not apply. On Windows, you will have to find where it is installed (import sys and print sys.executable in PyMOL).

So if you want to use PyMOL within your Python code conda install -c schrodinger pymol or compile it if pip. Yes, it's wasteful and you have to re-add the licence.
About this mode, remember to run without the display pymol_argv = ['pymol', '-qc'] or __main__.pymol_argv = ['pymol', '-qc'].

Matteo Ferla
  • 2,128
  • 1
  • 16
  • 27
  • 1
    A meta-footnote, this question is more suited at [bioinformatics.stackexchange.com](https://bioinformatics.stackexchange.com/) – Matteo Ferla Nov 21 '19 at 16:00
1

If you want to use pymol as an import in your backend code:

You could create a virtual environment based on the python3 version that PyMOL ships. As Matteo says, it's a separate python3 that gets installed on your system.


  1. The way to find which one is "PyMol python"(as opposed to your other pythons) is to open PyMOL the GUI and execute import sys; print(sys.executable). Props to Maximilian Peters.

  2. Now that you know where the pymol's python3 exec is you can create a virtualenv based on it: virtualenv --python="/usr/bin/python3". In my case it happened to be /usr/bin/python but yours might be different.

  3. Now you can install packages into this virtual environment and import pymol to invoke its functionality alongside your regular python/django/flask/numpy code or whatever.

  4. If you want to use it as a module, follow https://pymolwiki.org/index.php/Linux_Install and add the $PYMOL_PATH/modules/ folder to your python path (export PYTHONPATH="$PYTHONPATH:$PYMOL_PATH/modules/:"). So you can put your pymol in a completely different location so logn as the python that runs your main scritp/application has the modules files on path.

Paraphrasing Leandro from the forum:

python3 setup.py build install --home=path_to_pymol/
--install-lib=path_to_pymol/modules/ --install-scripts=path_to_pymol/
 The part you are interested in is the modules.

 In addition, you need to add `path_to_pymol/modules/` to your python

paths. You can add these to the .bashrc file:

export PYMOL_PATH=path_to_pymol/
export PYTHONPATH=$PYTHONPATH:$PYMOL_PATH/modules:
rtviii
  • 807
  • 8
  • 19