SorooshMani-NOAA / OCSMeshTutorial

This repository stores files and documentation used for OCSMesh tutorial Sessions
Creative Commons Zero v1.0 Universal
2 stars 1 forks source link

TypeError when importing ocsmesh #5

Closed melissamattwig closed 1 year ago

melissamattwig commented 1 year ago

In the first block of code importing the modules I got this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 21
     18 import xarray as xr
     19 from rasterio.plot import show as rioshow
---> 21 import ocsmesh
     22 import pyschism
     23 import pyschism.driver

File ~\AppData\Local\anaconda3\envs\simulation\Lib\site-packages\ocsmesh\__init__.py:10
      6 import platform
      9 try:
---> 10     import jigsawpy  # noqa: F401
     11 except OSError as e:
     12     pkg = util.find_spec("jigsawpy")

File ~\AppData\Local\anaconda3\envs\simulation\Lib\site-packages\jigsawpy\__init__.py:58
     55 from jigsawpy.def_t import jigsaw_def_t
     56 from jigsawpy.prj_t import jigsaw_prj_t
---> 58 from jigsawpy import jigsaw, libsaw
     60 from jigsawpy.loadmsh import loadmsh
     61 from jigsawpy.savemsh import savemsh

File ~\AppData\Local\anaconda3\envs\simulation\Lib\site-packages\jigsawpy\libsaw.py:65
     62 if (JLIBNAME == Path()):
     63 #---------------------------- search machine path for binary
     64     if   (platform.system() == WIN):
---> 65         JLIBNAME = Path(
     66             ctypes.util.find_library("jigsaw.dll"))
     68     elif (platform.system() == LNX):
     69         JLIBNAME = Path("libjigsaw.so")

File ~\AppData\Local\anaconda3\envs\simulation\Lib\pathlib.py:871, in Path.__new__(cls, *args, **kwargs)
    869 if cls is Path:
    870     cls = WindowsPath if os.name == 'nt' else PosixPath
--> 871 self = cls._from_parts(args)
    872 if not self._flavour.is_supported:
    873     raise NotImplementedError("cannot instantiate %r on your system"
    874                               % (cls.__name__,))

File ~\AppData\Local\anaconda3\envs\simulation\Lib\pathlib.py:509, in PurePath._from_parts(cls, args)
    504 @classmethod
    505 def _from_parts(cls, args):
    506     # We need to call _parse_args on the instance, so as to get the
    507     # right flavour.
    508     self = object.__new__(cls)
--> 509     drv, root, parts = self._parse_args(args)
    510     self._drv = drv
    511     self._root = root

File ~\AppData\Local\anaconda3\envs\simulation\Lib\pathlib.py:493, in PurePath._parse_args(cls, args)
    491     parts += a._parts
    492 else:
--> 493     a = os.fspath(a)
    494     if isinstance(a, str):
    495         # Force-cast str subclasses to str (issue #21127)
    496         parts.append(str(a))

TypeError: expected str, bytes or os.PathLike object, not NoneType

I think it may be something to do with the jigsawpy module but I'm not sure. I'm using the simulation virtual environment that was created for this tutorial, and the files are in the tmp folder that was also created. I was trying to run this in a Jupyter notebook for which the kernel I used was for the simulation virtual environment.

I'm still a bit new to working with virtual environments and the nuances of anaconda so I appreciate the help!

SorooshMani-NOAA commented 1 year ago

@melissamattwig it looks like it cannot find the jigsaw library. jigsawpy is a python wrapper that relies on jigsaw library to execute meshing commands. You need to install both either from conda repository or from the source code.

Have you successfully executed all the installation steps outlined in the readme? In specific:

python setup.py install_jigsaw

This step requires that you have cmake and gcc installed on the machine. This fetches jigsawpy and jigsaw source code, builds jigsaw library and then installs jigsawpy. It is possible that when you ran this, it failed to build jigsaw library, but just installed jigsawpy.

If for any reason the step above cannot be successfully executed in your environment, you can try installing jigsaw from conda by (also in the readme):

conda install -c conda-forge jigsaw jigsawpy
melissamattwig commented 1 year ago

I tried installing jigsaw both ways. Using the setup.py, it also threw the same TyperError message in anaconda that I get when trying to import ocsmesh in a Jupyter notebook. Is that because there is no gcc compiler? What is the best way to install gcc through conda if possible? I tried using

conda install -c conda-forge gcc

that I got from the anaconda website but I got a message that it wasn't available on that current channel. I do believe I have cmake. I'm doing this all on my NOAA laptop which I just recently got so I'm starting from scratch but not exactly sure what is included in anaconda and what I need to reinstall every time I create a new virtual environment.

The readme installs it through mamba, which I did for my first try and it didn't work. Then I used the above code that you provided and tried installing it through conda to no avail. All in all, I seem to have issues installing jigsaw just in general. It could be the issue is in the previous installation steps. Since I already had anaconda on my computer (and I'm doing this locally and not on an HPC) before starting this tutorial, I started with the step that installs mamba. Do I need to run the first two blocks of code in the readme file before installing mamba if I already have anaconda on my computer?

SorooshMani-NOAA commented 1 year ago

Thanks for the detailed description. mamba and conda shouldn't really matter in terms of the results. I just used conda in my previous comment because I didn't want to assume you have mamba.

About GCC, since I'm using WSL, I usually install it using apt. I'm not sure what the best way is for conda. I think what you do above works for linux and mac machines, but for windows you need something else. I don't know what/how.

If jigsaw is already installed using conda and it still doesn't work, the problem might just be with how Windows resolves the dll paths. It looks like you're using Anaconda installation on windows, I don't have Anaconda on windows, I'm just using miniconda on WSL on windows, so I'm not sure how to reproduce the issue on my side. Would it be possible for your to use WSL and setup your conda environment on linux?

Update I forgot to mention. Can you also try just opening a python session and executing from jigsawpy import jigsaw, libsaw to make sure we get the exact same error?

SorooshMani-NOAA commented 1 year ago

Do I need to run the first two blocks of code in the readme file before installing mamba if I already have anaconda on my computer?

No the first two blocks just install conda

I'm starting from scratch but not exactly sure what is included in anaconda and what I need to reinstall every time I create a new virtual environment.

Usually if you don't stack environments (which is done explicitly) each environment is pretty minimal and you should install pretty much all the packages you need.

SorooshMani-NOAA commented 1 year ago

Just for the sake of completeness:

We investigate this issue further and realized it seems to have something to do with how opening Jupyter using it's GUI in Windows loads the environment vs how this can be done through the command line interface. On Windows, using PowerShell activating the created env (simulation) and then running jupyter lab from that console helped resolve the issue.

Further down we realized pyschism had issue due to dependency on cf. cf-python at this point is not released for Windows on conda and should be installed via pip, which seems to have some dependecy issues when trying to import cf.

Since this latter issue is specific to Windows and is not a main blocker for the meshing section of the tutorial, I close this ticket. Later let's create a separate issue for the cf-python problem.