-
Notifications
You must be signed in to change notification settings - Fork 478
Description
Describe the bug
When a file called logging.py
exists in the directory that pipx
is invoked from, pipx
crashes.
How to reproduce
On my Ubuntu 20.04 LTS machine:
cd $(mktemp -d)
pipx --version
1.2.0
Create a logging.py
file:
cat > logging.py
print('hello world')
^d
Run pipx:
pipx --version
"hello world" appears, then a crash:
hello world
Traceback (most recent call last):
File "/home/james/.local/bin/pipx", line 5, in <module>
from pipx.main import cli
File "/home/james/.local/lib/python3.8/site-packages/pipx/main.py", line 7, in <module>
import logging.config
ModuleNotFoundError: No module named 'logging.config'; 'logging' is not a package
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 32, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 12, in <module>
import os, glob, subprocess, os.path, time, pwd, sys, requests_unixsocket
File "/usr/lib/python3/dist-packages/requests_unixsocket/__init__.py", line 1, in <module>
import requests
File "/usr/lib/python3/dist-packages/requests/__init__.py", line 43, in <module>
import urllib3
File "/usr/lib/python3/dist-packages/urllib3/__init__.py", line 7, in <module>
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 29, in <module>
from .connection import (
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 41, in <module>
from .util.ssl_ import (
File "/usr/lib/python3/dist-packages/urllib3/util/__init__.py", line 20, in <module>
from .retry import Retry
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 20, in <module>
log = logging.getLogger(__name__)
AttributeError: module 'logging' has no attribute 'getLogger'
Original exception was:
Traceback (most recent call last):
File "/home/james/.local/bin/pipx", line 5, in <module>
from pipx.main import cli
File "/home/james/.local/lib/python3.8/site-packages/pipx/main.py", line 7, in <module>
import logging.config
ModuleNotFoundError: No module named 'logging.config'; 'logging' is not a package
Expected behavior
pipx is not be affected by the presence of a logging.py
file in the current directory - it shows the current version and does not crash.
Checking on docker with py3.12
I was concerned that this failure might be a consequence of my shaky Ubuntu install in the global environment, so I reproduced it in a docker Python 3.12 image. It's a bit hacky because I've run it as root, but I'm able to get the same crash when trying to install tox
:
docker run -it python:3.12 /bin/bash
root@8facc5020f37:/# python3 -m pip install pipx --user
Collecting pipx
Downloading pipx-1.2.0-py3-none-any.whl (57 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.8/57.8 kB 2.6 MB/s eta 0:00:00
Collecting argcomplete>=1.9.4 (from pipx)
Obtaining dependency information for argcomplete>=1.9.4 from https://files.pythonhosted.org/packages/1e/05/223116a4a5905d6b26bff334ffc7b74474fafe23fcb10532caf0ef86ca69/argcomplete-3.1.2-py3-none-any.whl.metadata
Downloading argcomplete-3.1.2-py3-none-any.whl.metadata (16 kB)
Collecting packaging>=20.0 (from pipx)
Obtaining dependency information for packaging>=20.0 from https://files.pythonhosted.org/packages/ec/1a/610693ac4ee14fcdf2d9bf3c493370e4f2ef7ae2e19217d7a237ff42367d/packaging-23.2-py3-none-any.whl.metadata
Downloading packaging-23.2-py3-none-any.whl.metadata (3.2 kB)
Collecting userpath>=1.6.0 (from pipx)
Obtaining dependency information for userpath>=1.6.0 from https://files.pythonhosted.org/packages/a2/28/20c7dcdb12681b2e12224184a8a158e5df51feb0c68116cb4b1b991a4aab/userpath-1.9.1-py3-none-any.whl.metadata
Downloading userpath-1.9.1-py3-none-any.whl.metadata (3.0 kB)
Collecting click (from userpath>=1.6.0->pipx)
Obtaining dependency information for click from https://files.pythonhosted.org/packages/00/2e/d53fa4befbf2cfa713304affc7ca780ce4fc1fd8710527771b58311a3229/click-8.1.7-py3-none-any.whl.metadata
Downloading click-8.1.7-py3-none-any.whl.metadata (3.0 kB)
Downloading argcomplete-3.1.2-py3-none-any.whl (41 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.5/41.5 kB 10.1 MB/s eta 0:00:00
Downloading packaging-23.2-py3-none-any.whl (53 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 53.0/53.0 kB 7.0 MB/s eta 0:00:00
Downloading userpath-1.9.1-py3-none-any.whl (9.1 kB)
Downloading click-8.1.7-py3-none-any.whl (97 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 kB 6.4 MB/s eta 0:00:00
Installing collected packages: packaging, click, argcomplete, userpath, pipx
WARNING: The script userpath is installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script pipx is installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed argcomplete-3.1.2 click-8.1.7 packaging-23.2 pipx-1.2.0 userpath-1.9.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[notice] A new release of pip is available: 23.2.1 -> 23.3
[notice] To update, run: pip install --upgrade pip
root@8facc5020f37:/# /root/.local/bin/pipx --version
1.2.0
root@8facc5020f37:/# cat > logging.py
print('hello world')
root@8facc5020f37:/# /root/.local/bin/pipx --version
1.2.0
root@8facc5020f37:/# /root/.local/bin/pipx install tox
hello world
Traceback (most recent call last):
File "<frozen runpy>", line 189, in _run_module_as_main
File "<frozen runpy>", line 148, in _get_module_details
File "<frozen runpy>", line 112, in _get_module_details
File "/usr/local/lib/python3.12/venv/__init__.py", line 17, in <module>
logger = logging.getLogger(__name__)
^^^^^^^^^^^^^^^^^
AttributeError: module 'logging' has no attribute 'getLogger'
'/usr/local/bin/python3 -m venv --without-pip /root/.local/pipx/venvs/tox' failed
I'm probably getting something wrong with "ensurepath" or there's something going on that I'm missing - but hopefully this is helpful 🙏🏻
I spotted this when I tried to view a Markdown file with frogmouth in a project that contained a logging.py
file and the frogmouth package kept crashing, so this might affect installed packages too.