Hi,
I have a package installed in anaconda, and I want to use in Julia.
I did the following:
- set python environment in Julia to be anaconda python
- and rebuilt pycall
- restart Julia
I still have an importerror!
Any suggession?
Thanks
Hi,
I have a package installed in anaconda, and I want to use in Julia.
I did the following:
Thanks
Hi @nadaa and welcome to the julia discourse! Are you able to post the julia code youâre calling to import your python module and the exact error youâre getting? And are you unable to import any python modules into julia, or are you just having trouble with a particular module?
Itâs hard to know what the problem might be without more information. For some general tips on getting help on discourse, check out: Please read: make it easier to help you
Hi @Pbellive,
Import works with python built in packages only. For example, I tried to import pandas but got an error.
using PyCall
pandas = pyimport("pandas")
âERROR: LoadError: PyError (PyImport_ImportModule
The Python package pandas could not be found by pyimport. Usually this means
that you did not install pandas in the Python version being used by PyCallâ
Thank you
You can try pandas = pyimport_conda("pandas")
.
Probably you didnât configure PyCall to use the python
installation where you installed pandas
. Look at PyCall.python
to see what Python installation PyCall is configured to use.
Thanks @tkf, I got an error
ERROR: LoadError: MethodError: no method matching pyimport_conda(::String)
Thanks. Python path in Julia is the same as Anaconda!
Was there more output from the pyimport
error message?
If you run the Python from println(PyCall.python)
â that is, paste that path exactly into the Terminal (donât just run python
) and type import pandas
, does it work?
I paste the path from println(PyCall.python)
into the terminal (python Repl works).
This is the whole error:
The Python package pandas could not be found by pyimport. Usually this means
that you did not install pandas in the Python version being used by PyCall.PyCall is currently configured to use the Python version at:
C:\Users\na\AppData\Local\Continuum\anaconda3\python.exe
and you should use whatever mechanism you usually use (apt-get, pip, conda,
etcetera) to install the Python package containing the pandas module.One alternative is to re-configure PyCall to use a different Python
version on your system: set ENV[âPYTHONâ] to the path/name of the python
executable you want to use, run Pkg.build(âPyCallâ), and re-launch Julia.Another alternative is to configure PyCall to use a Julia-specific Python
distribution via the Conda.jl package (which installs a private Anaconda
Python distribution), which has the advantage that packages can be installed
and kept up-to-date via Julia. As explained in the PyCall documentation,
set ENV[âPYTHONâ]=ââ, run Pkg.build(âPyCallâ), and re-launch Julia. Then,
To install the pandas module, you can usepyimport_conda("pandas", PKG)
,
where PKG is the Anaconda package the contains the module pandas,
or alternatively you can use the Conda package directly (via
using Conda
followed byConda.add
etcetera).) <class âImportErrorâ>
ImportError(âUnable to import required dependencies:\nnumpy: DLL load failed: Das angegebene Modul wurde nicht gefunden.â)
File âC:\Users\na\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_init_.pyâ, line 17, in
âUnable to import required dependencies:\nâ + â\nâ.join(missing_dependencies)
This is the key line. What is the error when you try to pyimport("numpy")
?
ERROR: LoadError: PyError (PyImport_ImportModule
The Python package numpy could not be found by pyimport. Usually this means
that you did not install numpy in the Python version being used by PyCall.
Hi,
I had a similar issue, where I have different Python versions installed with Anaconda, and I needed to call them from within Julia. This is what I ended up with. If I remember OK, everytime I change the Python I use I have to rebuild PyCall. If you always use the same one, I guess you are ok building it only once.
ENV["PYTHON"]="/home/angelv/local/prog_langs/anaconda3/envs/chianti/bin/python"
using Pkg
pkg"build PyCall"
using PyCall
chio = pyimport("ChiantiPy.tools.io")
ch = pyimport("ChiantiPy.core")
Cheers,
Again, give the full error. The low-level error reported by Python will be at the end.
Building Conda ââ
C:\Users\na\.julia\packages\Conda\3rPhK\deps\build.log
Building PyCall âC:\Users\na\.julia\packages\PyCall\zqDXB\deps\build.log
ERROR: LoadError: PyError (PyImport_ImportModuleThe Python package numpy could not be found 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 Python version at:
C:\Users\na\AppData\Local\Continuum\anaconda3\python.exe
and you should use whatever mechanism you usually use (apt-get, pip, conda,
etcetera) to install the Python package containing the numpy module.One alternative is to re-configure PyCall to use a different Python
version on your system: set ENV[âPYTHONâ] to the path/name of the python
executable you want to use, run Pkg.build(âPyCallâ), and re-launch Julia.Another alternative is to configure PyCall to use a Julia-specific Python
distribution via the Conda.jl package (which installs a private Anaconda
Python distribution), which has the advantage that packages can be installed
and kept up-to-date via Julia. As explained in the PyCall documentation,
set ENV[âPYTHONâ]=ââ, run Pkg.build(âPyCallâ), and re-launch Julia. Then,
To install the numpy module, you can usepyimport_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 byConda.add
etcetera).) <class âImportErrorâ>
ImportError(âDLL load failed: Das angegebene Modul wurde nicht gefunden.â)
File âC:\Users\na\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy_init_.pyâ, line 140, in
from . import _distributor_init
File âC:\Users\na\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy_distributor_init.pyâ, line 34, in
from . import _mklinit
Are you using MKL.jl, or some other MKL-enabled Julia version? In this case itâs possible that you are seeing a conflict between the MKL library loaded by Python and one in Julia?
Hi, how can I check if MKL.jl exists?
and how to uninstall it?
Thanks
If youâre not using MKL
, then it doesnât matter whether it is installed.
Hello, not sure if you have figured it out. I had a similar problem, this works for me. Uninstall Julia and reinstall it to the same folder where Anaconda is. Hope this helps!
It worked for me too!