微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 PEP582 和 ipykernel 进行搜索路径的 VSCode 设置

如何解决使用 PEP582 和 ipykernel 进行搜索路径的 VSCode 设置

我使用了支持 PEP582 的 python 包管理器 (PyFlow/PDM):包安装在本地目录 {workspace_path}/__pypackages__/ 中。

我在 settings.json添加了一些配置,让 VSCode 知道如何找到包:

{
  ...,"python.autoComplete.extraPaths": [
    "__pypackages__/3.7lib"
  ],"python.analysis.extraPaths": [
    "__pypackages__/3.7/lib"
  ]
}

我写了一些代码,完成和内联代码文档在上述设置下运行良好。

# main.py
#%% jupyter cell
import sys
print(sys.path)
import pandas as pd
print(pd.__version__)
#%% 
print("hello world")

我以两种方式运行我的 main.py

  • 使用 VSCode (ctrl + opt + N) 运行文件
  • 运行 jupyter cell with ipykernel (shift + enter)。 VSCode 第一次让我安装 ipykernel,结果是用 pip 安装的,没有安装到 __pypackages__

但它失败并显示ModuleNotFoundError: No module named 'pandas'

我使用 sys.path 检查搜索路径,它不包含 __pypackages__ 用于 Python 模块:

['{$HOME}/{workspace}','{$HOME}/.vscode/extensions/ms-toolsai.jupyter-2021.5.745244803/pythonFiles','{$HOME}/.vscode/extensions/ms-toolsai.jupyter-2021.5.745244803/pythonFiles/lib/python','{$HOME}/.pyenv/versions/3.7.10/lib/python37.zip','{$HOME}/.pyenv/versions/3.7.10/lib/python3.7','{$HOME}/.pyenv/versions/3.7.10/lib/python3.7/lib-dynload','','{$HOME}/{workspace}/.venv/lib/python3.7/site-packages','{$HOME}/{workspace}/.venv/lib/python3.7/site-packages/IPython/extensions','{$HOME}/.ipython']

我的问题:

  • 如何配置 settings.json添加 Python 模块的搜索路径 (__pypackages__/3.7lib)。
  • 如何配置 settings.json 以让 VSCode Jupyter 服务器在 __pypackages__/3.7lib 中安装了 ipykernel 的情况下启动 IPython

解决方法

Dim olApp As Outlook.Application
Dim oDialog As SelectNamesDialog
Dim oGAL As AddressList
Dim myAddrEntry As AddressEntry
Dim exchUser As Outlook.ExchangeUser

Dim AliasName As String
Dim FirstName As String
Dim LastName As String
Dim EmailAddress As String

Set olApp = GetObject(,"Outlook.Application")
Set oDialog = olApp.Session.GetSelectNamesDialog
Set oGAL = olApp.GetNamespace("MAPI").AddressLists("Global Address List")

With oDialog
        .AllowMultipleSelection = False
        .InitialAddressList = oGAL
        .ShowOnlyInitialAddressList = True
        If .Display Then
            AliasName = oDialog.Recipients.Item(1).Name
            Set myAddrEntry = oGAL.AddressEntries(AliasName)
            Set exchUser = myAddrEntry.GetExchangeUser

            If Not exchUser Is Nothing Then
                ThisName = exchUser.Name
                FirstName = exchUser.FirstName
                LastName = exchUser.LastName
                EmailAddress = exchUser.PrimarySmtpAddress
                '...
                TextBox1.Value = ThisName
            End If
        End If
    End With
Set olApp = Nothing
Set oDialog = Nothing
Set oGAL = Nothing
Set myAddrEntry = Nothing
Set exchUser = Nothing

在 settings.json 中试试这个

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。