csdms / ivy

Course material on scientific software development for researchers in earth and planetary surface processes
https://csdms.colorado.edu
Other
75 stars 59 forks source link

Homework for ESPIn 2021 day 2 #46

Closed mdpiper closed 2 years ago

mdpiper commented 3 years ago

The "Writing stand-alone Python scripts" section of the Python Basics lesson was a little harder than intended today because we hadn't sufficiently covered the prerequisites for it; i.e., git, GitHub, and conda. These should now be satisfied. For homework today, please try the following:

  1. Clone the ESPIn repo to your local machine
  2. Read over the conda lesson
  3. Create the espin environment from the environment file in the repo
  4. Activate the environment; can you import numpy?
  5. Run the script from the "Writing stand-alone Python scripts" section

Feel free to add questions/comments to this issue!

taranguiz commented 3 years ago

When I want to run the script is showing me the following error with numpy:

(espin) Tamaras-Mac-mini:python taranguiz$ python script_3_homework.py 
Traceback (most recent call last):
  File "/opt/anaconda3/envs/espin/lib/python3.9/site-packages/numpy/core/__init__.py", line 22, in <module>
    from . import multiarray
  File "/opt/anaconda3/envs/espin/lib/python3.9/site-packages/numpy/core/multiarray.py", line 12, in <module>
    from . import overrides
  File "/opt/anaconda3/envs/espin/lib/python3.9/site-packages/numpy/core/overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: dlopen(/opt/anaconda3/envs/espin/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 2): Library not loaded: @rpath/libopenblas.dylib
  Referenced from: /opt/anaconda3/envs/espin/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
  Reason: image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/taranguiz/Desktop/espin/lessons/python/script_3_homework.py", line 1, in <module>
    import numpy as np
  File "/opt/anaconda3/envs/espin/lib/python3.9/site-packages/numpy/__init__.py", line 145, in <module>
    from . import core
  File "/opt/anaconda3/envs/espin/lib/python3.9/site-packages/numpy/core/__init__.py", line 48, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "/opt/anaconda3/envs/espin/bin/python"
  * The NumPy version is: "1.20.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: dlopen(/opt/anaconda3/envs/espin/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 2): Library not loaded: @rpath/libopenblas.dylib
  Referenced from: /opt/anaconda3/envs/espin/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
  Reason: image not found
eb-mars commented 3 years ago

Windows users who have Anaconda installed, here are the full list of tips to getting on with this homework, using conda, These were all posted on the ESPIn slack, but I thought it would be a handy place to cover all I came across as a windows user:

I hope that helps anyone using windows! :) As a windows user, I would be keen to hear about any general other issues and their solutions?

mdpiper commented 3 years ago

I want to follow up on the comments above. (We discussed these in class on Zoom, but I'd like to record them here for posterity.)

For @taranguiz's comment:

This is unusual! Libraries are constantly being updated, and sometimes things go wrong when building them. Sometimes things go wrong with conda, too. I bet if we try the same thing next week, everything will work. Your solution, to roll back the numpy version, was an excellent workaround.

For @eb-mars' comment:

Commenting out the pymt_sedflux package is an excellent workaround. It so happens that this package isn't built for Windows. You're also correct that conda activate [env] is what's used on Windows. The older source activate [env] is deprecated, but still works on Linux and macOS. I should update the lesson to use the former.

mdpiper commented 2 years ago

Marking this issue as resolved.

The numpy problem is transient, but it's good we talked about it and documented it here.

I marked pymt_sedflux as unix-only in the environment.yaml file. I also updated the conda lesson to use conda activate [env] and note that source may need to be substituted if you haven't done the recommended conda setup on Linux and macOS.