-
-
Notifications
You must be signed in to change notification settings - Fork 954
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
[Proposal] Can the dependency box2d-py==2.3.8
be replaced with Box2D==2.3.10
, which will simplify the installation?
#1324
Comments
THANK YOU SOOO MUCH! Thats the solution! Finally! Im using gym on windows and none of the existing issues did work. (#1009, #1127, #1292, #1300, #1309) So what are the exact steps for my applied hacky workaround, based on @moretouch ? (Im using Win11 with Python 3.12)
|
I have provided a script to facilitate the installation of this library. Copy and save it in an empty folder, then run it. @Wasserwecken import hashlib
import os
import shutil
import subprocess
import tarfile
def main():
# 1. Use pip to download the gymnasium library
print("Downloading gymnasium-1.1.0.tar.gz...")
subprocess.run(
["pip", "download", "gymnasium==1.1.0", "--no-binary", ":all:", "--no-deps", "-d", "."],
check=True
)
# 2. Verify the SHA256 hash
print("Checking file SHA256...")
def compute_sha256(filename):
sha256 = hashlib.sha256()
with open(filename, "rb") as f:
while chunk := f.read(4096):
sha256.update(chunk)
return sha256.hexdigest()
# this hex from https://pypi.org/project/gymnasium/#gymnasium-1.1.0.tar.gz
expected_hash = "dedb5c8c83047d3927ef8b841fb4ebadaeaa43ab954e2e3aca7eadcf4226c5f2"
actual_hash = compute_sha256("gymnasium-1.1.0.tar.gz")
if actual_hash != expected_hash:
raise ValueError(f"Hash verification failed! Expected: {expected_hash}, Actual: {actual_hash}")
# 3. Extract to the gymnasium folder
print("Extracting file...")
with tarfile.open("gymnasium-1.1.0.tar.gz", "r:gz") as tar:
# Create the target directory
os.makedirs("gymnasium", exist_ok=True)
# Process the archive members' paths
members = []
for member in tar.getmembers():
if member.name.startswith("gymnasium-1.1.0/"):
# Remove the top-level directory structure
member.name = member.name[len("gymnasium-1.1.0/"):]
members.append(member)
# Extract files
tar.extractall(path="gymnasium", members=members)
# 4. Modify the pyproject.toml file
print("Modifying dependencies...")
toml_path = os.path.join("gymnasium", "pyproject.toml")
with open(toml_path, "r") as f:
content = f.read()
# Use regular expressions to match different version declarations
new_content = content.replace('box2d-py ==2.3.5', 'Box2D ==2.3.10')
with open(toml_path, "w") as f:
f.write(new_content)
# 5. Repackage as a new tar.gz file
print("Repacking file...")
with tarfile.open("gymnasium-1.1.0.tar.gz", "w:gz") as tar:
# Add the modified content, preserving the original directory structure
tar.add("gymnasium", arcname="gymnasium-1.1.0")
print("The new file has been saved as gymnasium-1.1.0.tar.gz")
# Remove the directory
shutil.rmtree("gymnasium")
_type = input('Please input the content to install: [box2d / all] > ')
if _type:
subprocess.run(['pip', 'install', './gymnasium-1.1.0.tar.gz[' + _type.strip() + ']'])
else:
subprocess.run(['pip', 'install', './gymnasium-1.1.0.tar.gz[all]'])
os.unlink("gymnasium-1.1.0.tar.gz")
if __name__ == "__main__":
main() |
I would be interested in investigating this; however, it is not as simple as it appears.
To make the change, we would need to confirm that there is no impact for agents using |
Proposal
replace dependency
box2d-py==2.3.8
toBox2D==2.3.10
, will simplify the installation.hoping that more professional and trustworthy community members can test its function and check its security.
Motivation
During the process of learning gym, I am always blocked by the dependency
box2d-py
every time I install it. The official has stopped maintaining this project, and there are very few built distributions in the official pypi repository. There are a large number of similar installation errors in issues and on the internet. A c++ compilation environment is required to install thebox2d-py
dependency normally, which is actually unnecessary.The community provides the Box2D package (https://pypi.org/project/Box2D/). I downloaded the project code, changed the dependency configuration in
pyproject.toml
toBox2D ==2.3.10
, and made no other changes. Installation was very easy, and there were no issues with initial use. This should reduce the difficulty for many beginners.This may require more testing. I'm not very sure about the security of the
Box2D
package. I'm just making a suggestion, hoping that more professional and trustworthy community members can test its function and check its security.Pitch
Alternatives
No response
Additional context
No response
Checklist
The text was updated successfully, but these errors were encountered: