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

The python virtual environment selected don‘t take effect after "select workspace interpreter" in ubuntu #173

Closed
DonJayamanne opened this issue Nov 14, 2017 · 25 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@DonJayamanne
Copy link

From @appleyuchi on August 30, 2017 13:38

Environment data

VS Code version: 1.15.1
Python Extension version: 0.7.0
Python Version: 3.5.2
OS and version: Ubuntu16.04

Actual behavior

Python virtual environment did not take effect after select workspace interpreter

Expected behavior

python 3.5

Steps to reproduce:

1、launch from terminal:code
2、ctrl+shift+p=>select workspace interpreter,and choose“/home/appleyuchi/.virtualenvs/python2.7/bin/python”
3、reload
4、run the following code:
import sys
print(sys.prefix)
print(sys.executable)
5、the result is:
[Running] python "/home/appleyuchi/PycharmProjects/csdn_blog_codes/hello.py"
/usr
/usr/bin/python

Logs

Output from Python output panel :

[Running] python "/home/appleyuchi/PycharmProjects/csdn_blog_codes/hello.py"
/usr
/usr/bin/python

Output from Console window (Help->Developer Tools menu)

Copied from original issue: DonJayamanne/pythonVSCode#1186

@DonJayamanne
Copy link
Author

From @appleyuchi on August 30, 2017 13:40

I down load all from
https://github.com/DonJayamanne/pythonVSCode
and
npm install
which doesn't fix above,please help ,Thank you very much.

@DonJayamanne
Copy link
Author

From @appleyuchi on August 30, 2017 13:42

Also ,I have tried to edit python.Pythonpath and python.venvPath and then reload ,all of them don't take effect,my system is :
Linux Ubuntu16 4.8.0-36-generic #36~16.04.1-Ubuntu SMP Sun Feb 5 09:39:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

@brettcannon brettcannon added awaiting 1-verification bug Issue identified by VS Code Team member as probable bug labels Nov 14, 2017
@DonJayamanne
Copy link
Author

@appleyuchi
Please could you upload the contents of your workspace settings.json.

How are you running the code mentioned in step 4?

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster and removed awaiting 1-verification labels Nov 29, 2017
@brettcannon
Copy link
Member

I'm closing this as it has been over a month since we requested more info. If we do get the info at a later date we can re-open this issue.

@peacengell
Copy link

Hello,

I am having the same issue after updating to 1.20 today. Below is my settings.json.

=====
{
"git.enableSmartCommit": true,
"editor.scrollBeyondLastLine": false,
"workbench.sideBar.location": "left",
"editor.fontFamily": "monospace",
"editor.fontSize": 16,
"workbench.iconTheme": "vscode-great-icons",
"editor.multiCursorModifier": "ctrlCmd",
"workbench.colorTheme": "Darktooth",
"editor.lineNumbers": "on",
"workbench.colorCustomizations": {
"statusBar.background": "#3ca826",
"statusBar.foreground": "#eeecec",
"statusBar.noFolderBackground": "#333",
"statusBar.noFolderForeground": "#fff",
"editorGroup.background" : "#000000",
"sideBar.background": "#000000",
"sideBarTitle.foreground": "#ffffff",
"sideBarSectionHeader.background": "#000000",
"sideBarSectionHeader.foreground" : "#ffffff",
"editor.background": "#000",
"editor.foreground": "#fff",
"editorLineNumber.foreground": "#c9c9c9",
"editor.lineHighlightBackground": "#414141",
"activityBar.background" :"#241858cc",
},

"sync.gist": "",
"sync.lastUpload": "2018-02-09T08:24:56.845Z",
"sync.autoDownload": false,
"sync.autoUpload": false,
"sync.lastDownload": "",
"sync.forceDownload": false,
"sync.anonymousGist": false,
"sync.host": "",
"sync.pathPrefix": "",
"sync.quietSync": false,
"sync.askGistName": false,
"gitlens.advanced.messages": {
    "suppressCommitHasNoPreviousCommitWarning": false,
    "suppressCommitNotFoundWarning": false,
    "suppressFileNotUnderSourceControlWarning": true,
    "suppressGitVersionWarning": false,
    "suppressLineUncommittedWarning": false,
    "suppressNoRepositoryWarning": false,
    "suppressUpdateNotice": false,
    "suppressWelcomeNotice": true
},

"files.autoSave": "afterDelay",
"editor.trimAutoWhitespace": false,
"editor.renderWhitespace": "all",
"files.trimFinalNewlines": false,
"files.trimTrailingWhitespace": true,
"html.format.wrapLineLength": 80,
"git.confirmSync": false,

"highlight-matching-tag.leftStyle": {
"borderWidth": "0 0 0 3px",
"borderStyle": "dotted",
"borderColor": "red",
"borderRadius": "5px"
},
"workbench.startupEditor": "newUntitledFile",
"window.openFilesInNewWindow": "on",
"workbench.editor.enablePreview": false,
"editor.minimap.enabled": false,
"editor.formatOnSave": true,
"fileheader.Author": "",
"fileheader.tpl": "#\r\n# @Author: {author} \r\n# @Date: {createTime} \r\n #@Last Modified by:   {lastModifiedBy} \r\n #@Last Modified time: {updateTime} \r\n#\r\n",
"fileheader.LastModifiedBy": "",
"python.autoComplete.addBrackets": true,
"python.venvPath": "/home/toto/.virtualenvs/"

}

