简体   繁体   English

如何使用本地包调试 VSCODE python

[英]How to debug VSCODE python using local packages

import logging import sys import os from LoggingHelper.main import LoggingHelper <-- Import "LoggingHelper.main" could not be resolvedPylancereportMissingImports from LoggingHelper.models import logDataclass as ldc <-- Import "LoggingHelper.main" could not be resolvedPylancereportMissingImports from.configs.project_configs import * kafka_config = {} from fastapi import FastAPI, Request <-- Import "LoggingHelper.main" could not be resolvedPylancereportMissingImports from fastapi.responses import JSONResponse <-- Import "LoggingHelper.main" could not be resolvedPylancereportMissingImports import fastapi <-- Import "LoggingHelper.main" could not be resolvedPylancereportMissingImports import azure.functions as func <-- Import "LoggingHelper.main" could not be resolvedPylancereportMissingImports import nest_asyncio from starlette.middleware import Middleware <-- Import "LoggingHelper.main" could not be resolvedPylancereportMissingImports from starlette.middleware.cors import CORSMiddleware import logging import sys from LoggingHelper.main import LoggingHelper <-- 无法从 LoggingHelper.models 中导入“LoggingHelper.main”PylancereportMissingImports import logDataclass as ldc <-- 无法导入“LoggingHelper.main”PylancereportMissingImports from.configs。 project_configs import * kafka_config = {} from fastapi import FastAPI, Request <-- 无法解析导入“LoggingHelper.main”PylancereportMissingImports from fastapi.responses import JSONResponse <-- 导入“LoggingHelper.main”无法解析PylancereportMissingImports import fastapi <--导入“LoggingHelper.main”无法解析从 starlette.middleware.cors 导入 CORSMiddleware <-- Import "LoggingHelper.main" could not be resolvedPylancereportMissingImports nest_asyncio.apply() from TSAuthHelper import FastAPIAuthHelper <-- Import "LoggingHelper.main" could not be resolvedPylancereportMissingImports import json import os import time import traceback import pickle <-- 无法解析导入“LoggingHelper.main”PylancereportMissingImports nest_asyncio.apply() from TSAuthHelper import FastAPIAuthHelper <-- 导入“LoggingHelper.main”无法解析PylancereportMissingImports import json import os import time import traceback import pickle

I have a local library/package in ".python_packages\lib\site-packages" called "LoggingHelper", "fastapi", "starlette/middleware", etc. But I can't compile those in VSCODE.我在“.python_packages\lib\site-packages”中有一个名为“LoggingHelper”、“fastapi”、“starlette/middleware”等的本地库/包。但我无法在 VSCODE 中编译它们。 They work just fine if I publish them all to Azure Functions, but not locally.如果我将它们全部发布到 Azure Functions,但不是在本地,它们就可以正常工作。 I need to debug them locally on my VSCODE.我需要在我的 VSCODE 上本地调试它们。

I have been trying to read everything I can, change the interpreter, etc. But I'm not a developer and need some guidance.我一直在尝试尽我所能阅读所有内容,更改解释器等。但我不是开发人员,需要一些指导。

from.python_packages/fastapi import FastAPI from.python_packages/fastapi 导入 FastAPI

from fullpath/.python_packages/fastapi import FastAPI从完整路径/.python_packages/fastapi 导入 FastAPI

nothing works.没有任何作用。

When running locally you may need to specify the major version of Python you intend to use.在本地运行时,您可能需要指定要使用的 Python 的主要版本。 Normally on Linux the first line of a Python3 program would be something like:通常在 Linux 上,Python3 程序的第一行类似于:

#!/usr/bin/python3 

import os
...

Then before importing modules that are in an unusual location you might need to add a line:然后在导入位于不寻常位置的模块之前,您可能需要添加一行:

sys.path.append("/fullpath/to/custom/modules/dir")

then you should be able to import modules that are in that directory.那么您应该能够导入该目录中的模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM