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

VS Code Python Issue: "Default Python Functions Not Defined" Error #5447

Closed
ghost opened this issue Feb 6, 2024 · 12 comments
Closed

VS Code Python Issue: "Default Python Functions Not Defined" Error #5447

ghost opened this issue Feb 6, 2024 · 12 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@ghost
Copy link

ghost commented Feb 6, 2024

Description of the Problem:

I am experiencing an error in Visual Studio Code across all default Python functions (e.g., input(), print(), etc.). When trying to use these functions in a Python script, I receive errors stating that these functions are "not defined".

  • Environment Details:

Operating System (macOS Monterey ver. 12.7.2):
Visual Studio Code Version (1.86.0):
Python Extension Version in VS Code (2024.0.1):
Python Version (Python 3.11.5, All Versions I have installed):
Any other relevant extensions or tools installed (if any):
I am using Anaconda3
I have no extensions other than the default Python, Python Debugger, and Pylance

Steps to Reproduce:

  1. Open a new or existing Python file in VS Code.
  2. Write simple Python code using standard functions, such as print("Hello World") or name = input("Enter your name: ").
  • Expected Behavior:

The script should execute without errors, and standard Python functions should work as expected. Pylance should not flag default Python functions as reportUndefinedVariable.

  • Actual Behavior:

When running the script it executes normally and runs as normal, but VS Code flags errors for all standard Python functions, claiming they are "not defined". This is occurring despite these functions being integral parts of Python.

  • Troubleshooting Steps Already Taken:
  1. Ensured the correct Python interpreter is selected in VS Code.
  2. Reinstalled the Python extension in VS Code.
  3. Checked settings.json for any potentially conflicting settings, but I do not know enough to know if there are any conflicts.
  4. Updated VS Code and all extensions to the latest versions.
  5. Deleted and Reinstalled VS Code
  • Log when running a hello world file

output.txt

Normal Hello World Script like as follows has the following problem, the function print is underlined in yellow.
print('Hello, World!')
In the problems tab the following error occurs

"print" is not defined Pylance(reportUndefinedVariable) [Ln 1, Col 1]

VSCode_Issue1 VSCode_Issue2

Additional Context:

The issue seems to be isolated to Visual Studio Code, I suspect it might be related to Pylance, Because when pylance is disabled the issue goes away. Other QOL enhancements do too, but the original issue also disappears. I would also like to add, I am pretty new to learning python and am not sure how this occurred, so I'm not exactly sure how to replicate this issue. If i end up finding a solution i will add it.

Edit 2/6/2024 7:31pm EST : I managed to fix the issue. I completely uninstalled VSCode and all associated files and settings. I redownloaded it and reinstalled my plugins and it works fine. I still have no idea what caused this issue, but if it happens to anyone else my only advice is to completely delete and reinstall vscode, deleting the following files as well before you reinstall.
~/.config/Code ~/Library/Application Support/Code ~/Library/Caches/com.microsoft.VSCode ~/Library/Caches/com.microsoft.VSCode.ShipIt ~/Library/Preferences/com.microsoft.VSCode.helper.plist ~/Library/Preferences/com.microsoft.VSCode.plist ~/Library/Saved Application State/com.microsoft.VSCode.savedState

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Feb 6, 2024
@debonte
Copy link
Contributor

debonte commented Feb 7, 2024

Can you please provide a log as described under "Filing an issue" in the troubleshooting guide?

@ghost
Copy link
Author

ghost commented Feb 7, 2024

Can you please provide a log as described under "Filing an issue" in the troubleshooting guide?

I have added it into the file output.txt

@debonte
Copy link
Contributor

debonte commented Feb 7, 2024

This is weird. Any chance you have typeshed installed in your conda environment? Asking because I searched through our old issues for Could not import 'builtins' and the only hit was an issue caused by installing typeshed. #4508 (comment)

2024-02-06 18:12:31.637 [info] [Info  - 6:12:31 PM] (31127) Could not import 'builtins' in file '/Users/jdd31/Desktop/Python Code/CS103/prob1.py'
2024-02-06 18:12:31.639 [info] [Info  - 6:12:31 PM] (31127)   Looking in stubPath '/Users/jdd31/Desktop/Python Code/typings'
2024-02-06 18:12:31.641 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/Desktop/Python Code/typings'
2024-02-06 18:12:31.641 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/Desktop/Python Code/typings'
2024-02-06 18:12:31.642 [info] [Info  - 6:12:31 PM] (31127)   Looking in root directory of execution environment '/Users/jdd31/Desktop/Python Code'
2024-02-06 18:12:31.642 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/Desktop/Python Code'
2024-02-06 18:12:31.643 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/Desktop/Python Code'
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)   Finding python search paths
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)   Executing interpreter: '/Users/jdd31/anaconda3/bin/python'
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)   Skipping '/Users/jdd31/anaconda3/lib/python311.zip' because it is not a valid directory
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)   Received 4 paths from interpreter
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)     /Users/jdd31/anaconda3/lib/python3.11
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)     /Users/jdd31/anaconda3/lib/python3.11/lib-dynload
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)     /Users/jdd31/anaconda3/lib/python3.11/site-packages
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)     /Users/jdd31/anaconda3/lib/python3.11/site-packages/aeosa
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)   Looking in python search path '/Users/jdd31/anaconda3/lib/python3.11'
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/anaconda3/lib/python3.11'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/anaconda3/lib/python3.11'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Looking in python search path '/Users/jdd31/anaconda3/lib/python3.11/lib-dynload'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/anaconda3/lib/python3.11/lib-dynload'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/anaconda3/lib/python3.11/lib-dynload'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Looking in python search path '/Users/jdd31/anaconda3/lib/python3.11/site-packages'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/anaconda3/lib/python3.11/site-packages'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/anaconda3/lib/python3.11/site-packages'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Looking in python search path '/Users/jdd31/anaconda3/lib/python3.11/site-packages/aeosa'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/anaconda3/lib/python3.11/site-packages/aeosa'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/anaconda3/lib/python3.11/site-packages/aeosa'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Looking in bundled stubs path '/Users/jdd31/.vscode/extensions/ms-python.vscode-pylance-2023.12.1/dist/bundled/stubs'
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/.vscode/extensions/ms-python.vscode-pylance-2023.12.1/dist/bundled/stubs'
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/.vscode/extensions/ms-python.vscode-pylance-2023.12.1/dist/bundled/stubs'
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Looking for typeshed stdlib path
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Looking for typeshed stdlib path
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Typeshed path not found
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Looking for typeshed third-party path
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Looking for typeshed stubs path
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Typeshed path not found

@ghost
Copy link
Author

ghost commented Feb 7, 2024

This is weird. Any chance you have typeshed installed in your conda environment? Asking because I searched through our old issues for Could not import 'builtins' and the only hit was an issue caused by installing typeshed. #4508 (comment)

2024-02-06 18:12:31.637 [info] [Info  - 6:12:31 PM] (31127) Could not import 'builtins' in file '/Users/jdd31/Desktop/Python Code/CS103/prob1.py'
2024-02-06 18:12:31.639 [info] [Info  - 6:12:31 PM] (31127)   Looking in stubPath '/Users/jdd31/Desktop/Python Code/typings'
2024-02-06 18:12:31.641 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/Desktop/Python Code/typings'
2024-02-06 18:12:31.641 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/Desktop/Python Code/typings'
2024-02-06 18:12:31.642 [info] [Info  - 6:12:31 PM] (31127)   Looking in root directory of execution environment '/Users/jdd31/Desktop/Python Code'
2024-02-06 18:12:31.642 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/Desktop/Python Code'
2024-02-06 18:12:31.643 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/Desktop/Python Code'
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)   Finding python search paths
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)   Executing interpreter: '/Users/jdd31/anaconda3/bin/python'
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)   Skipping '/Users/jdd31/anaconda3/lib/python311.zip' because it is not a valid directory
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)   Received 4 paths from interpreter
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)     /Users/jdd31/anaconda3/lib/python3.11
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)     /Users/jdd31/anaconda3/lib/python3.11/lib-dynload
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)     /Users/jdd31/anaconda3/lib/python3.11/site-packages
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)     /Users/jdd31/anaconda3/lib/python3.11/site-packages/aeosa
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)   Looking in python search path '/Users/jdd31/anaconda3/lib/python3.11'
2024-02-06 18:12:31.644 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/anaconda3/lib/python3.11'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/anaconda3/lib/python3.11'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Looking in python search path '/Users/jdd31/anaconda3/lib/python3.11/lib-dynload'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/anaconda3/lib/python3.11/lib-dynload'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/anaconda3/lib/python3.11/lib-dynload'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Looking in python search path '/Users/jdd31/anaconda3/lib/python3.11/site-packages'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/anaconda3/lib/python3.11/site-packages'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/anaconda3/lib/python3.11/site-packages'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Looking in python search path '/Users/jdd31/anaconda3/lib/python3.11/site-packages/aeosa'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/anaconda3/lib/python3.11/site-packages/aeosa'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/anaconda3/lib/python3.11/site-packages/aeosa'
2024-02-06 18:12:31.645 [info] [Info  - 6:12:31 PM] (31127)   Looking in bundled stubs path '/Users/jdd31/.vscode/extensions/ms-python.vscode-pylance-2023.12.1/dist/bundled/stubs'
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve stub package using root path '/Users/jdd31/.vscode/extensions/ms-python.vscode-pylance-2023.12.1/dist/bundled/stubs'
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Attempting to resolve using root path '/Users/jdd31/.vscode/extensions/ms-python.vscode-pylance-2023.12.1/dist/bundled/stubs'
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Looking for typeshed stdlib path
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Looking for typeshed stdlib path
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Typeshed path not found
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Looking for typeshed third-party path
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Looking for typeshed stubs path
2024-02-06 18:12:31.646 [info] [Info  - 6:12:31 PM] (31127)   Typeshed path not found

no, i do not have typeshed installed.

@ghost
Copy link
Author

ghost commented Feb 7, 2024

Edit 2/6/2024 7:31pm EST : I managed to fix the issue. I completely uninstalled VSCode and all associated files and settings. I redownloaded it and reinstalled my plugins and it works fine. I still have no idea what caused this issue, but if it happens to anyone else my only advice is to completely delete and reinstall vscode, deleting the following files as well before you reinstall.
~/.config/Code ~/Library/Application Support/Code ~/Library/Caches/com.microsoft.VSCode ~/Library/Caches/com.microsoft.VSCode.ShipIt ~/Library/Preferences/com.microsoft.VSCode.helper.plist ~/Library/Preferences/com.microsoft.VSCode.plist ~/Library/Saved Application State/com.microsoft.VSCode.savedState

@ghost ghost closed this as completed Feb 7, 2024
@ghost ghost closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2024
@ghost ghost reopened this Feb 7, 2024
@ghost
Copy link
Author

ghost commented Feb 7, 2024

I'm keeping this open in hopes i can eventually repro

@debonte
Copy link
Contributor

debonte commented Feb 7, 2024

Please reactivate if you get a repro.

@debonte debonte closed this as completed Feb 7, 2024
@eliguinza
Copy link

Hi Team,
This happens because of a issue in the extension Pylance. All you have to do is uninstall it and restart VsCode. This should fix the issue. If you need pylance for your work, try re-installing it or try for an older version. Let me know if this helps anyone,
Kinds regards

@dfs-
Copy link

dfs- commented May 23, 2024

This seems to be reproducible by configuring something like

{
   "python.defaultInterpreterPath": "C:\\Tools\\Python2\\python.exe"
}

in VSCodes settings.json.
This is done to use old-school Python2 as default runtime. A workaround can be applied by doing something like this: https://stackoverflow.com/a/77793780/1873366

@heejaechang
Copy link
Contributor

thank you for the repro. let us take a look whether we can guard from it.

@heejaechang heejaechang reopened this May 23, 2024
@heejaechang heejaechang assigned heejaechang and unassigned KacieKK May 23, 2024
@pztrick
Copy link

pztrick commented Jul 9, 2024

I encountered this issue working on a project in wsl2.

The extension page presented with: This extension is disabled in this workspace because it is defined to run in the Remote Extension Host. Please install the extension in 'WSL: jammy' to enable..

After clicking to install in WSL and restarting VScode the Pylance lint errors for built-ins like print(...) were resolved.

Just sharing in case it helps to troubleshoot...

@heejaechang
Copy link
Contributor

I can't repro the original issue anymore. closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

6 participants