Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: ipykernel_launcher, delete absolute sys.path[0] #1206

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

stdll00
Copy link
Contributor

@stdll00 stdll00 commented Feb 7, 2024

If use -m option, sys.path[0] will be absolute path.
Delete sys.path[0] if it's absolute path. Due to PTH109, I use pathlib.
We cannot start python3 -m ipykernel_launcher in the directory which contains queue.py or zmq.py .

ipykernel_launcher.py:13:44: PTH109 `os.getcwd()` should be replaced by `Path.cwd()`

How to reproduce.

cd /tmp
git clone https://github.com/ipython/ipykernel.git
python3 -m pip install -e ./ipykernel
mkdir test
cd test
python3 -m ipykernel_launcher # it works
# Ctrl + \ to kill
touch queue.py

python3 -m ipykernel_launcher # error!

Error details

python3 -m ipykernel_launcher

['/private/tmp/test', '/opt/homebrew/Cellar/[email protected]/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python311.zip', '/opt/homebrew/Cellar/[email protected]/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11', '/opt/homebrew/Cellar/[email protected]/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload', '/opt/homebrew/lib/python3.11/site-packages', '/private/tmp/ipykernel']
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/opt/homebrew/lib/python3.11/site-packages/ipykernel_launcher.py", line 16, in <module>
    from ipykernel import kernelapp as app
  File "/private/tmp/ipykernel/ipykernel/__init__.py", line 7, in <module>
    from .connect import *
  File "/private/tmp/ipykernel/ipykernel/connect.py", line 12, in <module>
    import jupyter_client
  File "/opt/homebrew/lib/python3.11/site-packages/jupyter_client/__init__.py", line 3, in <module>
    from .asynchronous import AsyncKernelClient
  File "/opt/homebrew/lib/python3.11/site-packages/jupyter_client/asynchronous/__init__.py", line 1, in <module>
    from .client import AsyncKernelClient  # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/jupyter_client/asynchronous/client.py", line 11, in <module>
    from ..channels import AsyncZMQSocketChannel, HBChannel
  File "/opt/homebrew/lib/python3.11/site-packages/jupyter_client/channels.py", line 8, in <module>
    from queue import Empty
ImportError: cannot import name 'Empty' from 'queue' (/private/tmp/test/queue.py)

@blink1073 blink1073 changed the title fix: ipykernel_launcher, delete absolute sys.path[0] Fix: ipykernel_launcher, delete absolute sys.path[0] Feb 7, 2024
Copy link
Contributor

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@blink1073 blink1073 added the bug label Feb 7, 2024
@blink1073 blink1073 merged commit edbbd63 into ipython:main Feb 7, 2024
33 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants