OpenAI gym mujoco ImportError: No module named 'mujoco_py.mjlib' - python

I try to run this code in openAi gym. but it can not.
import mujoco_py
import gym
from os.path import dirname
env = gym.make('Hopper-v1')
env.reset()
for _ in range(1000):
env.render()
env.step(env.action_space.sample())
the error info:
/Users/yunfanlu/anaconda/envs/py35/bin/python3.5 /Users/yunfanlu/WorkPlace/OpenAIGym/OpenGymL/c.py
[2017-07-23 17:17:15,633] Making new env: Hopper-v1
Traceback (most recent call last):
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/mujoco/mujoco_env.py", line 12, in <module>
from mujoco_py.mjlib import mjlib
ImportError: No module named 'mujoco_py.mjlib'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/yunfanlu/WorkPlace/OpenAIGym/OpenGymL/c.py", line 15, in <module>
env = gym.make('Hopper-v1')
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/registration.py", line 161, in make
return registry.make(id)
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/registration.py", line 119, in make
env = spec.make()
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/registration.py", line 85, in make
cls = load(self._entry_point)
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/registration.py", line 17, in load
result = entry_point.load(False)
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg/pkg_resources/__init__.py", line 2258, in load
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg/pkg_resources/__init__.py", line 2264, in resolve
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/mujoco/__init__.py", line 1, in <module>
from gym.envs.mujoco.mujoco_env import MujocoEnv
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/mujoco/mujoco_env.py", line 14, in <module>
raise error.DependencyNotInstalled("{}. (HINT: you need to install mujoco_py, and also perform the setup instructions here: https://github.com/openai/mujoco-py/.)".format(e))
gym.error.DependencyNotInstalled: No module named 'mujoco_py.mjlib'. (HINT: you need to install mujoco_py, and also perform the setup instructions here: https://github.com/openai/mujoco-py/.)
Process finished with exit code 1
My Computer Envs:
OS: macOS
python: python3.5 (conda envs)
I have benn install "pip install 'gym[all]'" and install mujoco.
➜ .mujoco tree
.
├── LICENSE.txt
├── mjkey.txt
└── mjpro150
I can run the examples of mujoco. it is successful.
(py35) ➜ OpenGymL python body_interaction.py
Creating window glfw

I have the same issue and it is caused by having a recent mujoco-py version installed which is not compatible with the mujoco environment of the gym package.
The issue is still open and its details are captured in #80. As commented by machinaut, the update is on the roadmap and you can use version 0.5.7 in the meantime.
pip install mujoco-py==0.5.7

Related

Problem launching Jupyter Notebook from Anaconda

I am having issues launching Jupyter Notebook. I have tried to do it two ways and seem to get errors.
1 - Launching from the Anaconda Prompt using the command jupyter notebook or directly choosing from the Anaconda menu
I get the following:
(base) C:\Users\metni>jupyter notebook
Traceback (most recent call last):
File "C:\Users\metni\anaconda3\lib\site-packages\jsonschema\__init__.py", line 31, in <module>
from importlib import metadata
ImportError: cannot import name 'metadata' from 'importlib' (C:\Users\metni\anaconda3\lib\importlib\__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\metni\anaconda3\lib\site-packages\nbformat\validator.py", line 12, in <module>
from jsonschema import ValidationError
File "C:\Users\metni\anaconda3\lib\site-packages\jsonschema\__init__.py", line 33, in <module>
import importlib_metadata as metadata
ModuleNotFoundError: No module named 'importlib_metadata'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\metni\anaconda3\Scripts\jupyter-notebook-script.py", line 6, in <module>
from notebook.notebookapp import main
File "C:\Users\metni\anaconda3\lib\site-packages\notebook\notebookapp.py", line 80, in <module>
from .services.contents.manager import ContentsManager
File "C:\Users\metni\anaconda3\lib\site-packages\notebook\services\contents\manager.py", line 17, in <module>
from nbformat import sign, validate as validate_nb, ValidationError
File "C:\Users\metni\anaconda3\lib\site-packages\nbformat\__init__.py", line 32, in <module>
from .validator import validate, ValidationError
File "C:\Users\metni\anaconda3\lib\site-packages\nbformat\validator.py", line 23, in <module>
raise ImportError(str(e) + verbose_msg)
ImportError: No module named 'importlib_metadata'
Jupyter notebook format depends on the jsonschema package:
https://pypi.python.org/pypi/jsonschema
Please install it first.
2 - Launching from the command line with the same command
I get the following:
C:\Users\metni>jupyter notebook
Traceback (most recent call last):
File "C:\Users\metni\anaconda3\Scripts\jupyter-notebook-script.py", line 6, in <module>
from notebook.notebookapp import main
File "C:\Users\metni\anaconda3\lib\site-packages\notebook\notebookapp.py", line 64, in <module>
from tornado import httpserver
File "C:\Users\metni\anaconda3\lib\site-packages\tornado\httpserver.py", line 29, in <module>
import ssl
File "C:\Users\metni\anaconda3\lib\ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified module could not be found.
It seems like this is referring to a package called jsonschema which is not installed apparently, but running a pip install jsonschema does not solve the problem for me...
In the answer above I also have two two commands but they are a bit different
source /opt/anaconda/bin/activate root
and then
jupyter notebook
It seems like you have to go into your anaconda directory then bin, then you can
"activate root"
It also looks like you need to install some other dependencies for jupyter to run. Where is says
Jupyter notebook format depends on the jsonschema package:
https://pypi.python.org/pypi/jsonschema
Please install it first.
So if the above doesn't work try installing the other dependency and try again
Based on this answer from a similar question, I managed to solve the problem by running these two commands:
conda update -n root conda
conda update --all
I thus updated all packages, and the notebook is now launching.

Error: It seems that scikit-learn has not been built correctly

I am running Mac OS 10.10.5. and Python 3 and XCode 7.2.1. I installed SciKit-Learn and all of its dependencies with pip (PyCharm) and I am getting this error when I try to use the package. I tried it on another computer also running 10.10.5 and didn't get the error. Here is the full error message:
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/jonathankogan/PycharmProjects/Test/test.py
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/__check_build/__init__.py", line 44, in <module>
from ._check_build import check_build
ImportError: dynamic module does not define module export function (PyInit__check_build)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jonathankogan/PycharmProjects/Test/test.py", line 2, in <module>
from sklearn import datasets
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/__init__.py", line 56, in <module>
from . import __check_build
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/__check_build/__init__.py", line 46, in <module>
raise_build_error(e)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/__check_build/__init__.py", line 41, in raise_build_error
%s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
ImportError: dynamic module does not define module export function (PyInit__check_build)
___________________________________________________________________________
Contents of /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/__check_build:
__init__.py __pycache__ _check_build.cpython-35m-darwin.so
setup.py
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.

tox Invocation failed for Python 3

tox runs my Python 2.7 tests, but fails for Python 3.4. It gives an "Invocation failed" message. Excerpts:
py34 create: /home/josh/code/ezoutlet/.tox/py34
ERROR: invocation failed (exit code 1), logfile: /home/josh/code/ezoutlet/.tox/py34/log/py34-0.log
ERROR: actionid: py34
msg: getenv
cmdargs: ['/usr/bin/python', '-m', 'virtualenv', '--python', '/usr/bin/python3.4', 'py34']
And later
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Running virtualenv with interpreter /usr/bin/python3.4
ERROR: InvocationError: /usr/bin/python -m virtualenv --python /usr/bin/python3.4 py34 (see /home/josh/code/ezoutlet/.tox/py34/log/py34-0.log)
You need to look at the details of the error message. Notice the command that failed (from the first excerpt):
cmdargs: ['/usr/bin/python', '-m', 'virtualenv', '--python', '/usr/bin/python3.4', 'py34']
You can run this manually with:
/usr/bin/python -m virtualenv --python /usr/bin/python3.4 py34
Assuming you see the same error, your issue is with virtualenv rather than tox.
I reviewed the virtualenv help page and it seems like this should work. Faced with a possible bug, a good first step is to upgrade Python, virtualenv, or other libraries.
In my case, upgrading virtualenv was the solution:
pip install --upgrade virtualenv
Interestingly, this solution worked on both Windows and Linux. Most likely, there was a bug fix between when I got virtualenv and the latest release.

Passing Python3 to virtualenvwrapper throws up ImportError

I'm trying to use the virtualenvwrapper to make a python 3 based virtualenv. However,I'm when I pass the optional interpreter argument, I'm seeing this error. I'm running Ubuntu 15.04. I tried reinstalling virtualenv and virtualenvwrapper without success. Thanks for all your help!
$ mkvirtualenv scriptcutter --python=/usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
I come across same issue, but after I downgrade virtualenv to 12.0.2, this problem disappears.
This is sort of a workaround for now.
Create a virtualenv using pyvenv.
# install pyvenv on Ubuntu
sudo apt-get install python3-venv
To minimize disruption in your normal workflow, pass a destination directory that is the same as the one used by virtualenvwrapper Like so,
pyvenv example ~/.virtualenvs/example
This is automatically working with workon and cdproject commands. I don't use much else that is provided by virtualenvwrapper
Hope this helps.
You can upgrade to the most recent version of virtualenv, with:
sudo pip install --upgrade https://github.com/pypa/virtualenv/archive/master.zip
virtualenv --version
# Returns 15.2.0.dev0 when I ran it
The following command then works:
mkvirtualenv scriptcutter --python=/usr/bin/python3
Apparently, the develop branch was dropped, so the URL with "develop" will no longer work. My answer was based off of #pjotr_dolphin's comment, with the URL updated.

Cannot install html package with pip in virtualenv

In my root project folder I have created a virtual environment for python 3.4 using the following commands:
$ virtualenv -p /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 venv
$ source venv/bin/activate
Now I would like to install some packages with pip only for this project and I do:
$ venv/bin/pip install html
And I get the following error (full traceback except I have replaced path with '...'):
Collecting html
Using cached html-1.16.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 3, in <module>
File ".../venv/lib/python3.4/site-packages/setuptools/__init__.py", line 11, in <module>
from setuptools.extension import Extension
File ".../venv/lib/python3.4/site-packages/setuptools/extension.py", line 8, in <module>
from .dist import _get_unpatched
File ".../venv/lib/python3.4/site-packages/setuptools/dist.py", line 16, in <module>
from setuptools.depends import Require
File ".../venv/lib/python3.4/site-packages/setuptools/depends.py", line 6, in <module>
from setuptools import compat
File ".../venv/lib/python3.4/site-packages/setuptools/compat.py", line 44, in <module>
from html.entities import name2codepoint
ImportError: No module named 'html.entities'; 'html' is not a package
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/xz/15p_y6cn09bdc55vkvx6vrd80000gn/T/pip-build-lgl2qvpz/html
Note that I can install this package without problems globally for python 2.7.5 which is the default version on my mac.
The package I am trying to install is this one:
https://pypi.python.org/pypi/html/1.16
This package is obsolete not compatible with current packaging tools, its last release was more than 8 years ago. I really doubt that packages published so long time ago are still usable with recent python(s).

Categories