# How do I migrate from imp?

**URL:** <https://discuss.python.org/t/how-do-i-migrate-from-imp/27885>\
**Category:** Python Help\
**Created:** [June 15, 2023, 9:39am UTC](https://discuss.python.org/t/how-do-i-migrate-from-imp/27885 "2023-06-15T09:39:50Z")\
**Posts on this page:** 1\
**Showing post:** 28

<div class="post-metadata">

**Author:** ![hugovk](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/hugovk/32/14505_2.png) [@hugovk](https://discuss.python.org/u/hugovk)\
**Post date:** [November 10, 2023, 2:50pm UTC](https://discuss.python.org/t/how-do-i-migrate-from-imp/27885/28 "2023-11-10T14:50:58Z")

</div>

Tip: If you use `sys.version_info`, then when the time comes you can use [pyupgrade](https://github.com/asottile/pyupgrade) to automatically upgrade. For example, given:

```python
import sys

if sys.version_info < (3,):
    import imp

    def load_module(name):
        # logic that uses Python 2.x's `imp` here
        ...
else:
    import importlib

    def load_module(name):
        # logic that uses Python 3.x's `importlib` here
        ...

```

Running `pyupgrade 1.py --py38-plus` gives:

```python
import sys

import importlib

def load_module(name):
    # logic that uses Python 3.x's `importlib` here
    ...

```

---

_[View the full topic](https://discuss.python.org/t/how-do-i-migrate-from-imp/27885)._
