MahmoudAbdelRahman / GH_CPython

CPython plugin for Rhino-Grasshopper
BSD 2-Clause "Simplified" License
175 stars 38 forks source link

Issues with Anaconda environment as python interpreter #40

Closed kastnerp closed 4 years ago

kastnerp commented 4 years ago

Hi,

Thanks for the great work on this! It seems to me that it should be possible to use this with Anaconda, however, when I set a custom interpreter and try to import numpy, I receive this error:

C:\Users\USERDIR\.conda\envs\cpython36\lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
  from . import _distributor_init
Traceback (most recent call last):
  File "C:\Users\USERDIR\.conda\envs\cpython36\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
    from . import multiarray
  File "C:\Users\USERDIR\.conda\envs\cpython36\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
    from . import overrides
  File "C:\Users\USERDIR\.conda\envs\cpython36\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\GH_CPython\PythonFileWritten_2.py", line 33, in <module>
    import numpy
  File "C:\Users\USERDIR\.conda\envs\cpython36\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import core
  File "C:\Users\USERDIR\.conda\envs\cpython36\lib\site-packages\numpy\core\__init__.py", line 54, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python3.6 from "C:\Users\USERDIR\.conda\envs\cpython36\python.exe",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.18.1" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: DLL load failed: The specified module could not be found.

(Please note that I replaced my user directory in the paste above)

Opening the environment in a CLI and importing numpy from there works without any problems. One user reported #39 that reinstalling the numpy package solved the issue for him but that, unfortunately, doesn't work for me. Is there anything I can do to get this running with Anaconda?

Best,

Patrick

dt-js commented 4 years ago

Hi,

I just had this issue and I found advice here: https://github.com/numpy/numpy/issues/14675

So basically in my code, I added:

# Import libraries
import os
import sys

env_p = sys.prefix  # path to the env
print("Env. path: {}".format(env_p))

new_p = ''
for extra_p in (r"Library\mingw-w64\bin",
    r"Library\usr\bin",
    r"Library\bin",
    r"Scripts",
    r"bin"):
    new_p +=  os.path.join(env_p, extra_p) + ';'

os.environ["PATH"] = new_p + os.environ["PATH"]  # set it for Python

import numpy

Best,

Justyna

kastnerp commented 4 years ago

That worked, thanks!

tildekarthik commented 4 years ago

This worked for me too. This is something to do with emacs only as the code seems to work ok in vscode. Think it is the mingw-p64