Please help,

thanking you in advance.

@DonJayamanne
Copy link
Author

You haven't selected an interpreter, the seeing is missing in settings.json. the seeing is "python.pythonPath", and it should contain the fully qualified path to the interpreter. See here

@appleyuchi
Copy link

I have given up vscode and use sublime now

@DonJayamanne
Copy link
Author

DonJayamanne commented Feb 9, 2018

@appleyuchi I'm sorry to hear this.
Is this because this issue wasn't resolved?

@appleyuchi
Copy link

Accurately speaking,it was not solved in linux(of course I know it's OK in windows)serveral month ago,I don't know whether it's ok now,you can try。
vscode is just a platform but python-related plug-in software depends from personal author,not from microsoft,so,every author has only limited energy and time,it's understandable these kind-hearted authors have too many other things to do.

@appleyuchi
Copy link

appleyuchi commented Feb 10, 2018

`
vscode1

@appleyuchi
Copy link

vscode2

@appleyuchi
Copy link

May be it's my fault,I do not reading relevant instruction about vscode really carefully。
What I upload are two pictures about the code I use and the content of settings.json ,I installed vscode under ubuntu just now。
then I print F5 in keyboard twice,we can see python3.5 in the left-down corner of both the two pictures,
however ,the result of the running code told me that is python2.7

@appleyuchi
Copy link

appleyuchi commented Feb 10, 2018

and this is my .bashrc
**`# ~/.bashrc: executed by bash(1) for non-login shells.

see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)

for examples

If not running interactively, don't do anything

case $- in
i) ;;
*) return;;
esac

don't put duplicate lines or lines starting with space in the history.

See bash(1) for more options

HISTCONTROL=ignoreboth

append to the history file, don't overwrite it

shopt -s histappend

for setting history length see HISTSIZE and HISTFILESIZE in bash(1)

HISTSIZE=1000
HISTFILESIZE=2000

check the window size after each command and, if necessary,

update the values of LINES and COLUMNS.

shopt -s checkwinsize

If set, the pattern "**" used in a pathname expansion context will

match all files and zero or more directories and subdirectories.

#shopt -s globstar

make less more friendly for non-text input files, see lesspipe(1)

[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

set variable identifying the chroot you work in (used in the prompt below)

if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi

set a fancy prompt (non-color, unless we know we "want" color)

case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac

uncomment for a colored prompt, if the terminal has the capability; turned

off by default to not distract the user: the focus in a terminal window

should be on the output of commands, not on the prompt

#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}[\033[01;32m]\u@\h[\033[00m]:[\033[01;34m]\w[\033[00m]$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$ '
fi
unset color_prompt force_color_prompt

If this is an xterm set the title to user@host:dir

case "$TERM" in
xterm*|rxvt*)
PS1="[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a]$PS1"
;;
*)
;;
esac

enable color support of ls and also add handy aliases

if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

fi

colored GCC warnings and errors

#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

some more ls aliases

alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

Add an "alert" alias for long running commands. Use like so:

sleep 10; alert

alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '''s/^\s*[0-9]+\s*//;s/[;&|]\s*alert$//''')"'

Alias definitions.

You may want to put all your additions into a separate file like

~/.bash_aliases, instead of adding them here directly.

See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

enable programmable completion features (you don't need to enable

this, if it's already enabled in /etc/bash.bashrc and /etc/profile

sources /etc/bash.bashrc).

