简体   繁体   English

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

[英]ImportError: cannot import name _remove_dead_weakref - no error when running python script.py, error when running script.py from bash shell script

I am trying to import a package that requires sklearn. 我正在尝试导入需要sklearn的软件包。 This is in a test script named script.py. 这在名为script.py的测试脚本中。 When I run: python script.py allele_1 , I do not get an error. 当我运行: python script.py allele_1 ,我没有收到错误。 However, when I include this command inside a bash shell script as follows: 但是,当我在bash shell脚本中包括以下命令时:

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

I get the following error 我收到以下错误

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

I've seen similar questions, but have not seen a definitive answer, nor have I seen any question in the context of command line vs shell script execution. 我见过类似的问题,但没有确定的答案,也没有见过命令行与Shell脚本执行相关的问题。 Any help would be greatly appreciated! 任何帮助将不胜感激!

This issue is probably you have installed python2 with homebrew which is conflicting with system python version. 这个问题可能是您安装了带有自制软件的python2,它与系统python版本冲突。 Try uninstalling python@2 homebrew version and you should be good to go. 尝试卸载python @ 2自制版本,您应该一切顺利。

brew remove python@2 --ignore-dependencies

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM