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

Brocken import from current directory in 7.2.0 #11531

Open
hsalamin opened this issue Dec 14, 2018 · 5 comments
Open

Brocken import from current directory in 7.2.0 #11531

hsalamin opened this issue Dec 14, 2018 · 5 comments

Comments

@hsalamin
Copy link

hsalamin commented Dec 14, 2018

Trying to import module in the current working directory raise a ImportError exception after updating ipython to 7.2.0. I have an empty module test_module.py in the current directory.

The command:
ipython -c "import test_module"
run withouth error.

However, if I launch ipython and execute the statement
import test_module
I get an ImportError

If I reinstall version 7.1.0 (using pip), I don't have an error when trying to import test_module inside iPython

@hsalamin hsalamin reopened this Dec 14, 2018
@dsblank
Copy link
Contributor

dsblank commented Dec 26, 2018

What is the output of:

import sys; print(sys.path)

@hsalamin
Copy link
Author

hsalamin commented Dec 27, 2018

For ipython version (7.1.0):

['', '/home/hsalamin/.virtualenvs/python3/bin', '/home/hsalamin/.virtualenvs/python3/lib/python35.zip', '/home/hsalamin/.virtualenvs/python3/lib/python3.5', '/home/hsalamin/.virtualenvs/python3/lib/python3.5/plat-x86_64-linux-gnu', '/home/hsalamin/.virtualenvs/python3/lib/python3.5/lib-dynload', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/home/hsalamin/.virtualenvs/python3/lib/python3.5/site-packages', '/home/hsalamin/.virtualenvs/python3/lib/python3.5/site-packages/IPython/extensions', '/home/hsalamin/.ipython']

For ipython version 7.2.0 (inside iypthon):
['/home/hsalamin/.virtualenvs/python3/bin', '/home/hsalamin/.virtualenvs/python3/lib/python35.zip', '/home/hsalamin/.virtualenvs/python3/lib/python3.5', '/home/hsalamin/.virtualenvs/python3/lib/python3.5/plat-x86_64-linux-gnu', '/home/hsalamin/.virtualenvs/python3/lib/python3.5/lib-dynload', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/home/hsalamin/.virtualenvs/python3/lib/python3.5/site-packages', '/home/hsalamin/.virtualenvs/python3/lib/python3.5/site-packages/IPython/extensions', '/home/hsalamin/.ipython']

For ipython 7.2.0 from the cmd line:
['/home/hsalamin/.virtualenvs/python3/bin', '/home/hsalamin/.virtualenvs/python3/lib/python35.zip', '/home/hsalamin/.virtualenvs/python3/lib/python3.5', '/home/hsalamin/.virtualenvs/python3/lib/python3.5/plat-x86_64-linux-gnu', '/home/hsalamin/.virtualenvs/python3/lib/python3.5/lib-dynload', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '', '/home/hsalamin/.virtualenvs/python3/lib/python3.5/site-packages', '/home/hsalamin/.virtualenvs/python3/lib/python3.5/site-packages/IPython/extensions', '/home/hsalamin/.ipython']

@fianitnz
Copy link

fianitnz commented Jan 19, 2019

Immediately after upgrading to ipython 7.2.0 in venv
There was the same problem.

Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import microblog                                                                             
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-889f693766cd> in <module>
----> 1 import microblog

ModuleNotFoundError: No module named 'microblog'

After restarting the computer, it remained.
Made pip install --upgrade ipython
Requirement already up-to-date: ipython
Requirement already satisfied, skipping upgrade: all the rest.

import works

The same thing happened when updating ipython on the system.

add after 30min: It does not work again, I can not repeat it.
add: Repeats if you open a new terminal.

import sys; print(sys.path)
The working output version is different from the non-working '',
If you add manually it starts working but then disappears again.
And stops working.

@andrii-rubtsov
Copy link

andrii-rubtsov commented Feb 16, 2019

In my case I see that IPython 7.2.0 puts current working directory '' in the middle of the list. Thus standard libs are loaded before my own ones from current dir. It should not happen.

bash-5.0$ python -V
Python 3.6.8
bash-5.0$ python -c 'import sys,pprint; pprint.pprint(sys.path)'
['',
 '/Users/arubtsov/.pyenv/versions/3.6.8/lib/python36.zip',
 '/Users/arubtsov/.pyenv/versions/3.6.8/lib/python3.6',
 '/Users/arubtsov/.pyenv/versions/3.6.8/lib/python3.6/lib-dynload',
 '/Users/arubtsov/.pyenv/versions/3.6.8/lib/python3.6/site-packages']
bash-5.0$ ipython -c 'import sys,pprint; pprint.pprint(sys.path)'
['/Users/arubtsov/.pyenv/versions/3.6.8/bin',
 '/Users/arubtsov/.pyenv/versions/3.6.8/lib/python36.zip',
 '/Users/arubtsov/.pyenv/versions/3.6.8/lib/python3.6',
 '/Users/arubtsov/.pyenv/versions/3.6.8/lib/python3.6/lib-dynload',
 '',
 '/Users/arubtsov/.pyenv/versions/3.6.8/lib/python3.6/site-packages',
 '/Users/arubtsov/.pyenv/versions/3.6.8/lib/python3.6/site-packages/IPython/extensions',
 '/Users/arubtsov/.ipython']
bash-5.0$ ipython -V
7.2.0

I am on Mac OS Mojave in case it matters.
The same story with python 3.7.2

Actually, I have found the problem with my problem. Posting here in case someone else is curious: 2c70fc6

It seems like this was done intentionally. I cannot fully agree with the reasoning though

@dragoljub
Copy link

@minrk is there any way we can disable this behavior? I just ran into this after updating IPython and was very surprised that the CWD py files were not the first things to be imported. This causes issues if you want to jump into a specific package folder and just import that module, but a higher level module init is in the PYTHONPATH which is now above the CWD and overrides your local import attempt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants