6
$\begingroup$

I installed chemcoord (link to documentation) on MacOS in a fresh Python 3.7 virtual environment. When I tried to run the first line of code from the tutorial:

import chemcoord as cc
data = cc.Cartesian.read_xyz('/path/to/xyz/file/data.xyz')

I get the following AttributeError:

Traceback (most recent call last):
  File "/Users/deyanmihaylov/Documents/Work/pyscf_geometry/chemcoord.py", line 1, in <module>
    import chemcoord as cc
  File "/Users/deyanmihaylov/Documents/Work/pyscf_geometry/chemcoord.py", line 6, in <module>
    water = cc.Cartesian.read_xyz('/Users/deyanmihaylov/Documents/Work/pyscf_geometry/diborane.xyz')
AttributeError: module 'chemcoord' has no attribute 'Cartesian'

When I run print(dir(cc)) after importing as above, I get:

['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'cc']

When I run pip list in my terminal, chemcoord is definitely there:

Package             Version
------------------- ---------
...
chemcoord           2.0.5
...

How chemcoord was installed

From PyPI:

python3.7 -m venv coords
source coords/bin/activate
pip install chemcoord

This gives an environment (coords) which presumably has chemcoord installed

From source code:

python3.7 -m venv coords
source coords/bin/activate
git clone [email protected]:mcocdawc/chemcoord.git
cd chemcoord
pip install .

This again gives an environment where chemcoord is installed (verified through pip list) and should be available.


Since this is code given in the tutorials in the documentation, I suspect there is something that I am missing. What could I be doing wrong with either the installation or running the code?

$\endgroup$
10
  • 1
    $\begingroup$ I've sent a link of this question to Oskar Weser, the first author on the paper about chemcoord. $\endgroup$ Commented Jun 8, 2023 at 1:06
  • 3
    $\begingroup$ Did you use pip install or conda ? Please add that detail in your question $\endgroup$ Commented Jun 8, 2023 at 5:59
  • $\begingroup$ Have you checked the Python code? $\endgroup$ Commented Jun 8, 2023 at 11:27
  • 3
    $\begingroup$ The installation page suggests it requires python >=3.7. One thing you can check is what attributes are available for chemcoord, using print(dir(chemcoord)) or tab completing in an IPython terminal. $\endgroup$
    – Tyberius
    Commented Jun 9, 2023 at 2:17
  • 3
    $\begingroup$ Thanks @NikeDattani for including me in this post. Indeed I am the author of that package and would be happy to help. I just checked again if I did mess up the export of Cartesian to the root namespace, but that seems fine. What do you get if you query package attributes like cc.__version__ or cc.__file__? How exactly did you install? $\endgroup$
    – mcocdawc
    Commented Jun 9, 2023 at 7:56

1 Answer 1

4
$\begingroup$

Your problem

You are running a script called chemcoord.py which has the same name as the package itself. Your chemcoord.py script does not have the Cartesian attribute defined anywhere, but the Python interpreter is looking for it in your script.

The program works for me

The installation took several minutes, starting with:

[nike@gra-login3 ~]$ pip install  chemcoord

The output is as follows:

Defaulting to user installation because normal site-packages is not writeable
Looking in links: /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/avx2, /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/generic, /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic
Collecting chemcoord
  Downloading chemcoord-2.0.5-py3-none-any.whl (96 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 96.8/96.8 KB 6.6 MB/s eta 0:00:00
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/avx2/pandas-2.0.0+computecanada-cp310-cp310-linux_x86_64.whl
Collecting pymatgen
  Downloading pymatgen-2023.5.31.tar.gz (9.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.7/9.7 MB 29.3 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: six in /cvmfs/soft.computecanada.ca/easybuild/software/2020/avx2/Core/python/3.10.2/lib/python3.10/site-packages (from chemcoord) (1.16.0)
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/generic/scipy-1.10.1+computecanada-cp310-cp310-linux_x86_64.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/generic/numba-0.56.3+computecanada-cp310-cp310-linux_x86_64.whl
Collecting sympy
  Downloading sympy-1.12-py3-none-any.whl (5.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.7/5.7 MB 93.4 MB/s eta 0:00:00
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/generic/numpy-1.24.2+computecanada-cp310-cp310-linux_x86_64.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/sortedcontainers-2.4.0+computecanada-py3-none-any.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/generic/numpy-1.23.2+computecanada-cp310-cp310-linux_x86_64.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/avx2/llvmlite-0.39.1+computecanada-cp310-cp310-linux_x86_64.whl
Requirement already satisfied: setuptools in /cvmfs/soft.computecanada.ca/easybuild/software/2020/avx2/Core/python/3.10.2/lib/python3.10/site-packages (from numba>=0.35->chemcoord) (60.7.1)
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/pytz-2023.3+computecanada-py2.py3-none-any.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/python_dateutil-2.8.2+computecanada-py2.py3-none-any.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/tzdata-2023.3+computecanada-py2.py3-none-any.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/spglib-2.0.2+computecanada-cp310-cp310-linux_x86_64.whl
Collecting ruamel.yaml>=0.17.0
  Downloading ruamel.yaml-0.17.31-py3-none-any.whl (112 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 112.1/112.1 KB 5.6 MB/s eta 0:00:00
Collecting palettable>=3.1.1
  Downloading palettable-3.3.3-py2.py3-none-any.whl (332 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 332.3/332.3 KB 15.7 MB/s eta 0:00:00
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/tqdm-4.65.0+computecanada-py3-none-any.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/tabulate-0.9.0+computecanada-py3-none-any.whl
Collecting uncertainties>=3.1.4
  Downloading uncertainties-3.1.7-py2.py3-none-any.whl (98 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 98.4/98.4 KB 6.0 MB/s eta 0:00:00
Collecting pybtex
  Downloading pybtex-0.24.0-py2.py3-none-any.whl (561 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 561.4/561.4 KB 30.7 MB/s eta 0:00:00
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/avx2/matplotlib-3.7.0+computecanada-cp310-cp310-linux_x86_64.whl
Collecting requests
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 KB 5.1 MB/s eta 0:00:00
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/networkx-3.1+computecanada-py3-none-any.whl
Collecting monty>=3.0.2
  Downloading monty-2023.5.8-py3-none-any.whl (67 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 67.3/67.3 KB 5.2 MB/s eta 0:00:00
Collecting mp-api>=0.27.3
  Downloading mp_api-0.33.3-py3-none-any.whl (75 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 75.6/75.6 KB 6.9 MB/s eta 0:00:00
Collecting plotly>=4.5.0
  Downloading plotly-5.15.0-py2.py3-none-any.whl (15.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 15.5/15.5 MB 72.9 MB/s eta 0:00:00
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/mpmath-1.3.0+computecanada-py3-none-any.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/avx2/Pillow-9.5.0+computecanada-cp310-cp310-linux_x86_64.whl
Collecting fonttools>=4.22.0
  Downloading fonttools-4.40.0-py3-none-any.whl (1.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 MB 62.8 MB/s eta 0:00:00
Requirement already satisfied: packaging>=20.0 in /cvmfs/soft.computecanada.ca/easybuild/software/2020/avx2/Core/python/3.10.2/lib/python3.10/site-packages (from matplotlib>=1.5->pymatgen->chemcoord) (21.3)
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/cycler-0.11.0+computecanada-py3-none-any.whl
Requirement already satisfied: pyparsing>=2.3.1 in /cvmfs/soft.computecanada.ca/easybuild/software/2020/avx2/Core/python/3.10.2/lib/python3.10/site-packages (from matplotlib>=1.5->pymatgen->chemcoord) (3.0.7)
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/generic/contourpy-1.0.7+computecanada-cp310-cp310-linux_x86_64.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/avx2/kiwisolver-1.4.4+computecanada-cp310-cp310-linux_x86_64.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/msgpack-1.0.4+computecanada-cp310-cp310-linux_x86_64.whl
Collecting typing-extensions>=3.7.4.1
  Downloading typing_extensions-4.6.3-py3-none-any.whl (31 kB)
Collecting emmet-core>=0.54.0
  Downloading emmet_core-0.55.5-py3-none-any.whl (152 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 152.4/152.4 KB 10.4 MB/s eta 0:00:00
Collecting tenacity>=6.2.0
  Downloading tenacity-8.2.2-py3-none-any.whl (24 kB)
Collecting urllib3<3,>=1.21.1
  Downloading urllib3-2.0.3-py3-none-any.whl (123 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 123.6/123.6 KB 13.7 MB/s eta 0:00:00
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/charset_normalizer-3.1.0+computecanada-py3-none-any.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/idna-3.4+computecanada-py3-none-any.whl
Collecting certifi>=2017.4.17
  Downloading certifi-2023.5.7-py3-none-any.whl (156 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 157.0/157.0 KB 14.2 MB/s eta 0:00:00
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/ruamel.yaml.clib-0.2.7+computecanada-cp310-cp310-linux_x86_64.whl
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/generic/future-0.18.2+computecanada-py3-none-any.whl
Collecting latexcodec>=1.0.4
  Downloading latexcodec-2.0.1-py2.py3-none-any.whl (18 kB)
Processing /cvmfs/soft.computecanada.ca/custom/python/wheelhouse/gentoo/avx2/PyYAML-6.0+computecanada-cp310-cp310-linux_x86_64.whl
Collecting pydantic>=1.10.2
  Downloading pydantic-1.10.9-py3-none-any.whl (157 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 157.8/157.8 KB 11.9 MB/s eta 0:00:00
Building wheels for collected packages: pymatgen
  Building wheel for pymatgen (pyproject.toml) ... done
  Created wheel for pymatgen: filename=pymatgen-2023.5.31-cp310-cp310-linux_x86_64.whl size=11253958 sha256=c5db183a0b4b5607ae7634b2e2e41fb95162745158cab59f8942a68eb3f74666
  Stored in directory: /home/nike/.cache/pip/wheels/74/c0/d0/0aaf31f88e7cad712af75fc8dbabb792bcdac99107d85376b4
Successfully built pymatgen
Installing collected packages: sortedcontainers, pytz, msgpack, mpmath, urllib3, tzdata, typing-extensions, tqdm, tenacity, tabulate, sympy, ruamel.yaml.clib, PyYAML, python-dateutil, pillow, palettable, numpy, networkx, monty, llvmlite, latexcodec, kiwisolver, idna, future, fonttools, cycler, charset-normalizer, certifi, uncertainties, spglib, scipy, ruamel.yaml, requests, pydantic, pybtex, plotly, pandas, numba, contourpy, matplotlib, emmet-core, mp-api, pymatgen, chemcoord
Successfully installed PyYAML-6.0+computecanada certifi-2023.5.7 charset-normalizer-3.1.0+computecanada chemcoord-2.0.5 contourpy-1.0.7+computecanada cycler-0.11.0+computecanada emmet-core-0.55.5 fonttools-4.40.0 future-0.18.2+computecanada idna-3.4+computecanada kiwisolver-1.4.4+computecanada latexcodec-2.0.1 llvmlite-0.39.1+computecanada matplotlib-3.7.0+computecanada monty-2023.5.8 mp-api-0.33.3 mpmath-1.3.0+computecanada msgpack-1.0.4+computecanada networkx-3.1+computecanada numba-0.56.3+computecanada numpy-1.23.2+computecanada palettable-3.3.3 pandas-2.0.0+computecanada pillow-9.5.0+computecanada plotly-5.15.0 pybtex-0.24.0 pydantic-1.10.9 pymatgen-2023.5.31 python-dateutil-2.8.2+computecanada pytz-2023.3+computecanada requests-2.31.0 ruamel.yaml-0.17.31 ruamel.yaml.clib-0.2.7+computecanada scipy-1.10.1+computecanada sortedcontainers-2.4.0+computecanada spglib-2.0.2+computecanada sympy-1.12 tabulate-0.9.0+computecanada tenacity-8.2.2 tqdm-4.65.0+computecanada typing-extensions-4.6.3 tzdata-2023.3+computecanada uncertainties-3.1.7 urllib3-2.0.3

Now everything works:

[nike@gra-login3 ~]$ python
Python 3.10.2 (main, Feb  4 2022, 19:10:35) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import chemcoord as cc
>>> cc.__version__
'2.0.5'
>>> cc.__file__
'/home/nike/.local/lib/python3.10/site-packages/chemcoord/__init__.py'

Credits

While trying to get this question answered, I tried program myself and it worked (see the above output). I then went to the Python chatroom at StackOverflow and sought opinions there. Within three minutes Josh Rogan figured out the issue. He's not answering due to the current strike, but I've committed to giving Josh a bounty equal to the rep earned on this post if he decides to start posting answers again.

$\endgroup$
2
  • 2
    $\begingroup$ Thank you for this relieving answer. I was really confused. $\endgroup$
    – mcocdawc
    Commented Jun 12, 2023 at 16:17
  • $\begingroup$ Thank you @Nike Dattani for the answer and for figuring out what I was doing wrong. $\endgroup$
    – John
    Commented Jun 12, 2023 at 20:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .