簡體   English   中英

VS 代碼未使用選定的 python 解釋器

[英]VS Code not using selected python interpreter

vscode_setup 小伙伴們怎么了。 我似乎總是有這個問題,我嘗試了各種解決方法。 包括創建您可以在附圖中看到的 settings.json 文件。

問題:VS Code 沒有使用我在 venv/bin/python 中選擇的 python 解釋器(如照片左下角所示)。 Even though I can select it as the interpreter in vs code when I do python manage.py runserver for Django it gives me an error due to it using an older version of python that came with my computer. 由於這個原因,我第一次嘗試使用 pycharm 並最終遇到了同樣的問題。 僅僅是終端沒有使用正確版本的 Python 嗎? VS 代碼版本:1.62.3 我也在 iOS (M1)

讓我知道是否可以為您提供任何進一步的信息,謝謝。

 [![Image of my vscode set up][1]][1]
 ➜  Akutagawa . venv/bin/activate
(venv) ➜  Akutagawa which python
/usr/bin/python
(venv) ➜  Akutagawa which python
/usr/bin/python
(venv) ➜  Akutagawa cd Djanrest/backend
(venv) ➜  backend git:(main) ✗ which python
/usr/bin/python
(venv) ➜  backend git:(main) ✗ python manage.py runserver
  File "manage.py", line 17
    ) from exc
         ^
SyntaxError: invalid syntax
(venv) ➜  backend git:(main) ✗ python3 manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 11, in main
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 13, in main
    raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
(venv) ➜  backend git:(main) ✗ 

在 macOS 上,需要使用python3而不是python ,以便區分 macOS 上內置的 python2。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM