OpenAI Gym Atari on Windows - python

I'm having issues installing OpenAI Gym Atari environment on Windows 10. I have successfully installed and used OpenAI Gym already on the same system.
It keeps tripping up when trying to run a makefile.
I am running the command pip install gym[atari]
Here is the error:
and here is what I currently have on my system...cmake and make are both clearly installed.

A while ago I have created a fork with Windows support (devs of original repository do not merge or even comment PRs and issues). It does not require neither MSYS/Cygwin nor CMake or Zlib.
To simply install atari-py wheels (binaries) use this command:
pip install -f https://github.com/Kojoley/atari-py/releases atari_py
If you have any distutils supported compiler you can install from sources:
pip install git+https://github.com/Kojoley/atari-py.git
Test your installation with a simple example:
import gym
env = gym.make('SpaceInvaders-v0')
env.reset()
for _ in range(1000):
env.step(env.action_space.sample())
env.render('human')
env.close() # https://github.com/openai/gym/issues/893
If your got a 'scrambled' output that's most likely because your gym is outdated.

I ended up installing Bash on Ubuntu on Windows and using it to run the OpenAI Gym / Atari environment. OpenAI Gym has very limited support for Windows at the moment.

This is not fully tested, because I don't remember exactly what I did, but currently I have openAI gym running with all the atari games set up and displaying, and also matplotlib plots, all while using ubuntu on windows (WSL). In fact I have sublimetext3 and spider working too.
So take these as a guide, but I don't have "clean" environment to test them on.
First, in Windows, Google "xming" (x11 server) and download from sourceforge / install / run. This is what makes it all possible.
Now in WSL bash install the display stuff to work with xming
sudo apt-get install x11-apps
export DISPLAY=localhost:0.0
nano ~/.bashrc #(add export DISPLAY=localhost:0.0 at the end. Ctrl+X to exit/save)
sudo apt-get install gnome-calculator #will get you GTK
Now in WSL bash install Anaconda. this will involve downloading the .sh file (eg with curl -O "[the http link to latest anaconda]" and running it with bash [the file].sh. Don't use sudo when installing Anaconda.
With anaconda installed, close WSL, and restart it. Now make an environment and activate it
conda create -n gym python=3.5 anaconda
source activate gym
Now get the gym repo
git clone https://github.com/openai/gym.git
cd gym
Now install these gym dependencies mentioned on openai gym repo
apt-get install -y python-numpy python-dev cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev python-opengl libboost-all-dev libsdl2-dev swig
Now install libgcc with conda
conda install libgcc
Now build gym
pip install -e '.[all]'
That's basically it. make sure Xming is running on windows, and in WSL type gnome-calculator, and it should bring up the calculator. if it doesn't, keep working on the display side. If it does, try running some of the agents in the gym examples folder.
I may have missed a couple extra dependencies along the way, but these would have been things I figured out based on error messages.
Here's the pic to keep you motivated:
EDIT: Today I ran the following command which installed Qt5 as the back end, and matplotlib is working fine with Qt5Agg as the back end (vs TkAgg). This may be helpful if you're running some thing else on WSL which needs Qt5
sudo apt-get update && sudo apt-get install qtbase5-dev
Also, to find your matplotlibrc, and command prompt type:
python
import matplotlib
print(matplotlib.matplotlib_fname())
quit()
Please note that there is NO GPU SUPPORT on ubuntu for windows. This is the top requested feature at uservoice, yet MS has it on "backlog". If you're interested, vote here

I encountered that gym now requires later version v0.1.4 of atari-py than any of other cloned repos.
Thanks to Nikita Kniazev - I ported his Windows edits to latest code from openai/atari-py and got gym working.
Use:
pip install git+https://github.com/Kojoley/atari-py.git

I had the same issue with the atari-py environment. Then I followed the steps in the Openai GitHub and then it worked.

Related

Ubuntu 20.04 upgrade, Python missing libffi.so.6

I recently upgraded my OS to Ubuntu 20.04 LTS.
Now when I try to import a library like Numpy in Python, I get the following error:
ImportError: libffi.so.6: cannot open shared object file: No such file or directory
I tried installing the libffi package, but apt can't locate it :
sudo apt-get install libffi
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libffi
It seems like I fixed it. I could be wrong, but here is what I think happened:
Ubuntu 20.04 upgraded libffi6 to libffi7
Python is still looking for libffi6
What I did to fix it :
Locate libffi.so.7 in your system
$ find /usr/lib -name "libffi.so*"
Create a simlink named libffi.so.6 that points to libffi.so.7:
sudo ln -s /usr/path/to/libffi.so.7 /usr/lib/path/to/libffi.so.6
UPDATE:
As noted by many users, this fix could have unintended consequences. The better way to do it is to reinstall python as #amichaud explained. This should be used as a last resort IF you're not using pyenv/virtualenv/etc in which case removing python will cause a lot of dependencies to be removed as well.
If you are using pyenv, you should just uninstall the used python version and then reinstall it.
Example:
pyenv uninstall 3.7.4
pyenv install 3.7.4
It's cleaner and safer than renaming system library from my point of view.
I am using Xubuntu 20.04 and recompiling the python version 3.7 did not work for me.
The way I solved this was to download the 19.10 version of the package from here:
http://mirrors.kernel.org/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
and then installing it
sudo apt install ./libffi6_3.2.1-8_amd64.deb
This will unpack the libffi.so.6 and libffi.so.6.0.4 files to /usr/lib/x86_64-linux-gnu/. The libffi.so.6 file is just a link to libffi.so.6.0.4 in the same directory.
As far as I could see this does not overwrite any files so should be safe.
Ubuntu 22.04 additional step
As per comment from pijing below, you need to run this command after installing the above:
apt install libffi-devel
Then recompile Python.
Ubuntu 20 has libffi7 installed instead. It's possible to install the previous version using coming from Ubuntu 19.10 (Eoan Ermine) download from here Or you can follow these commands
$ curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
$ sudo dpkg -i libffi6_3.2.1-8_amd64.deb
Same problem for me
Upgraded to Ubuntu 20
pip didn't work anymore (same error)
What I did was:
Delete the virtual env I was using
Recreate it
Sure, I wasn't able to do a pip freeze to get save my dependencies (as pip didn't work), but fortunately I didn't care about them.
The libffi6 package may be downloaded and installed as follows:
Identify a source for apt from the list Download Page for libffi6
(I picked http://mirrors.kernel.org/ubuntu/ for instance)
Make a back up of /etc/apt/sources.list (just in case)
Edit /etc/apt/sources.list and add the line (I added it to the very end of the file) ands save the file
deb https://mirrors.kernel.org/ubuntu bionic main
Update to use the new repository
sudo apt update
Finally, install the package:
sudo apt install libffi6
Note that both libffi6 and libffi7 appear to coexist. (My Ubuntu version is 20.04)
$ sudo apt list | grep libffi[67]/
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libffi6/bionic,now 3.2.1-8 amd64 [installed]
libffi7/focal,now 3.3-4 amd64 [installed,automatic]
I had the same problem (when I upgrded to Ubuntu 20.04) when I tried to run Jupyter Notebook.
Step 1) --> Just re-install python3.7.6 (the version I was using) :
$ cd path_to_python3.7_folder
Do again de installation process:
$ ./configure --enable-optimizations
$ make
$ sudo make install
Step 2: uninstall jupyter. I used pip3.7 uninstall ...
See: How to uninstall Jupyter note book installed by pip3
Step 3: Re-install jupyter again:
$ pip3.7 install jupyterlab
$ pip3.7 install notebook
Try to run jupyter again. It should work.
Symbolic linking to higher version of existing libffi,(e.g. pointing 6 to 8 or 9) does NOT harm since libffi's interface is almost frozen up to 9 years from now.
Higher SO version such as 6,7 or 8, simply it's there to indicate minimum requirement in case of new feature availability such as ffi_tramp_is_present. libffi itself is totally backward compatible so far as of 2022.
Anyone can confirm this by browsing inc folder in https://github.com/libffi/libffi
So, if you are seeing this issue in Ubuntu 22, please feel free to create a symbolic link to highest version of so available in your distro.
The problem with libffi can also be tackled with making a symlink:
sudo ln -s /usr/path/to/libffi.so.8 /usr/lib/path/to/libffi.so.7
Then you get another error in xorg log concerning wayland. What helped me was to reinstall wayland and lib32-wayland. After that I could boot normally (although I use xorg in Cinnamon, but also have Gnome installed)

