Vs code обновить python

How to change Python version in VS Code

so I want to make a project using python and have followed docs to install it but when I trying using it on vs code my version of python is 2 and not 3 even tho i’ve select my interpreter as python 3. I’ve check and python 3 is installed in my computer. version of python 3 installed in my terminal version of python in my vs terminal

In one case you start it with python and the other with python3 . Therefore you get different interpreters. Python 2 is the default on macOS at the moment

2 Answers 2

1) This is most probably because your environment variable paths include python 2. Add python3 environment variable to your paths if you haven done so.

2) In terminal, u can set your cmd line code to run with $python3 helloworld.py

You should be using virtual environments whenever you do something with Python (exception can be when writing single file scripts with no non-standard dependencies, and specifying the Python version with the shebang). That way, you’ll completely isolate your environment.

The problem you’re having now is that you rely on the path to your python . What happens if someone needs to run your project on his machine? And what he needs to install some dependency, but there’s some conflict with the ones already install? Virtual environments help you with that isolating your environment and making it portable.

Читайте также:  Fileinputstream in java methods

Here’s a quick start, which will help you to understand it:

❯❯❯ which python /usr/bin/python ❯❯❯ python --version Python 3.8.3 ❯❯❯ python3.7 -m venv venv/ ❯❯❯ source venv/bin/activate venv ❯❯❯ which python /tmp/python/venv/bin/python venv ❯❯❯ python --version Python 3.7.7 # Once you're done, you can deactivate the environment venv ❯❯❯ deactivate ❯❯❯ which python /usr/bin/python ❯❯❯ python --version Python 3.8.3 

This way, I’ve created a Python3.7 environment that is completely isolated from my system.

EDIT: I’ve just seen that the title was changed to a VS specific question. You can still do it with the command line (and it’s worth knowing how to do it and how it works), but this explains how to manage the virtual environments within the editor.

Источник

Как поставить нужную версию Python на VS code(если Vs code эту версию не видит)?

На днях перешел с Ubuntu на Linux Manjaro и установил VS code поставл все плагины связанные с Python
и начал выбирать интерпретатор (версии 3.10). Я знаю что он установлен на пк 6286984e7c9a5494996812.pngи во что я вижу на VS Code 6286987a2d107144152757.png
Версии 3.10 как не бывало. (Если что я пытался прописать все пути которые были возможны)
Мне кажется VS Code видит python 3.10 как 3.9, но это не так потому, что все модули приходиться устанавливать для каждой версии отдельно и такжетерминал VS Code не видит господнюю команду sudo. при вызове её выдаёт ошибку: «sh: sudo: команда не найдена»

Средний 1 комментарий

Ну и на первом скриншоте классные команды.

ТС: для начала надо освоить основы работы в Linux. А уж потом браться там программировать.

Nipheris

Самый простой вариант — взять нормальный менеджер окружений (и пакетов заодно), например Poetry, ну или pipenv, если очень хочется, развернуть где-нибудь в подпапке .venv вирт. окружение для вашего проекта, и натравить на него VS Code (вероятно, он сам даже предложит вам в списке этот вариант). Это если вы собираетесь делать что-то сложнее Hello world.

Ну а вообще почему бы вам не ввести путь /usr/bin/python3.10 ? Ну мало ли почему vscode его не нашёл.

Источник

Upgrade python version in visual studio code python workspace

Upgrade Python Virtual Environment

In my earlier article, I have explained how to upgrade Python on macOS and setup Visual Studio Code project for Python development. Now we will see how to upgrade the already setup Python environment in VS Code workspace.

In my current Python workspace, the interpreter is pointing to a virtual environment with Python 3.7.4. To upgrade this to version 3.8.5, I’ve followed these steps.

Caution

When upgrading the python interpreter version in python workspace, you may encounter errors or warnings while running the project because of incompatible usage of methods or objects. So please review the release documents from python.org before upgrading and prepare an action plan to migrate the code to new version of Python.

Prerequisites

  • VS Code should be setup to use Python.
  • A Python virtual environment should be created for the VS Code workspace.
  • Python should be upgraded on macOS to the desired version which you want to use in the VS Code workspace. Here in my case it’s 3.8.5.

Steps to upgrade Python in workspace

Check the current version of python virtual environment

  1. Launch the Visual Studio Code python workspace.
  2. Check the current python virtual environment version. You can check this by opening the Command Palette (by pressing Shift, Command and P keys) and select Python: Select Interpreter. This will show you the list of interpreters, both global and virtual. In my case Python 3.7.4 64-bit is the current virtual environment and 3.8.5 is listed as global environment.
  3. Go back to Command Palette and search and start Terminal: Create New Integrated Terminal. The terminal panel will open at the bottom.
  4. In the terminal run the below comment. In this comment python3.8 is important to upgrade the environment with Python 3.8.x. env is the existing name of the virtual environment.
python3.8 -m venv --upgrade env source env/bin/activate
  1. Restart VS Code and open the workspace.
  2. Now go back to the Command Palette and type in and select Python: Select Interpreter again.
  3. You can see the newly upgraded version (3.8.5) of python virtual environment listed.
    Upgrade Python Virtual Environment
  4. Select the virtual environment Python 3.8.5 64-bit (‘env’: venv).
  5. From now on, the VS Code workspace will use the environment with the new version of Python.
    Select the new version as the interpreter

Tools & Technologies Used

Источник

Оцените статью