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

Module is incorrectly imported in debugger #9593

Closed
chenly23 opened this issue Jan 15, 2020 · 6 comments
Closed

Module is incorrectly imported in debugger #9593

chenly23 opened this issue Jan 15, 2020 · 6 comments
Labels
area-debugging area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. bug Issue identified by VS Code Team member as probable bug

Comments

@chenly23
Copy link

chenly23 commented Jan 15, 2020

Environment data

  • VS Code version: 1.41.1
  • Extension version (available under the Extensions sidebar): 2020.1.58038
  • OS and version: Ubuntu 16.04.2 LTS
  • Python version (& distribution if applicable, e.g. Anaconda): 2.7.12
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv

Expected behaviour

Import the modules from my own files

Actual behaviour

Import the modules from files in vscode-python pythonFiles.

Steps to reproduce:

  1. Create a python file (test.py) with the code:
import completion
print(completion)
  1. Create an empty file named completion.py
  2. Debug test.py with Python: Current File (Integrated Terminal)
    Get the output:
<module 'completion' from '/root/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/completion.pyc'>
  1. Run test.py in terminal
    Get the output:
<module 'completion' from '/workspaceFolder/completion.py'>

As @brettcannon pointed out that the directory of pythonFiles gets put on the sys.path to load the debugger, so the modules clash with the user's files.

@chenly23 chenly23 added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Jan 15, 2020
@karthiknadig
Copy link
Member

@chenly23 Can you share the debugger command line that it puts in the terminal?

@karthiknadig karthiknadig added the info-needed Issue requires more information from poster label Jan 16, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jan 16, 2020
@chenly23
Copy link
Author

Sorry, the steps to reproduce may be error, since the workspaceFolder in sys.path is in front of vscode-pythonFiles.
The sys.path is:

['/cly', '/root/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles', '/usr/local/lib/python2.7/dist-packages/xblock_simplevideo-0.1-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/root/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']

/cly is the workspaceFolder. Now I move the completion.py to the site-packages (simulation of pip install?), so the file tree is

/cly
    test.py
/root/.local/lib/python2.7/site-packages
    completion.py
/usr/bin/python

@karthiknadig then the debugger command line and outputs:

root@DevEnv01:/cly# cd /cly ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /usr/bin/python /root/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 42543 /cly/test.py 
<module 'completion' from '/root/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/completion.pyc'>

and the Run Python File in Terminal command line and outpus:

root@DevEnv01:/cly# /usr/bin/python /cly/test.py
<module 'completion' from '/root/.local/lib/python2.7/site-packages/completion.py'>

@karthiknadig
Copy link
Member

@chenly23 This may be an artifact of how we launch the debugger. There is a work around that you can try for now.

workaround:

  1. Get the insiders version of the extension from https://pvsc.blob.core.windows.net/extension-builds/ms-python-insiders.vsix .
  2. Add this to your settings and reload VSCode. (we added the ability to opt-into experiments recently hence the need for insiders version)
    "python.experiments.optInto": [
        "DebugAdapterFactory - experiment",
        "PtvsdWheels37 - experiment"
    ]

This will force the extension to use a newer version of the debugger, that starts is a slightly different way. This method does not add the pythonFiles directory, that way it should not clash with your completion.py.

@karthiknadig karthiknadig added needs PR area-debugging area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. and removed info-needed Issue requires more information from poster triage labels Jan 19, 2020
@karthiknadig
Copy link
Member

Proposed solution:

We should rename our python files to have some sort of prefix that keeps it distinct from something that user might have.

Another solution could be to smartly remove the pythonFiles directory from sys.path before starting the debugger.
PS: Given that we are moving towards the new debugger, I recommend the previous solution.

@chenly23
Copy link
Author

@karthiknadig Thanks for the workaround, I will try the insiders version later.
I add preLaunchTask and postDebugTask to remove and recover the completion.py in pythonFiles to avoid clashing.
For the proposed solution, I recommend the files renaming also~

@karrtikr karrtikr removed their assignment Jan 21, 2020
@luabud
Copy link
Member

luabud commented Feb 12, 2020

Closing in favour of #4609.

@luabud luabud closed this as completed Feb 12, 2020
@ghost ghost removed the needs PR label Feb 12, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

5 participants