文章目录
- 一、No module named 'torch._six'
- 二、Cython.Compiler.Errors.CompileError
- 三、Could not find a version that satisfies the requirement tensorflow<2.0,>=1.8.0
- 四、A NumPy version >=1.19.5 and <1.27.0 is required for this version of SciPy (detected version 1.17.4)
- 五、module 'tensorflow._api.v2.train' has no attribute 'AdamOptimizer'
本博客用于记录使用conda的环境报错及处理方法。
一、No module named ‘torch._six’
自己的报错如下:No module named 'torch._six'
2. 报错原因
在看了许多解决办法之后发现,在pytorch1.8版本之后 container_abcs 就已经被移除。所以导入方式不同会出现此错误:No module named ‘torch._six’
因此使用不同版本的torch会出现不同问题:
- 1.8以下版本使用
from torch._six import container_abcs
; - 1.8以上版本使用
import collections.abc as container_abcs
;
3. 解决方法
找到报错文件,将from torch._six import container_abcs
注释,然后改成import collections.abc as container_abcs
即可。
如何确认 pytorch版本:
# 方法1: conda list # 方法2: import torch torch.__version__
二、Cython.Compiler.Errors.CompileError
1. 问题描述
在配置 mujoco210 环境执行python3 mujoco_py_test.py
,出现如下错误:
Compiling /home/gene/anaconda3/envs/mujoco_env/lib/python3.8/site-packages/mujoco_py/cymj.pyx because it changed.
[1/1] Cythonizing /home/gene/anaconda3/envs/mujoco_env/lib/python3.8/site-packages/mujoco_py/cymj.pyx
performance hint: /home/gene/anaconda3/envs/mujoco_env/lib/python3.8/site-packages/mujoco_py/cymj.pyx:67:0: Exception check on 'c_warning_callback' will always require the GIL to be acquired.
Possible solutions:
1. Declare 'c_warning_callback' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
2. Use an 'int' return type on 'c_warning_callback' to allow an error code to be returned.
performance hint: /home/gene/anaconda3/envs/mujoco_env/lib/python3.8/site-packages/mujoco_py/cymj.pyx:104:0: Exception check on 'c_error_callback' will always require the GIL to be acquired.
Possible solutions:
1. Declare 'c_error_callback' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
2. Use an 'int' return type on 'c_error_callback' to allow an error code to be returned.
Error compiling Cython file:
...
cythonize_one(*args)
File "/home/gene/anaconda3/envs/mujoco_env/lib/python3.8/site-packages/Cython/Build/Dependencies.py", line 1298, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: /home/gene/anaconda3/envs/mujoco_env/lib/python3.8/site-packages/mujoco_py/cymj.pyx
2. 报错原因
查看待执行模块的
requirements.txt
里对Cython版本版本要求如上图Cython>=0.27.2
,而当前环境 Cython版本如下,可知版本差异太大,需要降版本。
cython -V
Cython version 3.1.2
3. 解决方法
切换 更换低的近似Cython版本:
#网上 pip install Cython==3.0.0a10 自己使用此命令会报错
pip install cython==0.29.37
三、Could not find a version that satisfies the requirement tensorflow<2.0,>=1.8.0
1. 问题描述
进行 pip安装遇到Could not find a version that satisfies the requirement tensorflow<2.0,>=1.8.0
2. 报错原因
可能与网络原因有关。
3. 解决方法
指定源下载:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow
四、A NumPy version >=1.19.5 and <1.27.0 is required for this version of SciPy (detected version 1.17.4)
1. 问题描述
SciPy 要求 NumPy 版本 >=1.19.5 且 <1.27.0,但当前检测到的是 1.17.4(过低)
2. 解决方法
升级满足要求版本
# --user 将包安装到当前用户的本地目录(而非系统全局)
pip3 install --upgrade "numpy>=1.19.5,<1.27.0" --user
五、module ‘tensorflow._api.v2.train’ has no attribute ‘AdamOptimizer’
1. 问题描述
在测试spinup
库时出现如下错误:
2. 报错原因
原因:版本问题
3. 解决方法
根据报错信息提示,打开对应文件路径code */spinningup/spinup/utils/
,修改如下内容
# 1.修改前
class MpiAdamOptimizer(tf.train.AdamOptimizer):
# 1.修改后
class MpiAdamOptimizer(tf.compat.v1.train.AdamOptimizer):
# 2.修改前
tf.train.AdamOptimizer.__init__(self, **kwargs)
# 2.修改前
tf.compat.v1.train.AdamOptimizer.__init__(self, **kwargs)