yglukhov / nimpy

Nim - Python bridge
MIT License
1.47k stars 61 forks source link

`nimble test` fails on mac: #81

Closed timotheecour closed 5 years ago

timotheecour commented 5 years ago

possibly related to this: https://github.com/timotheecour/vitanim/pull/5#issuecomment-457740937 /cc @Vindaar

$nim_D/nimpy master 2.900 $ nimble test
   Warning: Using env var NIM_LIB_PREFIX: /Users/timothee/git_clone//nim//Nim/
  Executing task test in /Users/timothee/git_clone/nim/nimpy/nimpy.nimble
Hint: used config file '/Users/timothee/git_clone/nim/Nim/config/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/.config/nim/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/git_clone/nim/Nim/config/config.nims' [Conf]
/Users/timothee/git_clone/nim/nimpy/tests/nimfrompy.nim(1, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/nimpy/nimpy.nim(1, 24) Warning: import os.nim instead; ospaths is deprecated [Deprecated]
/Users/timothee/git_clone/nim/nimpy/tests/nimfrompy.nim(1, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/nimpy/nimpy.nim(10, 30) Warning: type pragmas follow the type name; this form of writing pragmas is deprecated [Deprecated]
/Users/timothee/git_clone/nim/nimpy/tests/nimfrompy.nim(1, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/nimpy/nimpy.nim(805, 34) Warning: type pragmas follow the type name; this form of writing pragmas is deprecated [Deprecated]
Hint:  [Link]
Hint: operation successful (58055 lines compiled; 1.496 sec total; 91.98MiB peakmem; Debug Build) [SuccessX]
Hint: used config file '/Users/timothee/git_clone/nim/Nim/config/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/.config/nim/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/git_clone/nim/Nim/config/config.nims' [Conf]
/Users/timothee/git_clone/nim/nimpy/tests/custommodulename.nim(1, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/nimpy/nimpy.nim(1, 24) Warning: import os.nim instead; ospaths is deprecated [Deprecated]
/Users/timothee/git_clone/nim/nimpy/tests/custommodulename.nim(1, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/nimpy/nimpy.nim(10, 30) Warning: type pragmas follow the type name; this form of writing pragmas is deprecated [Deprecated]
/Users/timothee/git_clone/nim/nimpy/tests/custommodulename.nim(1, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/nimpy/nimpy.nim(805, 34) Warning: type pragmas follow the type name; this form of writing pragmas is deprecated [Deprecated]
Hint:  [Link]
Hint: operation successful (57710 lines compiled; 1.042 sec total; 73.898MiB peakmem; Debug Build) [SuccessX]
Tests complete!
Tests complete!
Hint: used config file '/Users/timothee/git_clone/nim/Nim/config/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/.config/nim/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/git_clone/nim/Nim/config/config.nims' [Conf]
/Users/timothee/git_clone/nim/nimpy/tests/tpyfromnim.nim(1, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/nimpy/nimpy.nim(1, 24) Warning: import os.nim instead; ospaths is deprecated [Deprecated]
/Users/timothee/git_clone/nim/nimpy/tests/tpyfromnim.nim(1, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/nimpy/nimpy.nim(10, 30) Warning: type pragmas follow the type name; this form of writing pragmas is deprecated [Deprecated]
/Users/timothee/git_clone/nim/nimpy/tests/tpyfromnim.nim(1, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/nimpy/nimpy.nim(805, 34) Warning: type pragmas follow the type name; this form of writing pragmas is deprecated [Deprecated]
Hint:  [Link]
Hint: operation successful (57945 lines compiled; 1.226 sec total; 73.891MiB peakmem; Debug Build) [SuccessX]
Hint: /Users/timothee/git_clone/nim/nimpy/tests/tpyfromnim  [Exec]
/Users/timothee/git_clone/nim/nimpy/tests/tpyfromnim.nim(199) tpyfromnim
/Users/timothee/git_clone/nim/nimpy/tests/tpyfromnim.nim(62) test
/Users/timothee/git_clone/nim/nimpy/nimpy.nim(1018) pyImport
/Users/timothee/git_clone/nim/nimpy/nimpy/py_utils.nim(98) raisePythonError
Error: unhandled exception: <type 'exceptions.ImportError'>: cannot import name _remove_dead_weakref [Exception]
Error: execution of an external program failed: '/Users/timothee/git_clone/nim/nimpy/tests/tpyfromnim '
stack trace: (most recent call last)
/Users/timothee/git_clone/nim/nimpy/nimpy.nimble(34, 18) testTask
/Users/timothee/git_clone/nim/Nim/lib/system/nimscript.nim(241, 7) exec
/Users/timothee/git_clone/nim/Nim/lib/system/nimscript.nim(241, 7) Error: unhandled exception: FAILED: nim c -r tests/tpyfromnim.nim

diagnostic

yglukhov commented 5 years ago

I think nimpy is using python3 on your system. It tries to find the most recent python version. To verify that:

import nimpy
echo pyImport("sys").path

and compare it to

python -c "import sys; print(sys.path)"
timotheecour commented 5 years ago

doesn't look like it:

nim c -r main.nim

import nimpy
echo pyImport("sys").path
['/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Users/timothee/Library/Python/2.7/lib/python/site-packages', '/Users/timothee/homebrew/lib/python2.7/site-packages', '/Users/timothee/homebrew/Cellar/numpy/1.15.4_2/libexec/nose/lib/python2.7/site-packages', '/Users/timothee/homebrew/Cellar/protobuf/3.6.1.3/libexec/lib/python2.7/site-packages', '/Users/timothee/homebrew/opt/llvm_tim/lib/python2.7/site-packages', '/Users/timothee/homebrew/lib/python2.7/site-packages', '/Users/timothee/homebrew/Cellar/numpy/1.15.4_2/libexec/nose/lib/python2.7/site-packages', '/Users/timothee/homebrew/opt/llvm_tim/lib/python2.7/site-packages']
python -c "import sys; print(sys.path)"

['', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Users/timothee/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Users/timothee/Library/Python/2.7/lib/python/site-packages', '/Users/timothee/homebrew/lib/python2.7/site-packages', '/Users/timothee/homebrew/Cellar/numpy/1.15.4_2/libexec/nose/lib/python2.7/site-packages', '/Users/timothee/homebrew/Cellar/protobuf/3.6.1.3/libexec/lib/python2.7/site-packages', '/Users/timothee/homebrew/opt/llvm_tim/lib/python2.7/site-packages', '/Users/timothee/homebrew/lib/python2.7/site-packages', '/Users/timothee/homebrew/Cellar/numpy/1.15.4_2/libexec/nose/lib/python2.7/site-packages', '/Users/timothee/homebrew/opt/llvm_tim/lib/python2.7/site-packages']
yglukhov commented 5 years ago

Ok. And python -c 'import numpy' doesn't raise any errors?

timotheecour commented 5 years ago

it doesn't

yglukhov commented 5 years ago

Googling around this problem is vaguely described as a conflict between the system python and brew python. Could it so happen that python binary comes from the system python, and the dylib loaded by nimpy comes from brew, or the other way around?

narimiran commented 5 years ago

Could it so happen that python binary comes from the system python, and the dylib loaded by nimpy comes from brew, or the other way around?

If so, it might be connected to https://github.com/yglukhov/nimpy/issues/46

yglukhov commented 5 years ago

If so, it might be connected to #46

Yeah, but not really, because any installed python dll should work. And this is just a system (brew?) bug.

timotheecour commented 5 years ago

update: this is related to https://stackoverflow.com/questions/47658596/strange-mixing-of-system-homebrew-python-with-lldb this works:

PATH=/usr/bin:$PATH nimble test

but not ideal obviously as it has other side effects

yglukhov commented 5 years ago

Well I don't see a way to fix this properly. Even with python selection functionality in place, there still remains the possibility to hit this. Because, let me repeat it, I treat this as an os/environment issue. But feel free to prove me wrong.