VSCODE – How to select python version thought remote ssh?
Question:
How can I execute python 3.9 using remote ssh through vscode?
When I connect to the server, it only run as 2.6
My code:
from platform import python_version
print("Current Python Version-", python_version())
output:
[Running] python -u "/root/python/projetos.py"
('Current Python Version-', '2.6.6')
Is there any way to select the python version through vscode? I’ve tried to change at Linux level (using alternative
command), but don’t work.
What I need is vscode to call python3.9 command instead of python command :
[root@quickstart ~]# python --version
Python 2.6.6
[root@quickstart ~]# python3.9 --version
Python 3.9.10
[root@quickstart ~]#
Answers:
I’ve find out.
Need to install python vscode extension on remote ssh server.
When connected to the SSH Server, in extensions (Ctrl + shift + x
), look for python and so, install in SSH:
After install, type Ctrl + shift + p
and look for Python: select interpreter.
And here will show all python interpreters paths installed on the server.
If you want to go shortcut, then simply create a conda environment with Python 3.9 on it. If you do not want to create a separate conda environment, then you can upgrade/add the Python version you want to your server. That means you are brave enough to go the hard way, and then follow the instructions to install it from scratch.
Transfer the compression version of the files to your server:
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
Decompress the tar gz file
tar xvzf Python-3.4.3.tgz
Go to decompressed dir
cd Python-3.4.3
Install Python there
./configure --prefix=$HOME/.local
Do make install for pip and setuptools for Python packages
make
make install
All these commands finish up the Python installation. Once this one is all set, then
we will need to add the path to the environment.
Go to the home dir and open .bash_profile or .profile file
cd $home
vi .bash_profile
Add export path statement there
export PATH="$HOME/.local/bin:$PATH"
Then save file and run the bash file
source ~/.bash_profile
Installation should be all done. To check it, run
python --version
Hope it helps.
How can I execute python 3.9 using remote ssh through vscode?
When I connect to the server, it only run as 2.6
My code:
from platform import python_version
print("Current Python Version-", python_version())
output:
[Running] python -u "/root/python/projetos.py"
('Current Python Version-', '2.6.6')
Is there any way to select the python version through vscode? I’ve tried to change at Linux level (using alternative
command), but don’t work.
What I need is vscode to call python3.9 command instead of python command :
[root@quickstart ~]# python --version
Python 2.6.6
[root@quickstart ~]# python3.9 --version
Python 3.9.10
[root@quickstart ~]#
I’ve find out.
Need to install python vscode extension on remote ssh server.
When connected to the SSH Server, in extensions (Ctrl + shift + x
), look for python and so, install in SSH:
After install, type Ctrl + shift + p
and look for Python: select interpreter.
And here will show all python interpreters paths installed on the server.
If you want to go shortcut, then simply create a conda environment with Python 3.9 on it. If you do not want to create a separate conda environment, then you can upgrade/add the Python version you want to your server. That means you are brave enough to go the hard way, and then follow the instructions to install it from scratch.
Transfer the compression version of the files to your server:
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
Decompress the tar gz file
tar xvzf Python-3.4.3.tgz
Go to decompressed dir
cd Python-3.4.3
Install Python there
./configure --prefix=$HOME/.local
Do make install for pip and setuptools for Python packages
make
make install
All these commands finish up the Python installation. Once this one is all set, then
we will need to add the path to the environment.
Go to the home dir and open .bash_profile or .profile file
cd $home
vi .bash_profile
Add export path statement there
export PATH="$HOME/.local/bin:$PATH"
Then save file and run the bash file
source ~/.bash_profile
Installation should be all done. To check it, run
python --version
Hope it helps.