Settings and utility functions (utils.ipynb)

I’m having a problem by creating a file (utils.ipynb) for CADET-Tutorial
I get this error from row 11 :
AttributeError: ‘str’ object has no attribute 'exists’

and this is my code:

1-import platform
2-from pathlib import Path
3-from cadet import Cadet

4-cadet_bin_path = ‘c:/cadet/bin’

5-if platform.system() == ‘Windows’:
6- cadet_path = “c:/cadet/bin/cadet-cli.exe”
7- lwe_path = “c:/cadet/bin/createLWE.exe”
9- cadet_path = cadet_bin_path / “cadet-cli”
10- lwe_path = cadet_bin_path / “createLWE”

11-if cadet_path.exists() and lwe_path.exists():
12- Cadet.cadet_path = cadet_path.as_posix()
13-elif cadet_path.exists() and not lwe_path.exists():
14- print(“CADET was found but createLWE.exe was not found. Please make sure that none of the
files have been moved.”)
16- print(“CADET could not be found. Please check the bin path”)

What should I do?
thanks in advance

Hi Hamed,

I assume you copied this snippet from the tutorials:

#     windows: C:\Users\<username>\cadet\bin
#     linux: ~/cadet/bin
cadet_bin_path = Path.home() / "cadet"/ "bin"

if platform.system() == 'Windows':
    cadet_path = cadet_bin_path / "cadet-cli.exe"
    lwe_path = cadet_bin_path / "createLWE.exe"
    cadet_path = cadet_bin_path / "cadet-cli"
    lwe_path = cadet_bin_path / "createLWE"

When the path is checked,

if cadet_path.exists()

the program expects a Path object and not a string.

In your case, you would simply have to set:

cadet_bin_path = Path('C:\cadet\bin')

and leave the rest as is, assuming that you extracted the package in C:\cadet.
Please also note that in Windows, paths are denoted using backslashes (\)
The actual path to cadet-cli is then taken care of by the body of the if statement.

Alternatively, you could also directly set:

cadet_path = Path("C:\cadet\bin\cadet-cli")
lwe_path = Path("C:\cadet\bin\createLWE.exe")

Hope this fixes your problem! :sweat_smile:

Btw, while I appreciate you numbering the lines, please consider also using three backticks (`) before and after your code blocks s.t. the formatting makes it easier to read and to copy your code.

thanks a lot
that’s work now