How to install pip packages in Anaconda?

I am trying to install pip packages inside Anaconda without success.
This is what I have tried
1) installation of pip in Anaconda in the base environment
(base) root#eris:/# conda install pip
2) installation of a package, e.g. nano, using pip
(base) root#eris:/# pip install nano
Unfortunately, when I call nano an error message says that nano command was not found.
When I run "conda list", in one output line I get
nano 0.10.0 pypi_0 pypi
This is what I get when I run "which -a pip"
/root/anaconda3/bin/pip
and this is what I get when I run "which -a python"
/root/anaconda3/bin/python
Simon
conda activate environt_name followed by pip install package_name should work and install the package in that specific environment (but only do it for packages that are not in a conda repository and use conda install otherwise).
Unfortunately, when I call nano an error message says that nano command was not found.
Beware that pip install nano will install the nano library from Pypi. From the output of conda list it seems that the library was installed. I have never used this library, but from its description in Pypi it is related to django and it does not seem to come with an executable. Don't confuse it with the nano text editor that comes with most linux distributions (the nano text editor needs to be installed using your distro package manager).

Downgrading Python version on Ubuntu

Can someone please tell me how to downgrade Python 3.6.9 to 3.6.6 on Ubuntu ? I tried the below commands but didnot work
1) pip install python3.6==3.6.6
2) pip install python3.6.6
First, verify that 3.6.6 is available:
apt-cache policy python3.6
If available:
apt-get install python3.6=3.6.6
If not available, you'll need to find a repo which has the version you desire and add it to your apt sources list, update, and install:
echo "<repo url>" >> /etc/apt/sources.list.d/python.list
apt-get update
apt-get install python3.6=3.6.6
I advise against downgrading your system python unless you're certain it's required. For running your application, install python3.6.6 alongside your system python, and better yet, build a virtual environment from 3.6.6:
apt-get install virtualenv
virtualenv -p <path to python3.6.6> <venv name>
One option is to use Anaconda, which allows you to easily use different Python versions on the same computer. Here are the installation instructions for Anaconda on Linux. Then create a Conda environment by running this command:
conda create --name myenv python=3.6.6
Obviously your can use a different name than "myenv". You can then activate the environment in any terminal window:
conda activate myenv
Then you can pip install any packages you want. Some basics of anaconda environments can be found on the website's getting started page.

