You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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?
@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
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
@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.
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?
@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.
@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.
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
@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.
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
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:
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"?
@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!
Activity
den-run-ai commentedon May 14, 2017
This looks different issue. Can you describe all steps that you did to get pythonnet installed?
den-run-ai commentedon May 14, 2017
@spichardo @mateuszlewko @fractus did you have this issue on mac?
mateuszlewko commentedon May 14, 2017
Yes and I haven't tried it on different OS.
spichardo commentedon May 14, 2017
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?
fractus commentedon May 14, 2017
No, I didn't have that issue. Looking at the above though, I would proceed as follows:
Check that
which pythonpoints to your Anaconda installation; if not, update your user path in.bash_profile, restart the terminal, and try againIf
clr.soexists, add the following link (point to your mono installation) and try again.pip uninstall pythonnet.eggfiles insite-packagespip install pythonnet(uses 2.3.0)Ideally, you can skip the first two by creating a new conda environment.
[-]installing pyhtonnet on Mac Sierra [/-][+]installing pythonnet on Mac Sierra [/+]riccardodelutio commentedon May 15, 2017
Hello thanks for the answers!
@denfromufa @spichardo
I used
brew install monobecause 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 pythonnetfor pythonnet@fractus
which pythonoutputs/Users/riccardodelutio/anaconda2/bin/pythonso it should be okclr.sodoes exist, could you just detail how I shouldThanks a lot
fractus commentedon May 15, 2017
This is a symbolic links, so use the
lncommand as follows:mcgradymvp commentedon May 27, 2017
I was using
pip install pythonnetand getting the error message ofFailed building wheel for pythonnet.I recorded the error by asciinema:
asciinema error message
den-run-ai commentedon May 27, 2017
@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/pythonnetmcgradymvp commentedon May 27, 2017
@denfromufa
Thanks a lot. Now I can install pythonnet but got error when
import clrden-run-ai commentedon May 27, 2017
@mcgradymvp please follow instructions from @fractus on how to symbolically link mscorlib.dll:
#392
den-run-ai commentedon Jun 7, 2017
ok, so I managed to compile and use OSX + Mono 5.0 + pythonnet (master) on Mac Sierra.
Some additional instructions:
brew install pkg-configbrew install glib --universalThis should be on the same line:
USE_OSX_FRAMEWORKS=0 ARCHFLAGS="-arch x86_64" pip install git+https:\\github.com\pythonnet\pythonnet1 remaining item
fractus commentedon Aug 10, 2017
Looks good to me; two minor comments:
/Library/Frameworkswith the official installer. I would expect to brew to use/usr/local/Cellar, but I'm not using it.lodb commentedon Aug 25, 2017
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/pythonnetexecutes 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>:0It 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?
den-run-ai commentedon Aug 25, 2017
@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.
fractus commentedon Aug 25, 2017
@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.
vkhombal commentedon Oct 17, 2017
I had a version of Pythonnet+Mono setup that was working until a recent update of Mono. Now I get:
My /Library/Frameworks/Mono.framework/Versions/ looks like this
Can you please advice on how to fix this?
den-run-ai commentedon Oct 17, 2017
@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.
vkhombal commentedon Oct 17, 2017
@denfromufa
hi updated the softlink, but it still is looking for the 5.2.0
den-run-ai commentedon Oct 17, 2017
@vkhombal let's continue discussion in gitter chat: https://gitter.im/pythonnet/pythonnet
den-run-ai commentedon Oct 24, 2017
updated instructions from @vkhombal:
#555 (comment)
nsbruce commentedon Nov 6, 2017
@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\pythonnetthe 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/pythonnetden-run-ai commentedon Nov 7, 2017
@nsbruce good catch and feel free to edit this wiki.
ztl8702 commentedon Nov 9, 2018
@denfromufa
What is the reason for prefixing
pip install...withUSE_OSX_FRAMEWORKS=0 ARCHFLAGS="-arch x86_64"?If I build from source (
git cloneand thenpython3 setup.py bdist_wheel --xplat), why do I not have to setUSE_OSX_FRAMEWORKS=0 ARCHFLAGS="-arch x86_64"?den-run-ai commentedon Nov 9, 2018
@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!
filmor commentedon Jun 9, 2020
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.