check if python symbols are present in the current process#279
check if python symbols are present in the current process#279kevinushey merged 3 commits intorstudio:masterfrom
Conversation
src/libpython.cpp
Outdated
| loadSymbol(pLib, "Py_IsInitialized", (void**) &Py_IsInitialized, pError); | ||
| ::dlclose(pLib); | ||
|
|
||
| if (Py_IsInitialized != NULL) { |
There was a problem hiding this comment.
Is there a way to do this for Windows as well?
There was a problem hiding this comment.
we might use this from PyCall of Julia. I don't have a proper windows machine to test it though.
This PR is needed for me to use the latest conda python (an older version of conda python doesn't load symbols into the main process). I am not sure if python symbols will be loaded into the main process in Windows as well.
|
This looks good to me at first reading. I am going to wait to merge it until after the next CRAN release (which we are just now locking down for) |
|
I have updated the code. Now it checks the python symbols in Please notice that the path to
|
bac40c6 to
e3aab6e
Compare
|
@randy3k Thanks for all of this work. I am going to wait to merge until after the next CRAN release. |
22f3aa8 to
7df451b
Compare
|
bump |
|
I can see that a new release was made. Maybe it's the time to review this PR? |
|
Yes, apologize for not reviewing as part of v1.10 but there is a lot of code to review and it touches some sensitive parts of initialization so there is definitely a risk of breakage. I will try to review for the v1.11 release (which should be in another ~ 30 days). |
|
(Bumping as it's still an issue that is tripping people up.) |
2f0def2 to
a034083
Compare
when the libpython is the same as the executable (i.e. PIE),
the only way to find the correct symbols is `dlopen(NULL,..)`
Consider
```py
>>> import ctypes
>>> libpython = ctypes.PyDLL("/root/miniconda/lib/libpython3.6m.so")
>>> libpython.Py_IsInitialized()
0
>>> libpython = ctypes.PyDLL("/root/miniconda/bin/python")
>>> libpython.Py_IsInitialized()
0
>>> libpython = ctypes.CDLL(None)
>>> libpython.Py_IsInitialized()
1
>>>
```
# Conflicts:
# R/package.R
|
This is no longer needed for radian as we are patching reticulate directly randy3k/radian@88e0943. |
When R is embedded in a Python environment, it is possible that the python symbols get loaded into the main process. This PR first checks if the current process contains the python symbols. If found, it uses the python symbols found instead of the given
libPath.It would be more robust to check if the library found in the main process is consistent with
libPath, and throw an error if they do not match. But it will require some work and I currently don't have an elegant way to implement the check.related to #98