How to install COCO PythonAPI in python3

It seems the COCO PythonAPI only support python2. But peoples do use it in python3 environment.
I tried possible methods to install it, like
python3 setup.py build_ext --inplace
python3 setup.py install
But python3 setup.py install will fail due to coco.py and cocoeval.py containning python2 print function.
Update: solved by updating the COCO PythonAPI project. Leave this question for people facing the same issue.
Try the following steps:
Use git clone to clone the folder into your drive. In this case, it should be git clone https://github.com/cocodataset/cocoapi.git
Use terminal to enter the directory, or open a terminal inside the directory
Type in 2to3 . -w. Note that you might have to install a package to get 2to3. It is an elegant tool to convert code from Python2 to Python3; this code converts all .py files from Python2-compatible to Python3-compatible
Use terminal to navigate to the setup folder
Type in python3 setup.py install
This should help you install COCO or any package intended for Python2, and run the package using Python3. Cheers!
I have completed it with a simple step
pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"
** before that you need to install Visual C++ 2015 build tools on your path
Install
Instead of the official version (which has issues with python 3) use an alternative one. Install it on your local machine, globally (i.e., outside any virtual environment). You can do this by:
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
Check if it is installed globally:
pip freeze | grep "pycocotools"
You should see something like pycocotools==2.0.0 in your output.
Now, inside your virtual-env (conda or whatever), first install numpy and cython (and maybe setuptools if it's not installed) using pip, and then:
pip install pycocotools
Verify
Inside your project, import (for example) from pycocotools import mask as mask and then print(mask.__author__). This should print out the author's name, which is tsungyi.
Where Is It?
The installed package, like any other packages that are locally installed inside a virtual-env using pip, will go to External Libraries of your project, under site-packages. That means it is now part of your virtual-env and not part of your project. So, other users who may want to use your code, must repeat this installation on their virtual-env as well.
Troubleshooting:
The main source of confusion is that either you did not install the required packages before installing cocoapi, or you did install the required packages but for a different python version. And when you want to check if something is installed, you may check with, for instance, python3.6 and see that it exists, but you are actually running all your commands with python3.7. So suppose you are using python3.7. You need to make sure that:
python -V gives you python3.7 and NOT other version, and pip -V gives you pip 19.2.3 from /home/<USER>/.local/lib/python3.7/site-packages/pip (python3.7), that actually matches with your default python version. If this is not the case, you can change your default python using sudo update-alternatives --config python, and following the one-step instruction.
All the required packages are installed using the right python or pip version. You can check this using pip and pip3 to stop any differences that may cause an issue:
pip freeze | grep "<SUBSTRING-NAME-OF-PACKAGE>" or pip show <PACKAGE-NAME> for more recent versions of pip.
To install the required packages, after you made sure about (1), you need to run:
sudo apt install python-setuptools python3.7-dev python3-wheel build-essential and pip install numpy cython matplotlib
Environment:
The above steps were tested on Ubuntu 18.4, python 3.6.8, pip 19.0.3.
If you are struggling building pycocotools on Ubuntu 20.04 and python3.7
try this:
sudo apt-get install -y python3.7-dev
python3.7 -m pip install pycocotools>=2.0.1
There are alternative versions of the cocoapi that you can download and use too (I'm using python 3.5). Here's a solution that you might want to try out: How to download and use object detection datasets (e.g. coco or pascal)
here's how i did successfully! (the reason is the gcc version)
install the dependencies: cython (pip install cython), opencv (pip install opencv-python)
check the gcc version by this command: gcc --version
your output will be like this 'Command 'gcc' not found, but can be installed with:
sudo apt install gcc
'
Type the below commands to install the gcc:
sudo apt update
sudo apt install build-essential
sudo apt-get install manpages-dev
now check again the gcc version(step2)
if you get below output
'gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.'
now run the code for pycocotools installations:
pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"
finally wait check if the installation is successful :
'Successfully installed pycocotools-2.0'

Persistent issues with installation of OpenAI gym

I am running Ubuntu 16.04 and am having trouble doing a full installation of "gym". What I did:
Installed Anaconda 4.2.0 (the version that comes with Python 3.5)
Installed dependencies with sudo apt-get install -y python-numpy python-dev cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev python-opengl libboost-all-dev libsdl2-dev swig
Cloned gym repository with "git clone https://github.com/openai/gym.git"
Installed gym with cd gym and then pip install -e '.[all]'
I get no errors throughout this process. Then I open the Spyder ide and run:
import gym
env = gym.make("CartPole-v0")
And it works fine. However, when I run
import gym
env = gym.make("LunarLander-v2")
I get the error:
/path/anaconda3/lib/python3.5/site-packages/Box2D/_Box2D.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_appendEPKcm
I also get errors when I try to access other box2d and atari environments.
It is also worth noting that I tried doing all of this on another virtual machine on which I installed the Python 2.7 version of Anaconda, and I got the same message...so this does not seem to have anything to do with the version of python I am using.
I had the same issue on Ubuntu 16.04.
Try to install gcc (GCC) 4.8.5 in your conda environment with conda install -c anaconda gcc=4.8.5. This fixed it for me. See also https://anaconda.org/anaconda/gcc .
I had the same issue with my default gcc
$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4)
Hope that helps!
If you installed conda environment, use conda in your channel.
$ conda install -c https://conda.anaconda.org/kne pybox2d
Box2d will be added under python3.5/site-packages, and try code again.
import gym
env = gym.make("LunarLander-v2")
Good luck.

Categories

Resources