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

Handle statically linked case in macOS as well #212

Merged
merged 12 commits into from
Oct 28, 2018
Merged

Conversation

tkf
Copy link
Member

@tkf tkf commented Oct 25, 2018

It turned out macOS can have statically linked Python when it's installed via conda: #150 (comment)

So it seems linked_libpython (which calls libdl) is the only way to reliably detect if the Python executable is statically linked or not. Since cd2e408 implements it for Windows as well, we can simplify core.py a lot by relying on linked_libpython.

closes #150

It turned out macOS can have statically linked Python when it's
installed via conda:
JuliaPy#150 (comment)

So it seems `linked_libpython` (which calls `libdl`) is the only way
to reliably detect if the Python executable is statically linked or
not.  Since cd2e408 implements it for
Windows as well, we can now rely on `linked_libpython` everywhere
which simplifies core.py.
@tkf tkf added this to the 0.2 milestone Oct 25, 2018
@coveralls
Copy link

Pull Request Test Coverage Report for Build 511

  • 1 of 2 (50.0%) changed or added relevant lines in 1 file are covered.
  • 15 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.1%) to 74.783%

Changes Missing Coverage Covered Lines Changed/Added Lines %
julia/core.py 1 2 50.0%
Files with Coverage Reduction New Missed Lines %
julia/pseudo_python_cli.py 2 72.68%
julia/find_libpython.py 4 73.42%
julia/core.py 9 81.23%
Totals Coverage Status
Change from base Build 509: 0.1%
Covered Lines: 602
Relevant Lines: 805

💛 - Coveralls

@coveralls
Copy link

coveralls commented Oct 25, 2018

Pull Request Test Coverage Report for Build 516

  • 3 of 4 (75.0%) changed or added relevant lines in 1 file are covered.
  • 7 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.3%) to 74.938%

Changes Missing Coverage Covered Lines Changed/Added Lines %
julia/core.py 3 4 75.0%
Files with Coverage Reduction New Missed Lines %
julia/find_libpython.py 2 73.42%
julia/core.py 5 81.64%
Totals Coverage Status
Change from base Build 509: 0.3%
Covered Lines: 601
Relevant Lines: 802

💛 - Coveralls

@bstellato
Copy link

bstellato commented Oct 25, 2018

I have just tried this PR branch but I am getting exactly the same error. It does not change if I delete the .ji file. Maybe adding conda in the CI would help understanding why it happens.

EDIT: I was doing something stupid! It works now 👍 Thanks a lot!

@tkf
Copy link
Member Author

tkf commented Oct 25, 2018

@bstellato Thanks for trying it out!

With this PR, I expect that:

  • python -c "import julia.Main" fails with an informative error message mentioning python-jl.
  • python-jl -c "import julia.Main" should work fine

where python is installed with conda in macOS.

Do you see this behavior?

@bstellato
Copy link

This is so weird... it now works for me in both cases! I am using conda, python 3.6 and mac os.
I updated some packages but now linked_libpython() returns

/Users/xxx/miniconda3/envs/python36/lib/libpython3.6m.dylib

I have seen that within my package updates I ended up installing python from conda-forge. If I run conda list | grep python I get

...
python                    3.6.6                h5001a0f_0    conda-forge

Could this be the reason? This solves the problem #185 as well on the linux cluster I am working with.

@tkf
Copy link
Member Author

tkf commented Oct 26, 2018

@bstellato It would be nice if you can confirm that python from defaults channel throws a proper exception:

conda create --prefix testpyjulia defaults::python
testpyjulia/bin/pip install 'https://github.com/tkf/pyjulia/archive/macos-conda.zip#egg=julia'
testpyjulia/bin/python -c "import julia.Main"

(or maybe with the old python interpreter you were previously using) which should show something like:

It seems your Julia and PyJulia setup are not supported.

Julia interpreter:
    {runtime}
Python interpreter and libpython used by PyCall.jl:
    {jlinfo.pyprogramname}
    {jl_libpython}
Python interpreter used to import PyJulia and its libpython.
    {sys.executable}
    {py_libpython}

Your Python interpreter "{sys.executable}"
is statically linked to libpython.  Currently, PyJulia does not support
such Python interpreter.  One easy workaround is to run your Python
script with `python-jl` command bundled in PyJulia.  You can simply do:

    python-jl PATH/TO/YOUR/SCRIPT.py

See `python-jl --help` for more information.

For other available workarounds, see:
    https://github.com/JuliaPy/pyjulia/issues/185

Yes, we should be CIing with conda but conda can't be used with tox (until https://github.com/tox-dev/tox-conda is ready) so it's not straightforward to set it up...

@bstellato
Copy link

I ran the following commands:

conda create -n testpyjulia defaults::python
conda activate testpyjulia
pip install 'https://github.com/tkf/pyjulia/archive/macos-conda.zip#egg=julia'
python -c "import julia.Main"

I get this error though:

(testpyjulia) ➜  ~ python -c "import julia.Main"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "/Users/xxx/miniconda3/envs/testpyjulia/lib/python3.7/site-packages/julia/core.py", line 179, in load_module
    JuliaMainModule(self, fullname))
  File "/Users/xxx/miniconda3/envs/testpyjulia/lib/python3.7/site-packages/julia/core.py", line 84, in __init__
    self._julia = loader.julia
  File "/Users/xxx/miniconda3/envs/testpyjulia/lib/python3.7/site-packages/julia/core.py", line 171, in julia
    self.__class__.julia = julia = Julia()
  File "/Users/xxx/miniconda3/envs/testpyjulia/lib/python3.7/site-packages/julia/core.py", line 640, in __init__
    self._call(u"using PyCall")
  File "/Users/xxx/miniconda3/envs/testpyjulia/lib/python3.7/site-packages/julia/core.py", line 696, in _call
    self.check_exception(src)
  File "/Users/xxx/miniconda3/envs/testpyjulia/lib/python3.7/site-packages/julia/core.py", line 746, in check_exception
    .format(exception, src))
julia.core.JuliaError: Exception 'InitError' occurred while calling julia code:
using PyCall

@tkf
Copy link
Member Author

tkf commented Oct 26, 2018

Thanks a lot!

But this is not the expected exception... Could you try python -c 'from julia import Julia; Julia(debug=True)'?

Since `if determine_if_statically_linked()` block was removed, we need
additional check for statically linked executable.  Furthermore, using
`find_libpython()` here was not appropriate since `py_libpython`
should be the libpython _used_ by the current executable.
@tkf
Copy link
Member Author

tkf commented Oct 26, 2018

Actually, it turned out my earlier commit 77577f8 introduced a bug. 2e12d24 should fix it.

tkf added 3 commits October 26, 2018 00:09
Since `normalize_path(None)` is `None`, we don't need the explicit
block `if jlinfo.libpython is None`.
@tkf tkf force-pushed the macos-conda branch 5 times, most recently from 698e05b to 3c2eee8 Compare October 27, 2018 05:27
tkf added 5 commits October 27, 2018 21:30
No-capturing mode -s is useful for remote debugging especially in case
libjulia initialization fails.  But it makes reading output almost
impossible.  Let's use -v instead since it provides what test is being
executed in a more readable format.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SystemError: initialization of _heapq did not return an extension module
3 participants