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

Trouble using numpy and matplotlib via PyCall in Windows 10 #730

Closed
BoundaryValueProblems opened this issue Dec 9, 2019 · 2 comments · Fixed by #748
Closed

Trouble using numpy and matplotlib via PyCall in Windows 10 #730

BoundaryValueProblems opened this issue Dec 9, 2019 · 2 comments · Fixed by #748

Comments

@BoundaryValueProblems
Copy link

BoundaryValueProblems commented Dec 9, 2019

So far, this only happens on my Windows 10 (version 1909). No problems on my MacBook Pro and my linux machine. This problem occurs regardless I uninstall all of the python versions except that Julia internal version via Conda. Both Conda and PyCall are updated to be the current master branches.

julia> ENV["PYTHON"]=""
julia> Pkg.build("PyCall")
Building Conda ─→ `C:\Users\xxx\.julia\packages\Conda\kLXeC\deps\build.log`
  Building PyCall → `C:\Users\xxx\.julia\packages\PyCall\ttONZ\deps\build.log`
false
julia> using Conda, PyCall
julia> Conda.update()
# this installs a bunch of packages
julia> Conda.runconda(`search numpy=1.17.4`)
[ Info: Running `conda search numpy=1.17.4` in root environment
Loading channels: done
# Name                       Version           Build  Channel
numpy                         1.17.4  py36h4320e6b_0  pkgs/main
numpy                         1.17.4  py37h4320e6b_0  pkgs/main
numpy                         1.17.4  py38h4320e6b_0  pkgs/main

julia> pyimport("numpy")
ERROR: 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.

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('\n\nIMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!\n\nImporting the numpy c-extensions failed.\n- Try uninstalling and reinstalling numpy.\n- If you have already done that, then:\n  1. Check that you expected to use Python3.6 from "C:\\Program Files\\Julia-1.3.0\\bin\\julia.exe",\n     and that you have no directories in your PATH or PYTHONPATH that can\n     interfere with the Python and numpy version "1.17.4" you\'re trying to use.\n  2. If (1) looks fine, you can open a new issue at\n     https://github.com/numpy/numpy/issues.  Please include details on:\n     - how you installed Python\n     - how you installed 
numpy\n     - your operating system\n     - whether or not you have multiple versions of Python installed\n     - if you built from source, your compiler versions and ideally a build log\n\n- If you\'re working with a numpy git repository, try `git clean -xdf`\n  (removes all files not under version control) and rebuild numpy.\n\nNote: this error has many possible causes, so please don\'t comment on\nan existing issue about this - open a new one instead.\n\nOriginal error was: DLL load failed: The specified module could not be found.\n',)
  File "C:\Users\xxx\.julia\conda\3\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import core
  File "C:\Users\xxx\.julia\conda\3\lib\site-packages\numpy\core\__init__.py", line 47, in <module>
    raise ImportError(msg)

Stacktrace:
 [1] pyimport(::String) at C:\Users\xxx\.julia\packages\PyCall\ttONZ\src\PyCall.jl:544
 [2] top-level scope at none:0

Similar errors occur when I try to do pyimport("matplotlib") though Conda.runconda(`search matplotlib=3.1.1`) works.
So I am quite puzzled. I would greatly appreciate it if you could help me setting things on my windows machine! Thanks!

@BoundaryValueProblems
Copy link
Author

I resolved the above problem by wiping out ~/.julia, and added necessary packages all over again. Then, I built Conda and PyCall as usual. Then, I added matplotlib by Conda.add("matplotlib"). Everything works now. However, when I do Conda.update(), then the same errors occur all over again. So, shouldn't I update the python packages by Conda.update()? In the case of macOS, this is not a problem. But on windows, this somehow happens.

@stevengj
Copy link
Member

Seems to be a PATH issue with the latest version of Anaconda on windows. Fixed by doing:

using Conda
ENV["PATH"] = Conda.bin_dir(Conda.ROOTENV) * ";" * ENV["PATH"]
using PyPlot

I'll try to get a patch for PyCall soon that does this automatically when we are using Conda.

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 a pull request may close this issue.

2 participants