Install pybox2d for python 3.6 with conda 4.3.21 - python-3.x

i want to play with the lunar lander env from OpenAI gym.
In order to run this code I need to install Box2d, this is where my problems arise.
I am using ubuntu 16.04 with conda 4.3.21 and python 3.6.
When I tried to run the environment I received the error: ModuleNotFoundError: No module named '_Box2D'
So I tried the direct install of pybox2d:
https://github.com/pybox2d/pybox2d/blob/master/INSTALL.md
which yielded the same error message.
Then I tried to install from GitHub following the way outlined in https://github.com/cbfinn/gps/issues/34
$git clone https://github.com/pybox2d/pybox2d pybox2d_dev
$cd pybox2d_dev
$python setup.py build
$sudo python setup.py install
If I run this (in root environment which has python 3 or another new created environment with python 3) i get the result:
a lot of processing logs
Processing Box2D-2.3.2-py2.7-linux-x86_64.egg
creating /usr/local/lib/python2.7/dist-packages/Box2D-2.3.2-py2.7-linux-x86_64.egg
Extracting Box2D-2.3.2-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/dist-packages
Adding Box2D 2.3.2 to easy-install.pth file
Installed /usr/local/lib/python2.7/dist-packages/Box2D-2.3.2-py2.7-linux-x86_64.egg
Processing dependencies for Box2D==2.3.2
Finished processing dependencies for Box2D==2.3.2
So pybox2d is installed into the lib of the standard python 2 of ubuntu despite being in a python 3 conda environment.
So, I am looking for ways to install the pybox2d package for python 3 with conda 4.3.21

Installing Box2D from pip led me to the error described here when I tried to import it. Here's what worked for me on Python 3.6, as suggested in that GitHub issue:
conda install swig # needed to build Box2D in the pip install
pip install box2d-py # a repackaged version of pybox2d

Hey this question looks quite old but it seems no one really put the right answer in any where so just write this.
Follow the below two lines on your linux command:
$ sudo apt-get install build-essential python-dev swig python-pygame
$ pip install Box2D
---------Below is unnecessary details --------
Many wants to run Box2D based gym but it is sth you have to install by yourself like Mujoco series gym envs.
Many uses python 3.6 but the easiest way of installing Box2D, which is
$ conda install -c kne pybox2d
doesn't work cuz pybox2d has been maintained til py3.5
But directly doing
$ pip install Box2D
does not solve the issue. The error comes from swig given its error msg, but it's actually not.
$ sudo apt-get install build-essential python-dev swig python-pygame
This line always solve everything in one go.
I have been doing research based on Box2D envs but still foget this everytime I install this in a new env, so this is for me as well lol
Contribute: https://github.com/jonasschneider/box2d-py/blob/master/INSTALL.md
Btw, do not forget to double-check whether it is properly install.
In linux command
$ python --version
python 3.6. sthsth
$ python
>>> import numpy as np
>>> import gym
>>> env = gym.make('BipedalWalker-v2')
# If it does not give you error, then it's done!

You need to activate your environment:
source activate my_env_name
Then prompt changes to:
(my_env_name)
Now, install with pip and without sudo:
pip install pybox2d

sudo apt-get install swig
pip install pybox2d

Installing this way worked for me (also in a virtual env):
pip install box2d-py==2.3.8
I am running gym v 0.17.3.

Related

Error installing psycopg2 on macOS with building wheel [duplicate]

