python - 适用于 Linux 的 Windows 子系统 (WSL) 上的 virtualenv
问题描述
我正在使用 Windows 10 机器并想设置 WSL 开发环境。我在 WSL 中打开了 vscode 并设置了所有内容。安装 pip 等
我正在使用 pipenv 安装依赖项。这样做之后,我的网站将无法启动,因为找不到 python 包:
Exception has occurred:
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?
File "/mnt/d/dev/django_appelent_api/manage.py", line 11, in main
from django.core.management import execute_from_command_line
The above exception was the direct cause of the following exception:
File "/mnt/d/dev/django_appelent_api/manage.py", line 13, in main
raise ImportError(
File "/mnt/d/dev/django_appelent_api/manage.py", line 22, in <module>
main()
现在,当我查看virtualenv
文件夹(查看包是否在那里)时,我看到了我的 windows venv 和我的 ubuntu venv 之间的区别。Windows 在此文件夹中安装了软件包:
C:\Users\<username>\\.virtualenvs\django_appelent_api-8qkCZVAS\Lib\site-packages
和安装在此文件夹中的 ubuntu:
\\wsl$\Ubuntu-20.04\home\<username>\\.local\share\virtualenvs\django_appelent_api-PLA7kcVH\lib
这可以解释为什么我有这个错误吗?Windows 安装在 lib/site-packages 中,而 ubuntu 在它们之间放置了一个名为 python3.8 的文件夹。
我的调试文件(在 VSCODE 中)如下所示:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\manage.py",
"args": [
"runserver"
],
"django": true
},
{
"name": "Python: Django on WSL",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver"
],
"django": true
}
]
}
解决方案
推荐阅读
- asp.net - ASP.net Webservice 缺少 Xheader 确认电子邮件为空白
- java - 为什么我在检索 Bundle 参数时收到空指针异常?
- arrays - 如何添加或删除两个输入字段并将这些输入存储到反应数组中?
- javascript - 从数组格式化字符串创建 Javascript 数组
- moodle - Moodle课程总成绩
- google-api - Google G Suite 业务报告 API 配置
- python - 如何在分组条形图上方显示百分比
- c - 显示错误 zsh: segmentation fault 。如何改变?
- reactjs - 反应输入选择以显示相应的组件并将字符串值选择为数字值
- dart - Flutter(Dart)删除firebase数据库监听器