trippy icon indicating copy to clipboard operation
trippy copied to clipboard

imp Module Deprecated for Python v3.12 and Later

Open tseccull opened this issue 8 months ago • 3 comments

Hi Folks,

Hope you're well. I'm getting in touch to let you know about an issue I ran into while trying to install TRIPPy with the latest versions of python. I've created a conda environment called trippy and attempted to install TRIPPy as described in this repo's README (i.e. dependencies installed via conda and TRIPPy installed with pip). On trying to import trippy in python I get the following error.

Python 3.13.3 | packaged by conda-forge | (main, Apr 14 2025, 20:44:03) [GCC 13.3.0] on linux                         
Type "help", "copyright", "credits" or "license" for more information.                                                
>>> import trippy                                                                                                     
Traceback (most recent call last):                                                                                    
  File "<python-input-0>", line 1, in <module>                                                                        
    import trippy                                                                                                     
  File "/home/tom/miniforge3/envs/trippy/lib/python3.13/site-packages/trippy/__init__.py", line 6, in <module>        
    from . import psf,pill,bgFinder                                                                                   
  File "/home/tom/miniforge3/envs/trippy/lib/python3.13/site-packages/trippy/psf.py", line 26, in <module>            
    import imp                                                                                                        
ModuleNotFoundError: No module named 'imp'           

Running conda install imp looks like it does something, but trying to import trippy afterwards will just give me the same error message as above. Running pip install imp gives

(trippy) tom@C1-10P:~$ pip install imp                                                                                
ERROR: Could not find a version that satisfies the requirement imp (from versions: none)                              
ERROR: No matching distribution found for imp  

I searched online to find out what's going on and I found this stack overflow page stating that imp is now deprecated in favour of importlib. I've confirmed that importing imp in python v3.11 gives the deprecation message shown in that post. I thought about forking TRIPPy and updating the imp to importlib in my own copy and submitting a pull request, but I don't know how you'd want to handle this issue for others still running TRIPPy with earlier versions of Python. I've found that TRIPPy does install with python v3.11, but that is the last version that supports imp. Reverting python all the way back to v3.5 as suggested in TRIPPy's README causes other dependency issues for me when imp is installed through conda. Python v3.6 now seems to be the earliest version of python I can use that would also be compatible with imp.

In short, if you're not aware of this you might want to look into it. Running on python v3.11 seems to work ok for now, but you might want to implement a more permanent fix for this in the long run.

Cheers, Tom

tseccull avatar May 01 '25 21:05 tseccull

Hey @tseccull , I'm not running such as new version as you but I did get trippy running on Python 3.9 with a few small changes which are on my fork: https://github.com/talister/trippy (@fraserw I'm happy to send you a PR for these changes if you want/like)

talister avatar Jun 03 '25 19:06 talister

Hang tight gents. Changes incoming in the next few days that will solve this and other issues.

fraserw avatar Jun 03 '25 19:06 fraserw

@tseccull and @talister I have updated the repo code to no longer use imp and pyfits. Please test!

fraserw avatar Jun 04 '25 14:06 fraserw