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

ImportError: No module named site when starting code in terminal after Python 3.8 was installed on MacOS #89013

Closed
nikolaj-lisberg-hansen opened this issue Jan 21, 2020 · 2 comments
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@nikolaj-lisberg-hansen
Copy link

Issue Type: Bug

Bacause Python 2 is being deprecated I installed Python 3 on MacOS with Catalina ,using the now standard zsh, instead of bash shell.

FIxed issue with having both Python 3.8 and 2.7 by adding these lines in

~/.zshrc and ~/.bash_profile

alias python=python3
alias pip=pip3
unset PYTHONPATH
unset PYTHONHOME

Root cause is Visual Studio code bash script, that is used to start the app from a Terminal. The dependency on Python in bash script, could be avoided in

Applications/Visual Studio Code.app/Contents/Resources/app/bin/code

#!/usr/bin/env bash

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License. See License.txt in the project root for license information.

Workaround for "ImportError: No module named site" with both python 2.7 and 3.8 and zsh in MacOS Catalina instead of bash

Fix is not to use Python but just standard bash to resolve symbolic links

--- Remove lines related to python:

function realpath() { python -c "import os, sys; print(os.path.realpath(sys.argv[1]))" "$0"; }

CONTENTS="$(dirname $(dirname $(dirname $(realpath "$0" ))))"

--- Start fix: Add standard bash logic for resolving symbolic links

Get code symbolic link /usr/local/bin/code symbolic link

CODE="${BASH_SOURCE[0]}"

Find Contents path in /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code

CONTENTS=ls -dal $CODE | awk '{ print substr($11 " " $12 " " $13,0,length($11 " " $12 " " $13)-length("/Resources/app/bin/code"))}'

--- End fix

ELECTRON="$CONTENTS/MacOS/Electron"
CLI="$CONTENTS/Resources/app/out/cli.js"
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?

VS Code version: Code 1.41.1 (26076a4, 2019-12-18T14:57:51.166Z)
OS version: Darwin x64 19.2.0

System Info
Item Value
CPUs Intel(R) Core(TM) m3-6Y30 CPU @ 0.90GHz (4 x 1100)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: unavailable_off
protected_video_decode: unavailable_off
rasterization: unavailable_off
skia_renderer: disabled_off
surface_control: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) 2, 2, 2
Memory (System) 8.00GB (0.12GB free)
Process Argv -psn_0_225335
Screen Reader no
VM 0%
Extensions (2)
Extension Author (truncated) Version
vscode-docker ms- 0.9.0
python ms- 2020.1.58038
@vscodebot vscodebot bot added the terminal Integrated terminal issues label Jan 21, 2020
@sbatten sbatten added the *caused-by-extension Issue identified to be caused by an extension label Jan 21, 2020
@vscodebot vscodebot bot closed this as completed Jan 21, 2020
@sbatten sbatten removed the *caused-by-extension Issue identified to be caused by an extension label Jan 21, 2020
@microsoft microsoft deleted a comment from vscodebot bot Jan 21, 2020
@sbatten sbatten reopened this Jan 21, 2020
@joaomoreno
Copy link
Member

The Python code we have there is compatible with both 2 and 3. If you see an error it might be because you have a broken Python installation. Can you confirm?

@joaomoreno joaomoreno added info-needed Issue requires more information from poster and removed terminal Integrated terminal issues labels Jan 23, 2020
@vscodebot vscodebot bot closed this as completed Jan 30, 2020
@vscodebot
Copy link

vscodebot bot commented Jan 30, 2020

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants