簡體   English   中英

在終端中成功導入模塊,但在 VS Code 中沒有

[英]Successfully import a module in terminal, but not in VS Code

當我想導入一個 package import cvxpy時,我遇到了如下問題。

(py37) E:\amaterials\program\Codefield\CODE_Python> cmd /C "C:\Users\adkad\.conda\envs\py37\python.exe c:\Users\adkad\.vscode\extensions\ms-python.python-2022.12.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher 51686 -- e:\amaterials\program\Codefield\CODE_Python\mathmodel\zhengshuguihua.py "
Traceback (most recent call last):
  File "e:\amaterials\program\Codefield\CODE_Python\mathmodel\zhengshuguihua.py", line 10, in <module>
    import cvxpy as cp
ModuleNotFoundError: No module named 'cvxpy'
Press any key to continue . . . 
(py37) E:\amaterials\program\Codefield\CODE_Python>python
Python 3.7.13 (default, Mar 28 2022, 08:03:21) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cvxpy
>>> print(cvxpy.__version__)
1.2.1
>>> ^Z

我的launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "python": "D:\\program\\python\\python.exe",
            "program": "${file}",
            "cwd": "${workspaceRoot}",
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        }
    ]
}

在 VS Code 終端,我可以成功導入 cvxpy,但是當我使用 Ctrl-F5 運行代碼時,它顯示 cvxpy 沒有找到。

我該如何處理?

Python 3.7.13(默認,2022 年 3 月 28 日,08:03:21)[MSC v.1916 64 位 (AMD64)]:: Anaconda, Inc. on win32

"python": "D:\program\python\python.exe",

conda環境中的 Python 用於終端,但與launch.json

您可以刪除這一行"python": "D:\\program\\python\\python.exe",以及select conda環境作為vscode中的解釋器。(“CTRL + SHIFT + P”並鍵入“Python:select口譯員”)。

暫無
暫無

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

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