Trouble with Pymongo installation and dependencies


I am a new user of mongoDB, which I need in order to write and run atomate workflows on an HPC. I have downloaded and activated an atomate environment on an HPC (TACC Stampede2) using Mamba, and I am having a great amount of trouble with library/package compatibility. I have written a simple script to get information from a Mongodb database, see below:

from pymongo import MongoClient

client = MongoClient()

client = MongoClient(host="", port=27017, username='atomate_readwrite', password='mongo_readwrite', authSource='SunGroupCentral_atomatedb')

atomate_db = client.SunGroupCentral_atomatedb.tasks
result = atomate_db.find_one({"task_id": 1022})

from pymatgen.core.structure import Structure #Get structure from Atomate.
struct = Structure.from_dict(result['input']['structure'])


When I try to run this script, an error is thrown in the import statement. I will note that this same error is thrown if I open python in the command prompt and simply type “import pymongo”:

Traceback (most recent call last):
  File "", line 2, in <module>
    from pymongo import MongoClient
  File "/home1/09341/jamesgil/mambaforge/envs/atomate_env/lib/python3.9/site-packages/pymongo/", line 106
    def has_c() -> bool:
SyntaxError: invalid syntax

I suspect that this is a compatibility issue, but I have been unsuccessful in trying to resolve it. I currently am using Python 3.9.16 and Pymongo 4.3.3. I tried downgrading to Pymongo 3.11.0, but encountered a similar error again:

Traceback (most recent call last):
  File "", line 2, in <module>
    from pymongo import MongoClient
  File "/home1/09341/jamesgil/mambaforge/envs/atomate_env/lib/python3.9/site-packages/pymongo/", line 87, in <module>
    from pymongo.collection import ReturnDocument
  File "/home1/09341/jamesgil/mambaforge/envs/atomate_env/lib/python3.9/site-packages/pymongo/", line 29, in <module>
    from pymongo import (common,
  File "/home1/09341/jamesgil/mambaforge/envs/atomate_env/lib/python3.9/site-packages/pymongo/", line 35, in <module>
    from pymongo.ssl_support import (validate_cert_reqs,
  File "/home1/09341/jamesgil/mambaforge/envs/atomate_env/lib/python3.9/site-packages/pymongo/", line 27, in <module>
    import pymongo.pyopenssl_context as _ssl
  File "/home1/09341/jamesgil/mambaforge/envs/atomate_env/lib/python3.9/site-packages/pymongo/", line 27, in <module>
    from OpenSSL import SSL as _SSL
  File "/home1/09341/jamesgil/mambaforge/envs/atomate_env/lib/python3.9/site-packages/OpenSSL/", line 8, in <module>
    from OpenSSL import SSL, crypto
  File "/home1/09341/jamesgil/mambaforge/envs/atomate_env/lib/python3.9/site-packages/OpenSSL/", line 9, in <module>
    from OpenSSL._util import (
  File "/home1/09341/jamesgil/mambaforge/envs/atomate_env/lib/python3.9/site-packages/OpenSSL/", line 21
    def text(charp: Any) -> str:
SyntaxError: invalid syntax

Does anyone have any idea what might be throwing this error and how I can begin to resolve it? Thanks in advance for the help.

Best way to debug this is to try it outside your special environment.

  • Create your virtual environment using python -m venv myenv --system-site-packages
  • Activate your virtual environment via source myenv/bin/activate
  • pip install pymongo
  • Try your code again

It runs completely fine when I run the code on a clean environment with just Pymongo (and Pymatgen)

If I had gotten paid overtime for every hour over 40 years I’ve spent debugging other people’s pestilential frameworks … :rofl: