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

[Solved] Installing mlagents doesn't generate a compatible Tensorflow. #4033

Closed
jdunwoody opened this issue May 28, 2020 · 8 comments
Closed
Assignees
Labels
bug Issue describes a potential bug in ml-agents.

Comments

@jdunwoody
Copy link
Contributor

mlagents-learn generates a stack trace because of Tensorflow with any command

ImportError: DLL load failed: The specified module could not be found.

a requirements.txt file would be helpful to lock down the various dependencies.
Tensorflow messageboards suggest downgrading protobuff versions and tensorflow versions. Could someone freeze a recent version of their environment and post it? This might help find a combination of dependencies that work together with the latest release of mlagents.

To Reproduce

C:\Projects\Unity\ml-agents>python --version
Python 3.7.7
C:\Projects\Unity\ml-agents>pip list
Package    Version
---------- -------
pip        20.1.1
setuptools 41.2.0
C:\Projects\Unity\ml-agents>pip install mlagents --no-cache-dir

C:\Projects\Unity\ml-agents>pip list
Package                Version
---------------------- -----------
absl-py                0.9.0
astunparse             1.6.3
cachetools             4.1.0
certifi                2020.4.5.1
chardet                3.0.4
cloudpickle            1.4.1
gast                   0.3.3
google-auth            1.15.0
google-auth-oauthlib   0.4.1
google-pasta           0.2.0
grpcio                 1.29.0
h5py                   2.10.0
idna                   2.9
importlib-metadata     1.6.0
Keras-Preprocessing    1.1.2
Markdown               3.2.2
mlagents               0.16.1
mlagents-envs          0.16.1
numpy                  1.18.4
oauthlib               3.1.0
opt-einsum             3.2.1
Pillow                 7.1.2
pip                    20.1.1
protobuf               3.12.2
pyasn1                 0.4.8
pyasn1-modules         0.2.8
pypiwin32              223
pywin32                227
PyYAML                 5.3.1
requests               2.23.0
requests-oauthlib      1.3.0
rsa                    4.0
scipy                  1.4.1
setuptools             41.2.0
six                    1.15.0
tensorboard            2.2.1
tensorboard-plugin-wit 1.6.0.post3
tensorflow             2.2.0
tensorflow-estimator   2.2.0
termcolor              1.1.0
urllib3                1.25.9
Werkzeug               1.0.1
wheel                  0.34.2
wrapt                  1.12.1
zipp                   3.1.0
C:\Projects\Unity\ml-agents>mlagents-learn
Traceback (most recent call last):
  File "c:\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "c:\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "c:\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "c:\python\python37\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "c:\python\python37\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
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:\python\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python\Python37\Scripts\mlagents-learn.exe\__main__.py", line 4, in <module>
  File "c:\python\python37\lib\site-packages\mlagents\trainers\learn.py", line 12, in <module>
    from mlagents import tf_utils
  File "c:\python\python37\lib\site-packages\mlagents\tf_utils\__init__.py", line 1, in <module>
    from mlagents.tf_utils.tf import tf as tf  # noqa
  File "c:\python\python37\lib\site-packages\mlagents\tf_utils\tf.py", line 3, in <module>
    import tensorflow as tf  # noqa I201
  File "c:\python\python37\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "c:\python\python37\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "c:\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 69, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "c:\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "c:\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "c:\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "c:\python\python37\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "c:\python\python37\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

Environment:

  • Unity Version: 2018.4.23f1
  • OS + version: Microsoft Windows 10 Home
  • ML-Agents version: release_2_branch
  • TensorFlow version: 2.2.0
  • Environment: No environment, root directory running mlagents-learn --help`
@jdunwoody jdunwoody added the bug Issue describes a potential bug in ml-agents. label May 28, 2020
@jdunwoody
Copy link
Contributor Author

I have also tried with Anaconda.

> python --version
Python 3.7.7
> pip list (before install)

Package      Version
------------ -------------------
certifi      2020.4.5.1
pip          20.0.2
setuptools   46.4.0.post20200518
wheel        0.34.2
wincertstore 0.2
> git status
On branch release_2_branch
Your branch is up to date with 'origin/release_2_branch'.
> unity version
2018.4.23f1
> ML Agents (com.unity.ml-agents)
1.0.2 preview
> pip install mlagents

(Python37MLAgents) C:\Projects\Unity\ml-agents>pip list
Package                Version
---------------------- -------------------
absl-py                0.9.0
astunparse             1.6.3
cachetools             4.1.0
certifi                2020.4.5.1
chardet                3.0.4
cloudpickle            1.4.1
gast                   0.3.3
google-auth            1.15.0
google-auth-oauthlib   0.4.1
google-pasta           0.2.0
grpcio                 1.29.0
h5py                   2.10.0
idna                   2.9
importlib-metadata     1.6.0
Keras-Preprocessing    1.1.2
Markdown               3.2.2
mlagents               0.16.1
mlagents-envs          0.16.1
numpy                  1.18.4
oauthlib               3.1.0
opt-einsum             3.2.1
Pillow                 7.1.2
pip                    20.0.2
protobuf               3.12.2
pyasn1                 0.4.8
pyasn1-modules         0.2.8
pypiwin32              223
pywin32                227
PyYAML                 5.3.1
requests               2.23.0
requests-oauthlib      1.3.0
rsa                    4.0
scipy                  1.4.1
setuptools             46.4.0.post20200518
six                    1.15.0
tensorboard            2.2.1
tensorboard-plugin-wit 1.6.0.post3
tensorflow             2.2.0
tensorflow-estimator   2.2.0
termcolor              1.1.0
urllib3                1.25.9
Werkzeug               1.0.1
wheel                  0.34.2
wincertstore           0.2
wrapt                  1.12.1
zipp                   3.1.0
(Python37MLAgents) C:\Projects\Unity\ml-agents>mlagents-learn --help
Traceback (most recent call last):
  File "c:\python\anaconda3\envs\python37mlagents\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "c:\python\anaconda3\envs\python37mlagents\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "c:\python\anaconda3\envs\python37mlagents\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "c:\python\anaconda3\envs\python37mlagents\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "c:\python\anaconda3\envs\python37mlagents\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
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:\python\anaconda3\envs\python37mlagents\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python\anaconda3\envs\python37mlagents\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\python\anaconda3\envs\Python37MLAgents\Scripts\mlagents-learn.exe\__main__.py", line 4, in <module>
  File "c:\python\anaconda3\envs\python37mlagents\lib\site-packages\mlagents\trainers\learn.py", line 12, in <module>
    from mlagents import tf_utils
  File "c:\python\anaconda3\envs\python37mlagents\lib\site-packages\mlagents\tf_utils\__init__.py", line 1, in <module>
    from mlagents.tf_utils.tf import tf as tf  # noqa
  File "c:\python\anaconda3\envs\python37mlagents\lib\site-packages\mlagents\tf_utils\tf.py", line 3, in <module>
    import tensorflow as tf  # noqa I201
  File "c:\python\anaconda3\envs\python37mlagents\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "c:\python\anaconda3\envs\python37mlagents\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "c:\python\anaconda3\envs\python37mlagents\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 69, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "c:\python\anaconda3\envs\python37mlagents\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "c:\python\anaconda3\envs\python37mlagents\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "c:\python\anaconda3\envs\python37mlagents\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "c:\python\anaconda3\envs\python37mlagents\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "c:\python\anaconda3\envs\python37mlagents\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

@jdunwoody jdunwoody changed the title Tensorflow dependency error. Installing mlagents doesn't generate a compatible Tensorflow. May 28, 2020
@chriselion
Copy link
Contributor

@jdunwoody This appears to be a general tensorflow problem, and not specific to ML-Agents.

Have you tried this? tensorflow/tensorflow#22794 (comment) (which I found by following the link to https://www.tensorflow.org/install/errors)

@anupam-142857 anupam-142857 self-assigned this May 28, 2020
@jdunwoody
Copy link
Contributor Author

@jdunwoody This appears to be a general tensorflow problem, and not specific to ML-Agents.

Have you tried this? tensorflow/tensorflow#22794 (comment) (which I found by following the link to https://www.tensorflow.org/install/errors)

That was exactly it! Thankyou very much!
Here is the solution in case the tensorflow link breaks:

For this problem

ImportError: DLL load failed: The specified module could not be found.

Install this
https://support.microsoft.com/en-my/help/2977003/the-latest-supported-visual-c-downloads

I also looked into the Tensorflow messageboards for reasons for this error but didn't get to the bottom of the discussion - to find this gem! Too many suggestions from the Tensorflow community suggesting various combinations of protobuf, tensorflow and cuda that I couldn't find a combination that works.

Would it be worthwhile adding this dependency to the mlagents installation docs, given that this requirement is now default for Linux and Windows Tensforflow?

I can raise a pull request if you'd like me to do it.

@jdunwoody jdunwoody changed the title Installing mlagents doesn't generate a compatible Tensorflow. [Solved] Installing mlagents doesn't generate a compatible Tensorflow. May 28, 2020
@chriselion
Copy link
Contributor

Glad that fixed it!

I think we should definitely add it to the FAQ here: https://github.com/Unity-Technologies/ml-agents/blob/master/docs/FAQ.md#tensorflow-dependency

An additional option would be to do a try-catch around the tensorflow import here

import tensorflow as tf # noqa I201

and log a better error message if the exception contains "DLL load failed". I like this option since it keeps the solution close to the problem, unfortunately I'm not on Windows so it's hard for me to test.

As for the installation instructions, @mmattar (who's currently on PTO until the end of the week) has some opinions on what should and shouldn't go in the install guide, and recently rewrote some large swaths of it.

If you want to make a pull request for either the FAQ or the try-catch, please do. You're welcome to for the installation instructions too, it just might take a few days to get it reviewed.

@jdunwoody
Copy link
Contributor Author

I'll submit a PR for at least the FAQ. I'll see how the guard code could work.
Thanks again for your response and suggestion.

chriselion added a commit that referenced this issue May 29, 2020
* Added Microsoft cpp dependency for windows users in faq (#4033)

* Update docs/FAQ.md

Co-authored-by: Chris Elion <celion@gmail.com>

* Update docs/FAQ.md

Co-authored-by: Chris Elion <celion@gmail.com>

Co-authored-by: Chris Elion <celion@gmail.com>
@Godatplay
Copy link

Could this be made more obvious in the Installation Guide? I think it should be mentioned there pretty clearly, since I only found out the solution to this problem by searching through previous issues and finding this. I didn't even consider looking for a FAQ since I interpreted Tensorflow's problem as a problem or bug rather than a question.

@Godatplay
Copy link

Godatplay commented Sep 4, 2020

Actually my bad, repairing the C++ redistributables did not solve my problem. I still get the following:

Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
2020-09-04 01:08:21.885272: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-09-04 01:08:21.888741: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

(not sure why it says win32, I'm definitely 64-bit)

EDIT: Needed to restart after CUDA install, ok good now ^_^

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue describes a potential bug in ml-agents.
Projects
None yet
Development

No branches or pull requests

4 participants