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

Not adding current directory to sys.path #246

Closed
yulqen opened this issue Jun 6, 2018 · 10 comments
Closed

Not adding current directory to sys.path #246

yulqen opened this issue Jun 6, 2018 · 10 comments

Comments

@yulqen
Copy link

yulqen commented Jun 6, 2018

I can't work out why some instances of ptpython add the current directory to sys.path. Most of my projects to date, using 0.41, do this with no issues, but in recent installations I've noticed that it is missing from sys.path. Is there a condition for this I'm missing? I can't do basic imports. Stock python (3.6.4) interpreter and bpython - as a quick check - add the current directory without an issue. Tested in a variety of virtualenvs. $PYTHONPATH not set. Thanks.

@jonathanslenders
Copy link
Member

Hi @hammerheadlemon,

This should happen on the following line: https://github.com/jonathanslenders/ptpython/blob/master/ptpython/entry_points/run_ptpython.py#L48
Can you check whether this lines appears in your ptpython source and whether it executes this line?

@yulqen
Copy link
Author

yulqen commented Jun 6, 2018

Hi @jonathanslenders - thanks for pitching in so quickly. Have just been looking at this. Running under the debugger is okay - breakpoint hits at https://github.com/jonathanslenders/ptpython/blob/d00f8d454fe2b94c499869e6677cce7a22601fc4/ptpython/entry_points/run_ptpython.py#L50 and sys.path is obviously set correctly, here, and running on from here to the repl, I get the correct path, but I guess this is a result of executing using the debugger? Without setting a tracepoint, no sys.path is set.

@yulqen
Copy link
Author

yulqen commented Jun 7, 2018

Further investigation... I am seeing this:

Run ptpython as normal and get to the repl:

sys.path

Working directory is at sys.path[0]. Then:

import package

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'package'

No module named 'package'

Then:

sys.path

Working directory is not now in path.

Insert directory manually:

sys.path.insert(0, '')
sys.path

Path is there.

import package

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'package'

No module named 'package'

import statements appear to remove sys.path[0] in this case (when adding an empty string to the path to represent working directory), although I haven't debugged further at this stage.

If I hardcode the working directory:

sys.path.insert(0, '/home/path/to/working/directory')
sys.path

Working directory is there. import works, sys.path stays the same, and correct.

@SBKch
Copy link

SBKch commented Jun 17, 2018

Confirming the same problem, current directory path isn't added automatically and it's removed from the sys.path after adding as ''. Putting dot inside works though ('.').

@davidhalter
Copy link

This is a Jedi bug. Confirmed in davidhalter/jedi#1148. Sorry for the issues it has caused.

@jonathanslenders
Copy link
Member

Hi everyone, I pushed a new version of ptpython that ensures that the current directory is always present in sys.path. This also upgrades to prompt_toolkit 2.0. Can you try again?

@davidhalter
Copy link

I will probably release a new Jedi version (without major changes, but with the patch for this bug). It has been fixed since 4th of July, but hasn't been released (I forgot to do that).

@jonathanslenders
Copy link
Member

Thanks, @davidhalter!

@yulqen
Copy link
Author

yulqen commented Oct 1, 2018

Thank you @davidhalter and @jonathanslenders . Will download and try in the next few days.

@jonathanslenders
Copy link
Member

Closing this. ptpython has a workaround, and there is a new Jedi release.

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

4 participants