JuliaPy / PyCall.jl

Package to call Python functions from the Julia language
MIT License
1.47k stars 187 forks source link

PyCall insists upon using system python #886

Open rkurchin opened 3 years ago

rkurchin commented 3 years ago

Julia version: 1.5.2 PyCall version: 1.92.2 Conda version: 1.5.1

Setup

 ENV["PYTHON"]=""
]add Conda
Conda.add("numpy")
]add PyCall
]build PyCall

Check some variables:

julia> PyCall.conda
true
julia> PyCall.current_python()
"/home/rkurchin/.julia/conda/3/bin/python"

Now here's the problem:

np = pyimport("numpy") # same error results from np = pyimport_conda("numpy","numpy")

And here's the output...

ERROR: PyError (PyImport_ImportModule

The Python package numpy could not be imported by pyimport. Usually this means
that you did not install numpy in the Python version being used by PyCall.

PyCall is currently configured to use the Julia-specific Python distribution
installed by the Conda.jl package.  To install the numpy module, you can
use `pyimport_conda("numpy", PKG)`, where PKG is the Anaconda
package the contains the module numpy, or alternatively you can use the
Conda package directly (via `using Conda` followed by `Conda.add` etcetera).

Alternatively, if you want to use a different Python distribution on your
system, such as a system-wide Python (as opposed to the Julia-specific Python),
you can re-configure PyCall with that Python.   As explained in the PyCall
documentation, set ENV["PYTHON"] to the path/name of the python executable
you want to use, run Pkg.build("PyCall"), and re-launch Julia.

) <class 'ImportError'>
ImportError('dynamic module does not define module export function (PyInit_multiarray)')
  File "/opt/ohpc/pub/libs/gnu/numpy/1.9.2/lib64/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
    from . import add_newdocs
  File "/opt/ohpc/pub/libs/gnu/numpy/1.9.2/lib64/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/opt/ohpc/pub/libs/gnu/numpy/1.9.2/lib64/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/opt/ohpc/pub/libs/gnu/numpy/1.9.2/lib64/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/opt/ohpc/pub/libs/gnu/numpy/1.9.2/lib64/python2.7/site-packages/numpy/core/__init__.py", line 6, in <module>
    from . import multiarray

Stacktrace:
 [1] pyimport(::String) at /home/rkurchin/.julia/packages/PyCall/tqyST/src/PyCall.jl:547
 [2] top-level scope at REPL[17]:1

Note that the stacktrace shows the system python (2.7) as opposed to the Conda.jl Python 3 that it should be using. This PyInit_multiarray seems to be a documented error arising when using Python 2 where Python 3 is needed.

OS details:

NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

The really weird part is I've gotten this to work perfectly on another system with the same OS and the only difference between the two that I can figure out is that the other system is running Julia 1.5.1 whereas this one is on 1.5.2.

I've completely run out of troubleshooting ideas here and would love any input!

stevengj commented 3 years ago

Probably some environment variable like PYTHONPATH is messing things up. I would check your environment for python-related variables.

rkurchin commented 3 years ago

aha, that was it! If I blank out PYTHONPATH as well, it works! Thanks! Possibly worth noting this in documentation/readme somewhere? I'll leave it to the developers where it would be appropriate...