if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
###############################
export JAVA_HOME=/home/appleyuchi/Java/jdk1.8.0_131
export CLASSPATH=${JAVA_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"

#########################################
alias py2.7="source /home/appleyuchi/.virtualenvs/python2.7/bin/activate&&deactivate&&source /home/appleyuchi/.virtualenvs/python2.7/bin/activate"

alias py3.5="source /home/appleyuchi/.virtualenvs/python3.5/bin/activate&&deactivate&&source /home/appleyuchi/.virtualenvs/python3.5/bin/activate"

alias py3.6="source /home/appleyuchi/.virtualenvs/python3.6/bin/activate&&deactivate&&source /home/appleyuchi/.virtualenvs/python3.6/bin/activate"

py2.7

alias suz="/usr/bin/suz.sh"`

@DonJayamanne
Copy link
Author

Please could you provide the contents of the file .vscode/launch.json?

@DonJayamanne DonJayamanne reopened this Feb 10, 2018
@DonJayamanne
Copy link
Author

Also please could you ensure you have updated your version of vscode and the python extension to the latest version. (The latest version of python extension is 2018.01.0 containing a number of fixes)
I'd like to try to help you out with this issue.

@DonJayamanne
Copy link
Author

You seem to have a custom launch.json config seeing and I'm certain the problem lies there. The value for "pythonPath" in there must be incorrect.

@appleyuchi
Copy link

edition

@appleyuchi
Copy link

my launch.json
------------------------not include this line---------------------------------------
{
"version": "0.2.0",
"configurations": [
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
// "pythonPath": "${config:python.pythonPath}",
"pythonPath":"/home/appleyuchi/.virtualenvs/python2.7/bin/python",
"program": "${file}",
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"name": "PySpark",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"osx": {
"pythonPath": "${env:SPARK_HOME}/bin/spark-submit"
},
"windows": {
"pythonPath": "${env:SPARK_HOME}/bin/spark-submit.cmd"
},
"linux": {
"pythonPath": "${env:SPARK_HOME}/bin/spark-submit"
},
"program": "${file}",
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"name": "Python Module",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"module": "module.name",
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"name": "Integrated Terminal/Console",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "",
"console": "integratedTerminal",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit"
]
},
{
"name": "External Terminal/Console",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "",
"console": "externalTerminal",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit"
]
},
{
"name": "Django",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/manage.py",
"cwd": "${workspaceRoot}",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput",
"DjangoDebugging"
]
},
{
"name": "Flask",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "fully qualified path fo 'flask' executable. Generally located along with python interpreter",
"cwd": "${workspaceRoot}",
"env": {
"FLASK_APP": "${workspaceRoot}/quickstart/app.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"name": "Flask (old)",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/run.py",
"cwd": "${workspaceRoot}",
"args": [],
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"name": "Pyramid",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
"args": [
"${workspaceRoot}/development.ini"
],
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput",
"Pyramid"
]
},
{
"name": "Watson",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/console.py",
"cwd": "${workspaceRoot}",
"args": [
"dev",
"runserver",
"--noreload=True"
],
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"name": "Attach (Remote Debug)",
"type": "python",
"request": "attach",
"localRoot": "${workspaceRoot}",
"remoteRoot": "${workspaceRoot}",
"port": 3000,
"secret": "my_secret",
"host": "localhost"
}
]
}

@appleyuchi
Copy link

change

@appleyuchi
Copy link

appleyuchi commented Feb 10, 2018

I try to change python edtion under ubuntu linux with the yellow arrow marked in the last picture I Uploaded

I am from china,It‘s a pity to say that there's no blog listed by Baidu (a search engine like Google) about how to change interpreter of python between python2.x and python3.x under ubuntu linux ,
I’m sorry for wasting your time

@appleyuchi
Copy link

appleyuchi commented Feb 10, 2018

even if I remove“py2.7”in my .bashrc and save
and restart terminal and type in
/home/appleyuchi/.local/share/umake/web/visual-studio-code/bin/code
to start vscode again
the problems remains to reoccur.

I start like this(not in virtualenv ):
appleyuchi@ubuntu:/Desktop$ /home/appleyuchi/.local/share/umake/web/visual-studio-code/bin/code
appleyuchi@ubuntu:
/Desktop$
I don't know why github erase my words in the above lines

@DonJayamanne
Copy link
Author

This is the problem in launch.json, you have hard-nosed the path to python iciest in there:
"pythonPath":"/home/appleyuchi/.virtualenvs/python2.7/bin/python

There are two solutions:

  1. Delete launch.json and start debugging again (it will get created automatically)
  2. Change all cakes for "pythonPath" in launch.json as follows:
    "pythonPath": "${config:python.pythonPath}",

Once again the problem is you have changed the python path in launch.json to point to python 2.7, so no matter what you select, when debugging a different value is used.

@DonJayamanne DonJayamanne added closed-fixed and removed info-needed Issue requires more information from poster labels Feb 10, 2018
@appleyuchi
Copy link

appleyuchi commented Feb 10, 2018

It really take effect ,I'm sorry I didn't understand these parameters in deep.
but it's very strange that when after I installed vscode,I never changed pythonPath,I found "pythonPath" was commented by "//" and replaced with "pythonPath":"/home/appleyuchi/.virtualenvs/python2.7/bin/python by vscode automatically.
Thanks very much~!
I'll write a chinese blog to tell them about this.!

@appleyuchi
Copy link

I have written the whole solution in a Chinese Blog:
http://blog.csdn.net/appleyuchi/article/details/79307692

Many thanks Again~!

@DonJayamanne
Copy link
Author

Glad I could help. Please don't hesitate to raise issues of things don't work or seem confusing.
We're here to help.

@DonJayamanne DonJayamanne self-assigned this Feb 20, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

4 participants