ctuning / ck-tensorflow

Collective Knowledge components for TensorFlow (code, data sets, models, packages, workflows):
http://cKnowledge.org
BSD 3-Clause "New" or "Revised" License
93 stars 26 forks source link

Tensorflow 1.10.1 issue with python2 #96

Closed yzh89 closed 5 years ago

yzh89 commented 5 years ago

Tensorflow 1.10.1 seems to have a conflict with preexisting python2 packages in CK framework. @psyhtest

$ ck virtual env --tags=lib,tensorflow
$ python -c "import numpy"

failed with error message

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/zzdq0r/CK-TOOLS/tensorflow-prebuilt-cpu-1.10.1-compiler.python-3.5.2-linux-64/lib/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/home/zzdq0r/CK-TOOLS/tensorflow-prebuilt-cpu-1.10.1-compiler.python-3.5.2-linux-64/lib/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/zzdq0r/CK-TOOLS/tensorflow-prebuilt-cpu-1.10.1-compiler.python-3.5.2-linux-64/lib/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/home/zzdq0r/CK-TOOLS/tensorflow-prebuilt-cpu-1.10.1-compiler.python-3.5.2-linux-64/lib/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/home/zzdq0r/CK-TOOLS/tensorflow-prebuilt-cpu-1.10.1-compiler.python-3.5.2-linux-64/lib/numpy/core/__init__.py", line 26, in <module>
    raise ImportError(msg)
ImportError: 
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: cannot import name multiarray

The trace seems to suggest in python 2.7 it is using prebuild tensorflow 1.10.1 with python 3.5.

In a clean installation of Tensorflow detection API does not have any issues.

gfursin commented 5 years ago

Hi @yzh89.

You need to use exactly the same python version which you used when installing TensorFlow package via CK. The reason is that CK will install extra Python packages such as numpy required by TF for this specific Python version and will add then to PYTHONPATH in the above virtual env. So if you do the following, it should work:

$ python3.5 -c "import numpy"

other python versions will indeed conflict with above packages ...

gfursin commented 5 years ago

In fact, it was solving different existing problems when you have multiple Pythons installed and then try to install TF for just one of them - in such case TF will often fail with above error. That's why we fix Python, fix TF dependencies for it, then install TF, and then allow you to use it from CK virtual environment with the same Python ... Actually, you can use ${CK_PYTHON_BIN} to know which Python version was used in this CK virtual environment ...

unmeshbordoloi commented 5 years ago

I understand. However, I am not sure how to configure CK program object-detection-tf-py to use Python3.5.

gfursin commented 5 years ago

I see "python" in the CK dependencies of this program, so normally, if you run it, you should be asked to select a Python (if you have multiple versions registered by CK). If CK already detected some version and it's not the suitable one, you can detect and register the correct one as follows:

$ ck detect soft --tags=compiler,python

Next time you run this program (i.e. "ck run program:object-detection-tf-py"), CK should ask you which Python version to use ...

However, maybe I am missing something. I will let @psyhtest check it further ...

gfursin commented 5 years ago

By the way, one more thing, I have an experimental option --reuse_deps which tries to reuse already resolved dependencies (such as Python) for all other dependencies. This can help you rebuild proper environment from scratch:

$ ck run object-detection-tf-py --reuse_deps
psyhtest commented 5 years ago

The most robust way of handling this is to select a version of Python (e.g. python3.6) and stick to it when installing dependencies via pip e.g.:

$ ck detect soft:compiler.python --full_path=`which python3.6`
$ python3.6 -m pip install numpy

then selecting the same version when installing TensorFlow:

$ ck install package --tags=lib,tensorflow

and finally when running a benchmark:

$ CK_PYTHON=python3.6 ck run program:image-classification-tf-py