I'm attempting to make a website with a few others for the first time, and have run into a weird error when trying to use Django/Python/VirtualEnv. I've found solutions to this problem for other operating systems, such as Ubuntu, but can't find any good solutions for Mac.
This is the relevant code being run:
virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
After running that block, I get the following errors:
AssertionError
Failed building wheel for django-toolbelt
Running setup.py bdist_wheel for psycopg2
...
AssertionError
Failed building wheel for psycopg2
Failed to build django-toolbelt psycopg2
I believe I've installed the "django-toolbelt" and "psycopg2", so I'm not sure why it would be failing.
The only difference I can think of is that I did not use the command
sudo apt-get install libpq-dev
as was instructed for Ubuntu usage as I believe that installing postgresql with brew took care of the header.
Thanks for any help or insight!
For MacOS users
After trying all the above methods (which did not work for me on MacOS 10.14), that one worked :
Install openssl with brew install openssl if you don't have it already.
add openssl path to LIBRARY_PATH :
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
install psycopg2 with pip pip3 install psycopg2
I had the same problem on Arch linux. I think that it's not an OS dependant problem. Anyway, I fixed this by finding the outdated packages and updating then.
pip uninstall psycopg2
pip list --outdated
pip install --upgrade wheel
pip install --upgrade setuptools
pip install psycopg2
I was also getting same error.
Using Python 3.7.3 and pip 19.1.1.
I used following command.
pip install psycopg2-binary==2.8.3
TDLR
If you aren't used to installing Python C-extensions, and psycopg2 isn't a core part of your work, try
pip install psycopg2-binary
Building Locally
psycopg2 is a C-extension, so it requires compilation when being installed by pip. The Build Prerequisites section of the docs explain what must be done to make installation via pip possible. In summary (for psycopg 2.8.5):
a C compiler must be installed on the machine
the Python header files must be installed
the libpq header files must be installed
the pg_config program must be installed (it usually comes with the libpq headers) and on $PATH.
With these prerequisites satisfied, pip install psycopg2 ought to succeed.
Installing pre-compiled wheels
Alternatively, pip can install pre-compiled binaries so that compilation (and the associated setup) is not required. They can be installed like this:
pip install psycopg2-binary
The docs note that
The psycopg2-binary package is meant for beginners to start playing with Python and PostgreSQL without the need to meet the build requirements.
but I would suggest that psycopg2-binary is often good enough for local development work if you are not using psycopg2 directly, but just as a dependency.
Concluding advice
Read the informative installation documentation, not only to overcome installation issues but also to understand the impact of using the pre-compiled binaries in some scenarios.
I had same problem and this appears to be a Mojave Issue, I was able to resolve with:
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
For Mac OS X users:
1. First check your postgresql path by running this command in terminal:
pg_config
If this fails lookup how to add pg_config to your path.
2. Next install Xcode Tools by running this command in terminal:
xcode-select --install
If you have both those sorted out now try to install psycopg2 again
For MacOS users, this question has the correct solution:
install command line tools if necessary:
xcode-select --install
then
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2
I was also facing the same after running all the above commands, but the following two commands worked for me:
Instead of pip, use this:
sudo apt-get install libpq-dev
then run this command:
pip install psycopg2
On OS X, I was able to solve this by simply upgrading wheel before installing psycopg2:
pip install --upgrade wheel
For OSX Sierra users, it seems that an xcode update is the solution: Can't install psycopg2 package through pip install... Is this because of Sierra?
I tried all the above solutions but they did not work for me. What I did was change the psycopg2 version in my requirements.txt file from psycopg2==2.7.4 to psycopg2==2.7.6
Is your error message complete? the most encountered reason for failing to install psycopg2 on mac from pip is pg_config is not in path.
by the way, using macports or fink to install psycopg2 is more recommended way, so you don't have to worry about pg_config, libpq-dev and python-dev.
plus, are using Python 3.5? then upgrage your wheel to > 0.25.0 using pip.
I faced the same issue, but the answers above didn't work for me.
So this is what I did in my requirements.txt
psycopg2-binary==2.7.6.1 and it worked fine
I had this issue on several packages, including psycopg2, numpy, and pandas. I simply removed the version from the requirements.txt file, and it worked.
So instead of psycopg2-binary==2.7.6.1 I just had psycopg2-binary.
I know you are asking for development environment but if you are deploying on server say, Heroku. Just add below line in the requirements.txt of your project.
django-heroku==0.3.1
As this package itself will install the required packages like psycopg2 on server deployment.So let the server(heroku) should take care of it.
sudo apt install libpq-dev python3.X-dev
where X is the sub version,
these should be followed by :
pip install --upgrade wheel
pip install --upgrade setuptools
pip install psycopg2
Enjoy !!!
I solved my problem by updating/installing vs_BuildTools. The link to the software was given in the error itself.
Error Image
Fixed by installing python3.7-dev: sudo apt install python3.7-dev, based on the link.
Python: 3.7
Ubuntu: 20.04.3 LTS

Pip install on Mac OS gets error: command '/usr/bin/clang' failed with exit code 1

