conda环境配置(二) —— 报错


本博客用于记录使用conda的环境报错及处理方法。

一、No module named ‘torch._six’

参考链接1参考链接2
1. 问题描述

自己的报错如下: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)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值