Windows Linux子系统(WSL)上的VirtualNV

2024-09-24 02:26:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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软件包中,而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
        }
    ]
}


Tags: todjangoinpydev文件夹apimanage