I want to install google-cloud-pubsub via pip installation on Mac OS but I get an error: distutils.errors.CompileError: command '/usr/bin/clang' failed with exit code 1. The command I run: pip install google-cloud-pubsub==2.1.0.
Here the complete error message.
Any suggestion? Thank you!
More info:
$ python -V
Python 3.9.0
$ pip -V
pip 20.2.4 from /.../lib/python3.9/site-packages/pip (python 3.9)
$ sw_vers
ProductName: macOS
ProductVersion: 11.0.1
BuildVersion: 20B29
I've seen other similar cases but them don't solve my issue. I tried:
Pip install error in Mac OS(error: command '/usr/bin/clang' failed with exit status 1)
Mac OS Mojave installation error - error: command 'clang' failed with exit status 1
Try to add these env var before
GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=true GRPC_PYTHON_BUILD_SYSTEM_ZLIB=true pip install google-cloud-pubsub==2.1.0
If it does not work you can try with virtualenv:
pip install virtualenv
virtualenv my-test-env
source my-test-env/bin/activate
my-test-env/bin/pip install google-cloud-pubsub==2.1.0
Because is written on github:
Install this library in a virtualenv using pip. virtualenv is a tool to create isolated Python environments. The basic problem it addresses is one of dependencies and versions, and indirectly permissions.
With virtualenv, it's possible to install this library without needing system install permissions, and without clashing with the installed system dependencies.
I was using pyenv and facing the similar kind of issue. Then I did the following and it worked.
First, upgrade pip
pip3 install --upgrade pip
Then, update the setup tools:
python3 -m pip install --upgrade setuptools
I just had this same problem but I'm using homebrew to manage my Mac packages.
My error result was the same as yours but within the error message it was:
plyvel/_plyvel.cpp:632:10: fatal error: 'leveldb/db.h' file not found
#include "leveldb/db.h"
This can be fixed using homebrew by just installing leveldb:
brew install leveldb
This allowed the plyvel dependency to be satisified. I then manually installed plyvel just to be safe:
pip3 install plyvel
And lastly because I'm trying to install the airflow libraries that include pubsub:
pip3 install apache-airflow-providers-google
I ended up just using Python 3.8.13 instead, managed with pyenv and pyenv-virtualenv.
If you don't have pyenv:
brew install pyenv pyenv-virtualenv
add
export PATH="$HOME/.pyenv/bin:$PATH"
export PATH="$HOME/.pyenv/shims:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
to your ~/.zshrc if it's not there, and source ~/.zshrc
pyenv install 3.8.13
pyenv global 3.8.13
pyenv virtualenv 3.8.13 venv
pyenv activate venv
pip install grcpio
Are you attempting to compile on a new M1 processor? I ran into trouble installing the latest grpcio (1.34.0) too, with the same error message as you.
Without messing with compile flags and libraries, I found the best solution for me (setting up a new Flask environment to talk to Google Cloud on a new Big Sur Mac) was the tip offered here:
https://osxdaily.com/2020/11/18/how-run-homebrew-x86-terminal-apple-silicon-mac/
Duplicate your Terminal rename it to "Rosetta Terminal" or similar
Get Info on the new app, and check the box for "Open using Rosetta"
Do your work with this new terminal app instead
grpcio installed fine for me this way, and I don't anticipate any problems running my Web apps in this translated environment (until I presume this issue gets fixed in the source libraries).
I encountered a similarly-named clang issue when attempting to awsiotsdk on an M1 Mac with Python 3.8
Incase it's relevant to anyone reading this, the underlying issue was a dependency on awscrt. This particular library (on PyPi) did not contain Built Distributions for the combination of M1 ("xxx_universal2.whl") and Python 3.8.
The solution was to use pyenv with pipenv (a favourite pattern of mine) to force this project to use a supported combination (in our case: Python 3.9 with M1 )
if you are using Mac M1 chip, just do the below thing it worked for me.
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1
Thanks for the below answer.
How can I install GRPCIO on an Apple M1 Silicon laptop?
Working solution in my case (Mac M1 Monterey OS):
brew install openssl re2
LDFLAGS="-L$(/opt/homebrew/bin/brew --prefix openssl)/lib -L$(/opt/homebrew/bin/brew --prefix re2)/lib" CPPFLAGS="-I$(/opt/homebrew/bin/brew --prefix openssl)/include -I$(/opt/homebrew/bin/brew --prefix re2)/include" GRPC_BUILD_WITH_BORING_SSL_ASM="" GRPC_PYTHON_BUILD_SYSTEM_RE2=true GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=true GRPC_PYTHON_BUILD_SYSTEM_ZLIB=true pip install grpcio
Credits to https://github.com/grpc/grpc/issues/24677#issuecomment-862413344
I started having that issue. Following this comment,
with pyenv, I uninstalled my python 3.9.12 and reinstalled it again.
I am having an M1 and macOS 12.6, btw.
Deactivate your current virtualenv first, then:
pyenv uninstall 3.9.12
pyenv install 3.9.12
pyenv local 3.9.12 # to set your local python version to the newly installed python
poetry shell
pip install grpcio # or poetry install grpcio

Docker python unable to import module installed via apt-get

