Bug 2344401 - direnv =< v2.34.0 throws DeprecationWarning: 'pkgutil.find_loader' trying to run layout_python3 or "layout python3" to load a Python venv
Summary: direnv =< v2.34.0 throws DeprecationWarning: 'pkgutil.find_loader' trying to ...
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: direnv
Version: 41
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Ed Marshall
QA Contact: Fedora Extras Quality Assurance
URL: https://github.com/direnv/direnv/issu...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2025-02-07 20:44 UTC by Will McDonald
Modified: 2025-02-08 10:25 UTC (History)
3 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Will McDonald 2025-02-07 20:44:16 UTC
direnv v2.34.0 and earlier using deprecated pkgutil.find_loader. 

[vagrant@localhost ~]$ rpm -q direnv
direnv-2.32.3-5.fc41.x86_64
[vagrant@localhost ~]$ cat project-a/.envrc 
layout python3
[vagrant@localhost ~]$ cd project-a/
direnv: loading ~/project-a/.envrc
<string>:1: DeprecationWarning: 'pkgutil.find_loader' is deprecated and slated for removal in Python 3.14; use importlib.util.find_spec() instead
  import pkgutil as u, platform as p;ve='venv' if u.find_loader('venv') else ('virtualenv' if u.find_loader('virtualenv') else '');print('.'.join(p.python_version_tuple()[:2])+' '+ve)
direnv: export +VIRTUAL_ENV ~PATH

https://github.com/direnv/direnv/issues/1177 indicates the cause.

https://github.com/direnv/direnv/commit/af06cb05c1468f4b80a7548818d096625fb04c36 indicates the upstream direnv fix.

Reproducible: Always

Steps to Reproduce:
1. $ sudo dnf -y install direnv
2. $ echo eval "$(direnv hook bash)" >> ~/.bashrc
3. $ mkdir ~/project-a
4. $ python -m venv ~/project-a/.venv
5. $ cd ~/project-a
6. $ echo 'layout python3' > .envrc
7. $ direnv allow

Actual Results:  
[vagrant@localhost ~]$ cd project-a/
direnv: loading ~/project-a/.envrc
<string>:1: DeprecationWarning: 'pkgutil.find_loader' is deprecated and slated for removal in Python 3.14; use importlib.util.find_spec() instead
  import pkgutil as u, platform as p;ve='venv' if u.find_loader('venv') else ('virtualenv' if u.find_loader('virtualenv') else '');print('.'.join(p.python_version_tuple()[:2])+' '+ve)
direnv: export +VIRTUAL_ENV ~PATH


Expected Results:  
direnv invokes the venv without throwing the exception.

https://github.com/direnv/direnv/issues/1177 indicates the cause.

https://github.com/direnv/direnv/commit/af06cb05c1468f4b80a7548818d096625fb04c36 indicates the upstream direnv fix.


Note You need to log in before you can comment on or make changes to this bug.