ImportError:无法导入名称_remove_dead_weakref-运行python script.py时没有错误,从bash shell脚本中运行script.py时错误

时间:2018-06-19 20:05:39

标签: python bash import weak-references

我正在尝试导入需要sklearn的软件包。这在名为script.py的测试脚本中。当我运行python script.py allele_1时,没有收到错误消息。但是,当我在bash shell脚本中包括以下命令时:

#!/bin/bash
allele=($(ls $1 | grep H))
python script.py $allele

我收到以下错误

File "/home/jhuang/miniconda2/lib/python2.7/site- 
packages/mhcnuggets/src/dataset.py", line 12, in <mod                                                                                              
ule>
from sklearn.model_selection import train_test_split
File "/home/jhuang/miniconda2/lib/python2.7/site- 
packages/sklearn/__init__.py", line 20, in <module>
  import logging
File "/home/jhuang/miniconda2/lib/python2.7/logging/__init__.py", line 26, in 
<module>
import sys, os, time, cStringIO, traceback, warnings, weakref, collections
File "/home/jhuang/miniconda2/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref

我见过类似的问题,但没有明确的答案,也没有见过命令行与Shell脚本执行相关的问题。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:2)

此问题可能是您安装了带有自制软件的python2,而该软件与系统python版本冲突。尝试卸载python @ 2自家版本,您应该一切顺利。

brew remove python@2 --ignore-dependencies