Problem installing pymatgen on Windows


#1

Hello dwinston,

I had responded to an old google groups post by you: here.

I did install pymatgen on a windows 10 build through your channel in Anaconda, but am running into an error:

Traceback (most recent call last):

  File "<ipython-input-1-33f7a5e33ac2>", line 1, in <module>
    runfile('C:/Users/Jack/Documents/Python/test.py', wdir='C:/Users/Jack/Documents/Python')

  File "C:\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
    execfile(filename, namespace)

  File "C:\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 88, in execfile
    exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)

  File "C:/Users/Jack/Documents/Python/test.py", line 8, in <module>
    import pymatgen as mg

  File "C:\Anaconda3\lib\site-packages\pymatgen\__init__.py", line 17, in <module>
    from .io.smart import read_structure, write_structure, read_mol, write_mol

  File "C:\Anaconda3\lib\site-packages\pymatgen\io\smart.py", line 28, in <module>
    from pymatgen.io.cif import CifParser, CifWriter

  File "C:\Anaconda3\lib\site-packages\pymatgen\io\cif.py", line 43, in <module>
    from pymatgen.symmetry.analyzer import SpacegroupAnalyzer

  File "C:\Anaconda3\lib\site-packages\pymatgen\symmetry\analyzer.py", line 53, in <module>
    raise ImportError(msg)

ImportError: Spglib required. Please either run python setup.py install for pymatgen, or install pyspglib from spglib.

The test script that resulted in this is simply “import pymatgen as mg”, as part of testing it. Do you have any ideas for solutions? I’ve google around with spglib but didn’t find any obvious solutions that worked.

Thanks!


#2

Hello,

I have a couple ideas.:

  1. Since v3.6.0, pymatgen does not bundle spglib as a dependency. In v3.3.4, which is the version built on my anaconda channel, spglib is bundled internally, and unsucessfully loading spglib is the cause of the ImportError in your traceback. I think that perhaps if I built a conda package for the latest version of pymatgen, it would work. I’m not sure I will have time to do this soon.

  2. You say you are using Windows 10. I would consider looking into Docker for Windows. Docker is an increasingly popular way to build reproducible environments. It can essentially give you the equivalent of a Linux virtual machine without hogging resources from your host Windows system. Pymatgen is supported by default for Unix systems (Linux, Mac OS), so this is a nice option.

I will let you know / post here about option 1 when I find the time. In the meantime, through, I’d be very interested in your trying option 2 and letting us all know how it goes.


#3

I made some time to give it a quick go for you. I uploaded conda builds for pymatgen v4.2.1 and its dependencies across all supported platforms, including Windows. See https://anaconda.org/dwinston/pymatgen. The command to install should be

conda install -c dwinston pymatgen=4.2.1

If you have further questions / follow-up, post back to the pymatgen mailing list thread.


#4

I tried option one and updated my conda install, but to no avail, I got a slightly different import error:

`Traceback (most recent call last):

  File "<ipython-input-1-33f7a5e33ac2>", line 1, in <module>
    runfile('C:/Users/Jack/Documents/Python/test.py', wdir='C:/Users/Jack/Documents/Python')

  File "C:\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
    execfile(filename, namespace)

  File "C:\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 88, in execfile
    exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)

  File "C:/Users/Jack/Documents/Python/test.py", line 8, in <module>
    import pymatgen as mg

  File "C:\Anaconda3\lib\site-packages\pymatgen\__init__.py", line 13, in <module>
    import spglib

  File "C:\Anaconda3\lib\site-packages\spglib\__init__.py", line 35, in <module>
    from .spglib import (get_version,

  File "C:\Anaconda3\lib\site-packages\spglib\spglib.py", line 35, in <module>
    from . import _spglib as spg

ImportError: cannot import name '_spglib'`

Which looks like the spglib library was successfully found this time, but may be getting called wrong? I went into the spglib.py file and changed line 35 from import _spglib to import spglib, which led to a different error:

File "C:\Anaconda3\lib\site-packages\pymatgen\__init__.py", line 13, in <module>
    import spglib

  File "C:\Anaconda3\lib\site-packages\spglib\__init__.py", line 51, in <module>
    __version__ = "%d.%d.%d" % get_version()

  File "C:\Anaconda3\lib\site-packages\spglib\spglib.py", line 39, in get_version
    return tuple(spg.version())

AttributeError: module 'spglib.spglib' has no attribute 'version'

For the sake of posterity I reverted the file back to the original version. Any ideas on this?

Thanks for your time!


#5

In regards to the Docker idea, I will give it a shot and check back in. I need to look more into Virtualbox VM’s with Hyper-V enabled first, as I saw there may be issues there and I need the VM’s to work / checking on how migration works.


#6

Hmm, no ideas. Maybe spglib needs to be built a special way with conda.


#7

A bit of an update:

Since the appearance of http://pymatgen.org/installation.html with instructions for Windows, I decided to try following that procedure on a VM of Windows 10 (I normally only use Mac OSX and Linux). Here are some issues I encountered with those instructions:

  1. After creating a conda environment(e.g. conda create --name pmg python, I needed to use activate pmg rather than source activate pmg. source wasn’t a recognized command in the anaconda prompt.

  2. spglib requires a change to its setup.py to accomodate there being no CFLAGS configuration variable for python on Windows.

  3. At this point, I was still getting the error on from . import _spglib. I found that after explicitly building the C extension via python setup.py build before a python setup.py install, spglib finally installed correctly, and a subsequent pip install python resulted in a successful import pymatgen at a prompt.

I was then able to e.g. instantiate a pymatgen.symmetry.analysys.SpacegroupAnalyzer and get data on a structure.

I hope this helps. In the near future, there should be a patch version of spglib released that addresses this issue, and I may try to re-build conda packages for spglib and pymatgen. This is not a priority for me, however. I hope this helps.


#8

A post was split to a new topic: Help on gist script