Skip to main content
 首页 » 编程设计

python之运行健身房时,健全性检查返回 numpy __version__ 的属性错误

2024年10月01日7shanyou

我正在尝试让开放式 AI 健身房正常工作,但我遇到了一个非常持续的错误。
当我运行我的程序(只是简单的演示 cartpole 求解器)时,出现此错误。 (文件“gperm.py”是cartpole求解器)

File "gperm.py", line 1, in <module> 
import gym 
File "/Users/sonyaferraro/Desktop/dpy/gym/__init__.py", line 48, in <module> 
sanity_check_dependencies() 
File "/Users/sonyaferraro/Desktop/dpy/gym/__init__.py", line 20, in sanity_check_dependencies 
if distutils.version.LooseVersion(numpy.__version__) < distutils.version.LooseVersion('1.10.4'): 

最后打印:

AttributeError: module 'numpy' has no attribute '__version__' 

这很奇怪,因为我对 numpy 进行了完整的 pip 安装,甚至尝试 git clone 它都没有用。我已经检查以确保我没有其他名为 numpy 的文件,并且一切似乎都在检查中。

如果其他人遇到同样的问题或者有人有解决方案,我们将不胜感激。

它还会打印一个“提示”提示我尝试:pip install -U numpy。

    logger.warn("You have 'numpy' version %s installed, but 'gym' requires at least 1.10.4. HINT: upgrade via 'pip install -U numpy'.", numpy.__version__) 

我确实有一个版本的 numpy>= 1.10.4,所以应该不会弹出,对吗?(不记得确切的版本)

然而,使用 pip install -U numpy 会返回“SNIMissingWarning”、“InsequrePlatformWarning”和以下内容:

The directory '/Users/sonyaferraro/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. 
The directory '/Users/sonyaferraro/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. 

老实说,我不知道这是要我做什么,因为我确实拥有这些目录的权限。

请您参考如下方法:

根据您的终端输出,我认为您使用的是 MacOS 和 brew。

brew link --overwrite numpy 似乎已经为我解决了这个问题。