VS代码:Python解释器找不到我的venv [英] VS Code: Python Interpreter can't find my venv

查看:101
本文介绍了VS代码:Python解释器找不到我的venv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经坚持了几天,请帮忙.

I've been stuck on this for a few days, kindly help me if you can.

我的根项目文件夹中有我的venv文件夹.当我尝试设置Python解释器时,它仅显示我机器中安装的Python,而不显示我的根文件夹中的Python.

I have my venv folder on my root project folder. When I try to set the Python Interpreter, it shows me only the Python installed in my machine and not the one in my root folder.

在我格式化PC并安装10 64位Windows 10之前,它一直运行良好.(已在Windows 7 64位之前运行)

It was working fine until I formatted my PC and installed windows 10 64 bits. (was running on windows 7 64 bits prior)

我尝试过的事情:

  • 通过 pythonPath 和/或 venvPath 在工作区和用户设置中手动设置路径:
  • Set the path manually via pythonPath and/or venvPath, in both workspace and user settings:
    "python.pythonPath": "F:/Web Dev/Python/Django/project_x_v2/backend/venv/Scripts/python.exe",
    "python.venvPath": "F:/Web Dev/Python/Django/project_x_v2/backend/venv/Scripts/python.exe",

它向我显示了占位符的正确位置,但是我没有选择从下拉列表中选择的位置:

It shows me the correct location in the placeholder but I don't have the option to choose it from the dropdown list:

有什么办法可以解决这个问题吗?

Any ideas how I can solve this?

非常感谢您.

  • 在图像中显示"python",但我已将其更正为"python.exe",但仍然无法正常工作;
  • 〜\ AppData \ ... 位于磁盘C:\中,而我的venv位于磁盘F:中.我不确定这是否有意义;
  • venv在控制台中运行正常.
  • In the image it shows "python", but I have corrected it to "python.exe" and it still does not work;
  • ~\AppData\... is located in the disk C:\ while my venv is located in the disk F:. I am not sure whether that is relevant though;
  • The venv runs fine in the console.

推荐答案

我发现的唯一解决方案是删除 venv 并重新创建它.我遵循了这些步骤,但我将提供Windows的简要摘要:

The only solution I found was to delete the venvand recreate it. I followed these steps but I'll provide a brief summary for Windows:

  1. 激活您的virtualenv.转到虚拟环境所在的父文件夹,然后运行 venv \ scripts \ activate .请记住,"venv"的名字可能会有所不同.
  2. 创建一个requirements.txt文件.点冻结要求.txt
  3. 停用退出venv
  4. rm venv 删除venv
  5. py -m venv venv 创建一个新的
  6. pip install -r requirements.txt 来安装需求.
  1. Activate your virtualenv. Go to the parent folder where your Virtual Environment is located and run venv\scripts\activate. Keep in mind that the first name "venv" can vary.
  2. Create a requirements.txt file. pip freeze requirements.txt
  3. deactivate to exit the venv
  4. rm venv to delete the venv
  5. py -m venv venv to create a new one
  6. pip install -r requirements.txt to install the requirements.

这篇关于VS代码:Python解释器找不到我的venv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