I'm trying to build a python app via docker, but it fails to import numpy even though I've installed the appropriate package via apt. As an example of the dockerfile reduced to only what's important here:
FROM python:3
RUN apt-get update \
&& apt-get install python3-numpy -y
RUN python3 -c "import numpy; print(numpy.__version__)"
Attempting to build that dockerfile results in the error ModuleNotFoundError: No module named 'numpy'.
I am able to get this working if I use pip to install numpy, but I was hoping to get it working with the apt-get package instead. Why isn't this working the way I would expect it to?
The problem is that you have two Pythons installed:
The image comes with python in /usr/local/bin.
When you install python3-numpy, that install python3 package from Debian, which ends up with /usr/bin/python.
When you run your code at the end you're likely using the version from /usr/local/bin, but NumPy was installed for the version in /usr/bin.
Solution: Install NumPy using pip, e.g. pip install numpy, instead of using apt.
Long version, with other ways you can get import errors: https://pythonspeed.com/articles/importerror-docker/
The problem is with python environments, not with docker. The apt-get installed numpy is not in the same environment as the python installation. Moreover, the dependencies should be stored in a requirements.txt file, which should then be installed through pip. python -m pip can be used to ensure that the pip command is in the same environment as the python installation.

installing Mayavi with pip - no module named 'vtkOpenGLKitPython'

I am trying to install mayavi via pip on my ubuntu 16.04 via shell. I am using python 3.6 via anaconda and already installed vtk and all other requirements but i get the above error when i try pip3 install mayavi or pip2 install mayavi.
Mayavi is packaged for ubuntu packages.ubuntu.com/xenial/mayavi2.
I suggest that you install with the command
sudo apt-get install mayavi2
instead, this will take care of installing a version that matches the vtk install on your system.
Try to rename libvtkOpenGLKitPython*.so file.
In my case it was:
cd /opt/conda/envs/pytorch-py3.6/lib/python3.6/site-packages/vtk
cp libvtkOpenGLKitPython36D-8.1.so libvtkOpenGLKitPython.so
and, maybe one more error with libxt6 file. Fix it:
apt install libxt6

How to install library

I am a little bit confused....
I installed anaconda on my computer (I have windows 10).
Normally, when I want to install a package I simply do "pip install package_name" or "conda install package_name" and it is done.
First question: what is the difference between pip and conda?
Now I tried to install xgboost and it was really complicated I tried lot of things nothings worked until I install something called miniconda.
There it works but now, when I do "conda install package_name" it install it in miniconda3/lib/site _package and I have to copy/paste it in Anaconda3/lib/site_package if I want it to work.
Second question: how can I ask to the computer that "conda install
package_name" install it directly in anaconda3 and not miniconda3?
Finally I tried to install the package "surprise" for recommended systems. Both "pip install" or "conda install" failed.
I went in github and got the file "surprise" from https://github.com/NicolasHug/Surprise
I tried to copy it in Anaconda3/lib/site_package but it doesn't work.
When I do from surprise import Reader I did not get the error "no module name surprise" anymore but I get "cannot import name 'Reader'"
Last question: how can I make it work? I think I have to build it but
I do not now how...
Thank you in advance for anyone that can explain all this for me :-)
Similarly to you, I had issues installing the surprise package.
I tried both pip install surprise and conda install surprise unsuccessfully.
conda install -c conda-forge scikit-surprise
conda install -c conda-forge/label/gcc7 scikit-surprise
conda install -c conda-forge/label/cf201901 scikit-surprise
I found those on the anconda website and the first one worked for me.
Hopefully this would help you as well
pip vs conda
pip is a package manager that facilitates installation, upgrade,
and uninstallation of python packages. It also works with virtual python environments.
conda is a package manager for any software (installation, upgrade and uninstallation).
It also works with virtual system environments.
Conda is a packaging tool and installr that aims to do more than what pip does;
handle library dependencies outside of the Python packages as well as the Python packages themselves.
Conda also creates a virtual environment, like virtualenv does.
For more see here
Anaconda vs miniconda
The open source version of Anaconda is an easy-to-install
high performance Python and R distribution with a package manager,
environment manager and collection of 720+ open source packages.
It also comes with the options to install RStudio.
The "lite" version of Anaconda without the collection of 720 packages.
The downside is that you need to type in command line commands,
"conda install PACKAGENAME"
And Last
To install this package with conda run:
conda install -c anaconda py-xgboost=0.60
Update for surprise
The easiest way is to use pip (you'll need numpy):
$ pip install numpy
$ pip install scikit-surprise
Or you can clone the repo and build the source (you'll need Cython and numpy):
$ git clone https://github.com/NicolasHug/surprise.git
$ python setup.py install

Resources