System linkers ignore any changes to the LD_LIBRARY_PATH variable after the
program starts running. I agree, it's definitely frustrating and confusing
behavior to adopt.

As a bit of a workaround, you can push the path onto `Base.DL_LOAD_PATH`
and then call `dlopen("libjpeg")` manually

On Sat, Apr 18, 2015 at 10:28 PM Peter Simon <[email protected]> wrote:

> I'm running on CentOS with Julia 0.3.7.  I'm writing an executable Julia
> script for other non-Julia, non-Python users to run as a batch job.  The
> script generates plots using the following setup:
>
> using PyCall
> pyimport("matplotlib")[:use]("Agg")  # Doesn't require X connection
> @pyimport matplotlib.pyplot as plt
>
>
> Prior to this it first checks that Anaconda Python is set up in the user's
> path.  If not, it sets the appropriate values of environment variables as
> follows
>
>     pypath = ""
>     stderrold = STDERR; (rd,wr) = redirect_stderr()
>     try
>         pypath = readall(`which python`)
>     end
>     redirect_stderr(stderrold)
>     if isempty(search(pypath, "anaconda"))
>         println("Adding Anaconda Python to environment variables")
>         PREFIX = "/projects/antenna_eng/tools/python/CentOS/anaconda"
>         ENV["PATH"] = "$(PREFIX)/bin:$(ENV["PATH"])"
>         ENV["LD_LIBRARY_PATH"] =
> """$(PREFIX)/lib:$(ENV["LD_LIBRARY_PATH"])"""
>         pyversion=readchomp(`python -c "import sys; print
> sys.version.split()[0]"`)
>         ENV["PYTHONSRC"] = "$(PREFIX)/src/Python-$(pyversion)"
>     end
>
> These valiues for the environment variables are taken from the file
> python_envars.sh that is installed with Anaconda Python.
>
> The pyimport and @pyimport commands work fine.  However, when the Julia
> script gets to the part where it actually generates plots, Python complains
> that it can't find a file:
>
> ERROR: PyError (:PyImport_ImportModule) <type 'exceptions.ImportError'>
> ImportError('libjpeg.so.8: cannot open shared object file: No such file or
> directory',)
>
> This shared library is actually sitting in the directory in the Anaconda
> installation that was added to the LD_LIBRARY_PATH environment variable.
>
> If I set up the environment variables before launching the Julia script,
> all is well.
>
> Is this expected behavior?  I thought that if I altered the environment
> variables, they would be passed along to any programs launched by the Julia
> script, including Python via the PyCall package.  I guess I could write a
> shell script that sets up the environment variables and then calls my Julia
> script, but I would prefer to do this all with a single Julia script, if
> possible.  Any suggestions?
>
> Thanks,
> --Peter
>
>

Reply via email to