Skip to content

installing pythonnet on Mac Sierra  #465

Closed

Description

@riccardodelutio

I'm trying to use pythonnet in order to import a DLL assembly and use it in python. I've seen in some other threads that some people got it working. But when I try to use it I get

>>> import clr Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: dlopen(/Users/riccardodelutio/anaconda2/lib/python2.7/site-packages/clr.so, 2): Library not loaded: /usr/local/opt/glib/lib/libglib-2.0.0.dylib Referenced from: /Users/riccardodelutio/anaconda2/lib/python2.7/site-packages/clr.so Reason: image not found

I've seen the thread #120 proposed a patch but I'm not sure if that will fix my problem.

Thank you!

Activity

  1. den-run-ai commented on May 14, 2017

    @den-run-ai
    Contributor

    This looks different issue. Can you describe all steps that you did to get pythonnet installed?

  2. den-run-ai commented on May 14, 2017

    @den-run-ai
    Contributor

    @spichardo @mateuszlewko @fractus did you have this issue on mac?

  3. mateuszlewko commented on May 14, 2017

    @mateuszlewko

    Yes and I haven't tried it on different OS.

  4. spichardo commented on May 14, 2017

    @spichardo

    I haven't seen this issue. As side note I switched to Enthought Canopy instead of Anaconda (for different reasons), pythonnet 2.3.0 works out of the box with pip install pythonnet. I used brew to install mono.

    I've been using a lot pythonnet recently on Mac OS (Sierra) in my applications, so I know it works.

    @riccardodelutio It looks the error more related to the mono installation. How was it installed?

  5. fractus commented on May 14, 2017

    @fractus
    Contributor

    No, I didn't have that issue. Looking at the above though, I would proceed as follows:

    • Check that which python points to your Anaconda installation; if not, update your user path in .bash_profile, restart the terminal, and try again

    • If clr.so exists, add the following link (point to your mono installation) and try again.

    vasilios@exumas: /usr/local/anaconda/lib
    └─ $ ll | grep mono
    lrwxr-xr-x    1 vasilios  staff    60B 14 May 20:49 mono -> /Library/Frameworks/Mono.framework/Versions/Current/lib/mono
    
    • If still you get an error message, then I would guess, as @spichardo mentioned, a mono issue. You can try the following:
      • pip uninstall pythonnet
      • delete the all .egg files in site-packages
      • reinstall mono from official source
      • add the link as described above
      • pip install pythonnet (uses 2.3.0)

    Ideally, you can skip the first two by creating a new conda environment.

  6. changed the title [-]installing pyhtonnet on Mac Sierra [/-] [+]installing pythonnet on Mac Sierra [/+] on May 15, 2017
  7. riccardodelutio commented on May 15, 2017

    @riccardodelutio
    Author

    Hello thanks for the answers!

    @denfromufa @spichardo
    I used brew install mono because I saw this was recommended but before that I had tried by following what's described in this http://www.mono-project.com/download/
    and pip install pythonnet for pythonnet

    @fractus

    which python outputs /Users/riccardodelutio/anaconda2/bin/python so it should be ok
    clr.so does exist, could you just detail how I should

    If clr.so exists, add the following link (point to your mono installation) and try again.

    Thanks a lot

  8. fractus commented on May 15, 2017

    @fractus
    Contributor

    This is a symbolic links, so use the ln command as follows:

    vasilios@exumas: /usr/local/anaconda/lib
    └─ $ ln -s /Library/Frameworks/Mono.framework/Versions/Current/lib/mono
    
  9. mcgradymvp commented on May 27, 2017

    @mcgradymvp

    I was using pip install pythonnet and getting the error message of Failed building wheel for pythonnet.
    I recorded the error by asciinema:
    asciinema error message

  10. den-run-ai commented on May 27, 2017

    @den-run-ai
    Contributor

    @mcgradymvp can you try to install from master since you are using Mono 5.0, which just got fixed:

    pip install git+https://github.com/pythonnet/pythonnet

  11. mcgradymvp commented on May 27, 2017

    @mcgradymvp

    @denfromufa
    Thanks a lot. Now I can install pythonnet but got error when import clr

    >>> import clr
    The assembly mscorlib.dll was not found or could not be loaded.
    It should have been installed in the `/Users/wangfan/anaconda2/lib/mono/4.5/mscorlib.dll' directory.
    
  12. den-run-ai commented on May 27, 2017

    @den-run-ai
    Contributor

    @mcgradymvp please follow instructions from @fractus on how to symbolically link mscorlib.dll:

    #392

  13. den-run-ai commented on Jun 7, 2017

    @den-run-ai
    Contributor

    ok, so I managed to compile and use OSX + Mono 5.0 + pythonnet (master) on Mac Sierra.

    Some additional instructions:

    brew install pkg-config
    brew install glib --universal

    This should be on the same line:
    USE_OSX_FRAMEWORKS=0 ARCHFLAGS="-arch x86_64" pip install git+https:\\github.com\pythonnet\pythonnet

  14. 1 remaining item

  15. fractus commented on Aug 10, 2017

    @fractus
    Contributor

    Looks good to me; two minor comments:

    • Mono is installed in /Library/Frameworks with the official installer. I would expect to brew to use /usr/local/Cellar, but I'm not using it.
    • Formatting improvement; you could use triple ticks for the symbolic link to avoid confusion.
  16. lodb commented on Aug 25, 2017

    @lodb

    When trying to follow these instructions (brew mono, add symbolic link, yada yada...), USE_OSX_FRAMEWORKS=0 ARCHFLAGS="-arch x86_64" pip install git+https://github.com/pythonnet/pythonnet executes without errors.

    However, the problem is I'm running it in a virtualenv (using pyenv) with Python 3.4.3. When running import clr, I get the following error:
    Traceback (most recent call last): File "test.py", line 2, in <module> import clr ImportError: System.DllNotFoundException: python27 at (wrapper managed-to-native) Python.Runtime.Runtime:Py_IsInitialized () at Python.Runtime.Runtime.Initialize () [0x0000d] in <e96910e86ed845cb8f66189b0607b8cf>:0 at Python.Runtime.PythonEngine.Initialize () [0x00011] in <e96910e86ed845cb8f66189b0607b8cf>:0 at Python.Runtime.PythonEngine.InitExt () [0x00000] in <e96910e86ed845cb8f66189b0607b8cf>:0

    It looks like installing from master via pip in a virtual environment still refers to python2.7 somewhere. Is it correct to assume pythonnet doesn't support python3 on OSX?

  17. den-run-ai commented on Aug 25, 2017

    @den-run-ai
    Contributor

    @lodb no i think you missed something with your pythonnet installation in pyenv, which is not supported/tested by pythonnet. So I cannot tell you what is wrong with your installation due to this untested scenario with pyenv. I suggest to install on python 3.4 without using pyenv. I used pyenv once and was quite unhappy with it, but I may have missed some steps in using it.

  18. fractus commented on Aug 25, 2017

    @fractus
    Contributor

    @lodb
    I would suggest to use conda environments. I have successfully installed pythonnet in 2.7, 3.5 and 3.6 using the instructions. Just remember to activate them before.

  19. vkhombal commented on Oct 17, 2017

    @vkhombal

    I had a version of Pythonnet+Mono setup that was working until a recent update of Mono. Now I get:

    ImportError: dlopen(/Users/vh/anaconda/lib/python3.5/site-packages/clr.cpython-35m-darwin.so, 2): Library not loaded: /Library/Frameworks/Mono.framework/Versions/5.2.0/lib/libmonosgen-2.0.1.dylib
      Referenced from: /Users/vh/anaconda/lib/python3.5/site-packages/clr.cpython-35m-darwin.so
      Reason: image not found
    

    My /Library/Frameworks/Mono.framework/Versions/ looks like this

    MAC:lib vh$ ls /Library/Frameworks/Mono.framework/Versions/
    5.4.0	Current
    

    Can you please advice on how to fix this?

  20. den-run-ai commented on Oct 17, 2017

    @den-run-ai
    Contributor

    @vkhombal clearly pythonnet is trying to load mono version 5.2.0, but you have upgraded to 5.4.0. So you may need to update your symbolic links if that helps.

  21. vkhombal commented on Oct 17, 2017

    @vkhombal

    @denfromufa

    hi updated the softlink, but it still is looking for the 5.2.0

    MAC:lib vh$ pwd
    /Users/vh/anaconda/lib
    MAC:lib vh$ ls -l mono
    lrwxr-xr-x  1 vh  staff  58 Oct 17 10:03 mono -> /Library/Frameworks/Mono.framework/Versions/5.4.0/lib/mono
    
    ImportError: dlopen(/Users/vh/anaconda/lib/python3.5/site-packages/clr.cpython-35m-darwin.so, 2): Library not loaded: /Library/Frameworks/Mono.framework/Versions/5.2.0/lib/libmonosgen-2.0.1.dylib
      Referenced from: /Users/vh/anaconda/lib/python3.5/site-packages/clr.cpython-35m-darwin.so
      Reason: image not found
    
  22. den-run-ai commented on Oct 17, 2017

    @den-run-ai
    Contributor

    @vkhombal let's continue discussion in gitter chat: https://gitter.im/pythonnet/pythonnet

  23. den-run-ai commented on Oct 24, 2017

    @den-run-ai
    Contributor

    updated instructions from @vkhombal:

    #555 (comment)

  24. nsbruce commented on Nov 6, 2017

    @nsbruce

    @denfromufa a quick comment on the troubleshooting link (thanks for putting it together!) at https://github.com/pythonnet/pythonnet/wiki/Troubleshooting-on-Windows,-Linux,-and-OSX#osx-notes

    In the last bullet point, USE_OSX_FRAMEWORKS=0 ARCHFLAGS="-arch x86_64" pip install git+https:\github.com\pythonnet\pythonnet the slashes are backwards and one is missing. I think it should read as:

    USE_OSX_FRAMEWORKS=0 ARCHFLAGS="-arch x86_64" pip install git+https://github.com/pythonnet/pythonnet

  25. den-run-ai commented on Nov 7, 2017

    @den-run-ai
    Contributor

    @nsbruce good catch and feel free to edit this wiki.

  26. ztl8702 commented on Nov 9, 2018

    @ztl8702

    @denfromufa

    What is the reason for prefixing pip install... with USE_OSX_FRAMEWORKS=0 ARCHFLAGS="-arch x86_64"?

    If I build from source (git clone and then python3 setup.py bdist_wheel --xplat), why do I not have to set USE_OSX_FRAMEWORKS=0 ARCHFLAGS="-arch x86_64"?

  27. den-run-ai commented on Nov 9, 2018

    @den-run-ai
    Contributor

    @ztl8702 my memory has been flushed in one year and I cannot find the original reason for this. Google search cannot help either. Try without and let us know the error!

  28. filmor commented on Jun 9, 2020

    @filmor
    Member

    Since there have not been any updates in quite a while, I'll close this issue. Feel free to reopen and provide a information on the current state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions