poldracklab / pydeface

defacing utility for MRI images
MIT License
110 stars 42 forks source link

AttributeError: 'module' object has no attribute 'which' #32

Closed logophilus7 closed 11 months ago

logophilus7 commented 5 years ago

I installed pydeface on my CentOS 7.6, and my python version is 2.7.5 I got the following message when running pydeface on my data

Traceback (most recent call last):
  File "/usr/bin/pydeface", line 11, in <module>
    load_entry_point('pydeface==2.0', 'console_scripts', 'pydeface')()
  File "build/bdist.linux-x86_64/egg/pydeface/__main__.py", line 116, in main
  File "build/bdist.linux-x86_64/egg/pydeface/utils.py", line 83, in deface_image
AttributeError: 'module' object has no attribute 'which'

I heard that 'module' object has 'which' after 3.3 version of python. But I do not think pydeface is orginally developed for python3, and only work on python3 ? Any one could help me ?

vsoch commented 5 years ago

Yes, which is available in Python 3, and further, Python 2 is nearing end of life. You need to use Python 3.

shiranoren commented 4 years ago

Hello, I got this error too. I tried with python 3.8 and 3.7.5 Any suggestions on how to solve it?

This is the output:

------------
pydeface 2.0
------------
Traceback (most recent call last):
  File "/usr/local/bin/pydeface", line 11, in <module>
    load_entry_point('pydeface==2.0', 'console_scripts', 'pydeface')()
  File "build/bdist.macosx-10.14-intel/egg/pydeface/__main__.py", line 116, in main
  File "build/bdist.macosx-10.14-intel/egg/pydeface/utils.py", line 83, in deface_image
AttributeError: 'module' object has no attribute 'which'

Many thanks in advance :)

vsoch commented 4 years ago

I think you probably need to double check on the Python version - I can run both 3.8 and 3.7.5 in isolated environments (Docker) and show that the function does exist:

First here is Python 3.8

$ docker run -it python:3.8
Python 3.8.0 (default, Oct 17 2019, 05:36:36) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.which('ls')
'/bin/ls'

And Python 3.7.5

$ docker run -it python:3.7.5
Python 3.7.5 (default, Oct 19 2019, 00:03:48) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.which('ls')
'/bin/ls'

I think it's very likely that you are not using the version you think you are, or you are grabbing older versions on your python path. Take a look at:

shutil.__file__
'/usr/local/lib/python3.7/shutil.py'

to confirm where it's coming from.

ofgulban commented 4 years ago

Hi @shiranoren , I know that @logophilus7 solved this issue by installing pydeface from my old fork here: https://github.com/ofgulban/pydeface

Maybe you can try doing the same.