Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get started on OSX #37

Closed
sglyon opened this issue Aug 13, 2013 · 8 comments
Closed

Cannot get started on OSX #37

sglyon opened this issue Aug 13, 2013 · 8 comments
Labels

Comments

@sglyon
Copy link
Contributor

sglyon commented Aug 13, 2013

I am a Python developer and have multiple working versions of Python on my machine.

I cannot, however, get PyCall to work after simply following the instructions from the readme and doing Pkg.add("PyCall"). This is what a sample session looks like:

julia> using PyCall

julia> @pyimport scipy.optimize as so
ERROR: could not load module /libpython2.7.dylib: dlopen(/libpython2.7.dylib.dylib, 9): image not found
 in pyinitialize at /Users/sglyon/.julia/PyCall/src/PyCall.jl:339
 in pyimport at /Users/sglyon/.julia/PyCall/src/PyCall.jl:105

The error message is fairly clear at explaining what is happening, but I have no idea why PyCall is looking for python at / or how I tell it where my Python is. I would like to use the python at ~/anaconda/bin/python. I tried to be more explicit and set $PYTHONHOME to various values near that directory. I have tried all of the below values:

  • export PYTHONHOME="/Users/sglyon/anaconda/lib/python2.7"
  • export PYTHONHOME="/Users/sglyon/anaconda/bin"
  • export PYTHONHOME="/Users/sglyon/anaconda/lib/"
  • export PYTHONHOME="/Users/sglyon/anaconda/"

For each of those values I get the following printout (it is the same for any of the listed values):

julia> using PyCall

julia> @pyimport scipy.optimize as so
ImportError: No module named site
ERROR: failed process: Process(`python -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('LDLIBRARY'))"`, ProcessExited(1)) [1]
 in error at error.jl:22
 in pipeline_error at process.jl:436
 in readall at process.jl:394
 in libpython_name at /Users/sglyon/.julia/PyCall/src/PyCall.jl:328
 in pyinitialize at /Users/sglyon/.julia/PyCall/src/PyCall.jl:339
 in pyimport at /Users/sglyon/.julia/PyCall/src/PyCall.jl:105

What other configuration do I need to do to get this to work with the python of my choosing? (Note that the anaconda python is the first on my$PATH and is executing when typing python from the command line.)

@stevengj
Copy link
Member

As a workaround, you can run

using PyCall
pyinitialize("/....path..../libpython2.7.dylib")

to specify the Python shared library to link to.

Currently, PyCall runs the python executable and executes:

import distutils.sysconfig
print(distutils.sysconfig.get_config_var('LDLIBRARY'))
print(distutils.sysconfig.get_config_var('PYTHONFRAMEWORKPREFIX'))

to find out the name and location of the Python library. What does this print for you?

Alternatively, I'm thinking of using python-config instead. What does python-config --ldflags print for you?

@AlexMikhalev
Copy link

Same problem, but I am using anaconda,

workaround

using PyCall
pyinitialize("/opt/anaconda/lib/libpython2.7.dylib")

worked, but

In [1]: import distutils.sysconfig

In [2]: print(distutils.sysconfig.get_config_var('LDLIBRARY'))
libpython2.7.dylib

In [3]: print(distutils.sysconfig.get_config_var('PYTHONFRAMEWORKPREFIX'))

In [4]: 

@sglyon
Copy link
Contributor Author

sglyon commented Aug 13, 2013

@stevengj, thanks for the quick response. The pyinitialize(path) also worked for me!

FYI, when I run the commands listed (the ones PyCall executes) I get the exact same thing as @AlexMikhalev:

In [1]: import distutils.sysconfig

In [2]: print(distutils.sysconfig.get_config_var('LDLIBRARY'))
libpython2.7.dylib

In [3]: print(distutils.sysconfig.get_config_var('PYTHONFRAMEWORKPREFIX'))


In [4]: 

Executing python-config --ldflags gives the following (I get the feeling that this isn't what you want):

➜  ~  python-config --ldflags 
-ldl -framework CoreFoundation -lpython2.7 -u _PyMac_Error

@stevengj
Copy link
Member

Hmm, those --ldflags seem broken if that is what ~/anaconda/bin/python-config is printing, since that doesn't specify the location of the python2.7 library.

I need a way to query the location of libpython from either python or python-config...

@sglyon
Copy link
Contributor Author

sglyon commented Aug 14, 2013

Hmm. I'll think about it and let you know if I can come up with anything.

@lindahua
Copy link

I believe this works (at least for Mac OS X):

# get the path of (default) python executable
exepath = readchomp(`python -c "import sys; print sys.executable"`)   

 # construct the path of libpython
libpath = joinpath(dirname(dirname(exepath)), "lib", "libpython2.7.dylib")  

@stevengj
Copy link
Member

@lindahua, that works, and I can also use pyconfigvar(python, "LIBDIR") as well. However, I tried this with Anaconda and I got another error:

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site

With other Python installations I never had to set PYTHONHOME manually, so I'm not sure what is going on here.

@stevengj
Copy link
Member

Hmm, looks like I need to send the full path of the Python executable (via sys.executable) to Py_SetProgramName.

dhoegh pushed a commit to dhoegh/PyCall.jl that referenced this issue Sep 21, 2015
Add triple-quote LaTeXString string literals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants