Roy Smith
Roy Smith

Reputation: 2163

$PYTHONSTARTUP points to an old version of the extension

Somehow I got myself into a state where python is complaining about PYTHONSTARTUP pointing to a non-existant path. From the terminal tab:

% python
Python 3.11.8 (v3.11.8:db85d51d3e, Feb  6 2024, 18:02:37) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Could not open PYTHONSTARTUP
FileNotFoundError: [Errno 2] No such file or directory: '/Users/roysmith/.vscode/extensions/ms-python.python-2024.4.0/python_files/pythonrc.py'
>>> 

PYTHONSTARTUP is not set in my login shell, but it is set in the vscode environment:

% echo $PYTHONSTARTUP 
/Users/roysmith/.vscode/extensions/ms-python.python-2024.4.0/python_files/pythonrc.py

The problem is that it's pointing to an older version of the python extension (2024.4.0 instead of 2024.4.1):

% ls -ld /Users/roysmith/.vscode/extensions/ms-python.python-*
drwxr-xr-x@ 44 roysmith  staff  1408 Apr 18 17:07 /Users/roysmith/.vscode/extensions/ms-python.python-2024.4.1

So, what's setting PYTHONSTARTUP and why does it point to an old extension directory?

Upvotes: 1

Views: 170

Answers (1)

ggill
ggill

Reputation: 1

Try downgrading to an earlier version of the Microsoft python VSCode extension, and then reinstalling the version you want.

I ran into this same problem with the 2024.8.0 version of the Microsoft python VSCode extension still setting PYTHONSTARTUP=$HOME/.vscode/extensions/ms-python.python-2024.6.0/python_files/pythonrc.py (see 2024.6.0 in the path), which did not exist on my system.

Installing the 2024.6.0 version of the extension worked. (To do this click on the Python extension in the Installed section of the extension marketplace, then click the dropdown arrow on the Uninstall button to get the option to Install Another Version.) PYTHONSTARTUP now pointed to the correct file, the one referenced above, which was installed as part of the 2024.6.0 extension.

So I thought I'd file an issue about 2024.8.0 on the microsoft/vscode-python repo on github. In order to capture the steps for the bug report and the problem message, I reinstalled the 2024.8.0 version of the python extension.

And this time it worked. No complaint about the PYTHONSTARTUP file missing when I start a python terminal from within VSCode.

So you can try this too.

Something about the install of 2024.8.0 is wonky but since I can't reproduce this issue, I'm just going to forget about it.

I wasn't able to find any documentation on how the VSCode python extension sets PYTHONSTARTUP to the startup file it needs. There is this closed github issue, which suggests from the wording that they've only recently started setting PYTHONSTARTUP in the extension.

Upvotes: 0

Related Questions