Repository: cocotb/cocotb

Issue:
Cannot run on Big Sur
<!--
In case you are reporting a problem with running cocotb,
please remember to add relevant information about your environment, such as
* the cocotb version used,
* the operating system and version (32/64 bit),
* the simulator and version (32/64 bit),
* the Python version, and where it's coming from (e.g. system, Anaconda, self-installed, ...),
* (part of) the log file (cleaned of proprietary information).
If you are unsure about any of the above items, open the issue anyway and we will figure it out together.
Thanks for helping improve cocotb!
-->
Cocotb cannot find libpytyon3.8.so  

I do not see it in the libs:

```
(base) raysalemi@WriteNow lib % ls libpython*
libpython3.8.a		libpython3.8.dylib	libpython3.8.nolto.a
```

Am I doing something wrong?  

* Latest version of Cocotb (just downloaded)
* MacOS 11.0.1
* icarus-verilog 11.0
* anaconda python 3.8.3
* log file:
```
MODULE=tinyalu_cocotb TESTCASE= TOPLEVEL=tinyalu TOPLEVEL_LANG=verilog \
        /usr/local/bin/vvp -M /Users/raysalemi/opt/anaconda3/lib/python3.8/site-packages/cocotb/libs -m libcocotbvpi_icarus   sim_build/sim.vvp
     -.--ns ERROR    cocotb.gpi                         ..s/cocotb_utils.cpp:69   in utils_dyn_open                  Unable to open lib libpython3.8.so: dlopen(libpython3.8.so, 9): image not found

     -.--ns ERROR    cocotb.gpi                         ..mbed/gpi_embed.cpp:127  in embed_init_python               Failed to find Python shared library

     -.--ns INFO     cocotb.gpi                         ..mbed/gpi_embed.cpp:74   in set_program_name_in_venv        Did not detect Python virtual environment. Using system-wide Python interpreter
     -.--ns INFO     cocotb.gpi                         ../gpi/GpiCommon.cpp:105  in gpi_print_registered_impl       VPI registered
```




Discussion:
That is expected on Mac OS (#2084), but we should probably clean that up to prevent the message from printing. `libpython` is a library packaged with a Python installation, we don't package it ourselves. Are your simulations running fine?
Hi Kaleb,

No. The sim isn't running, but I'm new to this and probably made some other
error.  You're saying this should not keep it from working?
Ray


On Tue, Dec 1, 2020 at 9:29 AM Kaleb Barrett <notifications@github.com>
wrote:

> That is expected on Mac OS (#2084
> <https://github.com/cocotb/cocotb/issues/2084>), but we should probably
> clean that up to prevent the message from printing. libpython is a
> library packaged with a Python installation, we don't package it ourselves.
> Are your simulations running fine?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/cocotb/cocotb/issues/2246#issuecomment-736586941>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAYFXWV35HZMMSKOQRM64XTSST4U3ANCNFSM4UJDA6EQ>
> .
>

@raysalemi That is correct, if something isn't working there is probably another issue occurring later. Is what you posted all that is printed?
No. It hangs.

On Tue, Dec 1, 2020 at 11:13 AM Ray Salemi <ray@bostonlightpress.com> wrote:

> Hi Kaleb,
>
> No. The sim isn't running, but I'm new to this and probably made some
> other error.  You're saying this should not keep it from working?
> Ray
>
>
> On Tue, Dec 1, 2020 at 9:29 AM Kaleb Barrett <notifications@github.com>
> wrote:
>
>> That is expected on Mac OS (#2084
>> <https://github.com/cocotb/cocotb/issues/2084>), but we should probably
>> clean that up to prevent the message from printing. libpython is a
>> library packaged with a Python installation, we don't package it ourselves.
>> Are your simulations running fine?
>>
>> —
>> You are receiving this because you authored the thread.
>> Reply to this email directly, view it on GitHub
>> <https://github.com/cocotb/cocotb/issues/2246#issuecomment-736586941>,
>> or unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/AAYFXWV35HZMMSKOQRM64XTSST4U3ANCNFSM4UJDA6EQ>
>> .
>>
>

@raysalemi 
Can try to run a simple example like https://github.com/cocotb/cocotb/tree/master/examples/simple_dff and provide a full log file.


So it seems to work under CI: https://github.com/cocotb/cocotb/pull/2249/checks?check_run_id=1481370246

(The overall status if fail but this is other/setup issues).

Resolving patch:
diff --git a/cocotb_build_libs.py b/cocotb_build_libs.py
--- a/cocotb_build_libs.py
+++ b/cocotb_build_libs.py
@@ -281,6 +281,12 @@ def _get_python_lib():
 
     if os.name == "nt":
         python_lib = _get_python_lib_link() + "." + _get_lib_ext_name()
+    elif sys.platform == "darwin":
+        python_lib = os.path.join(sysconfig.get_config_var("LIBDIR"), "lib" + _get_python_lib_link() + ".")
+        if os.path.exists(python_lib + "dylib"):
+            python_lib += "dylib"
+        else:
+            python_lib += "so"
     else:
         python_lib = "lib" + _get_python_lib_link() + "." + _get_lib_ext_name()
 


Test patch: