I made a new conda environment with the Python 3.10.5 on CentOS 7.9 and installed the new version of the Materials Project API using “pip install mp-api” after installing pip via anaconda. The installation went fine. I then installed jupyter whose installation had some trouble with a dependency, but functionally seems to work.
Uninstalling pyzmq-22.3.0:
Successfully uninstalled pyzmq-22.3.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
maggma 0.47.3 requires pyzmq==22.3.0, but you have pyzmq 23.1.0 which is incompatible.
After starting Jupyter, I tried executing the python notebook from the 2021 Materials Project workshop that dealt with the API, namely " [MAPI Lesson (filled).ipynb" While the raw call requests.get to the database worked fine, attempting to read in the mp-api library failed
from mp_api import MPRester
mpr = MPRester(MP_API_KEY)
mpr.materials.available_fields
resulted in:
ModuleNotFoundError Traceback (most recent call last)
Input In [10], in <module>
----> 1 from mp_api import MPRester
ModuleNotFoundError: No module named 'mp_api'
The confusing thing is that if I start up ipython
Python 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:06:46) [GCC 10.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.
in the same environment, the same input works fine. What is wrong with the installation and why does it not work in Jupyter?
Are you able to install other packages and import them via Jupyter successfully?
Usually this error is because Jupyter is being launched from an environment different from the environment that the package was installed into, and usually requires installing a specific kernel (ipykernel) for that environment into Jupyter.
Yes I have installed matminer and pymatgen without problem. Is there a workaround for this?
Jupyter was installed via anaconda into a new virtual environment. I install mp-api using pip as recommended on the installation page. Matminer, pymatgen all seem fully functional. The pip installation was carried out within a new conda enviroment explicitly made for mp-api.
e.g.
conda create env -n mpapi
pip install mp-api
conda install jupyter
As I mentioned above using the mp-api under ipython (as opposed to Jupyter works fine)
Here are the details of the packages installed for jupyter and ipython. Do you have any ideas for a workaround or a fix?
jupyter --version
Selected Jupyter core packages...
IPython : 8.4.0
ipykernel : 6.15.0
ipywidgets : 7.7.0
jupyter_client : 7.3.4
jupyter_core : 4.10.0
jupyter_server : not installed
jupyterlab : not installed
nbclient : 0.6.4
nbconvert : 6.5.0
nbformat : 5.4.0
notebook : 6.4.12
qtconsole : 5.3.1
traitlets : 5.3.0
(mpapi) paulfons@muon:/data/Vasp/Friction/H2O_try2>ipython
Python 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:06:46) [GCC 10.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.
Yes, you need to either install mp-api inside the same environment that you launch Jupyter from (note that you can pip install inside a conda environment) or, alternatively, you need to install a kernel so that Jupyter can access your second environment, e.g.:
Thank you for your reply. I think I understand the concept, but I don’t understand the details. What is the exact procedure (from creating the environment onwards? I just gave it a try using
… and had the same problem with mp_api not being defined. Perhaps having the exact sequence will help me understand things better.
To be honest, I don’t really understand what the “python -m ipykernel install --user --name mpapi” command does as well. The “man python” result seems to indicate that this causes python to search sys.path and run the module as a script. What is being installed when I do this? What does the --name mpapi cause python to do – does python know about the mpapi environment of conda? (although obviously I am still doing something wrong as I still have the same problem). Is there a web page somewhere that documents this behavior that I could study up upon (as I have been occasionally bitten by this problem(bug?) before. I am grateful for your help!
I was re-reading what you wrote, namely "that you must install mp-api in the same environment I will run Jupyter from and I realized some of my preconceptions must be incorrect.
I thought when I made a (new) conda environment and switched to it and then installed pip using conda that all of the packages subsequently installed by pip (or conda) would be “in the same environment”. Due to the problems I am having accessing mp_api in Jupyter, it would seem that this is not the case. I am confused though why my last example did not work. Inside (a new) mpapi environment (created within conda), I installed pip (via conda). I then via pip, I installed mp-api, ipykernel, and notebook. I would have thought that all of these would be installed in the same environment. As I mentioned in my last note, I don’t really understand what “python -m ipykernel install --user --name mpapi” installs, so I am not sure how to troubleshoot my problem, but what is being installed in a different environment in the above?