个人日常踩坑小结

首先占坑,准备收录日常遇到的小坑,不能让宝贵的经验白白流失

Python

  • Vscode: goto definition 跳转到 stub文件(.pyi) (220722)
    起初认为是插件故障,实际上的确有过该类故障,不过是21年的事了。最终找到了一个相同的issue,发现十分简单,因为没有对应的python源码,对应的实现为.c,此时pylance默认跳转到stubs
  • 导入logging标准库时出现「circular import」,原因为当前目录的token.py与导入路径的标准库重名,被优先查找。更换命名即可

    ImportError: cannot import name ‘NullHandler’ from partially initialized module ‘logging’ (most likely due to a circular import)

  • 直接从dict构建类。Python允许kwargs作为参数,但当出现不存在的kv对时,就会产生TypeError: unexpected keyword argument。解决方法有:
    • 使用__init__(posotional_args, /, kv_args, **kvs)收集多余的kv对
    • 使用构造函数的模式,from_dict,一个定义如下,参考回答
      class X:
      	@classmethod
      	def from_dict(cls, data):
      	    return cls(
      	        **{
      	            key: (data[key] if val.default == val.empty else data.get(key, val.default))
      	            	for key, val in inspect.signature(cls).parameters.items()
      	        }
      	    )
      
  • 关于 Optional[T]Type annotation 在代码提示中报类似于type None doesn't implement foo的错误,而实际上在此处应当只是类型T。根据回答,消除该错误的方法有很多,原则上有两种:
    • 使用上下文将类型为None的语义消除,具体地例如:
    # 使用「assert」消除None的可能性
    assert var is not None
    var.foo()
    # 使用「exception」
    if var is None:
        raise RuntimeError("NO")
    var.foo()
    # 使用「if」
    if var is not None:
        var.foo()
    # 「type.cast」优点是没有运行时消耗
    var = cast(T, var)
    
    • 停用特定行的type checker功能,缺点是可能会影响后续的检查能力
    var : Optional[T]
    var.foo()  # type: ignore
    

Markdown

MAC

  • 「关于本机>存储空间」中System部分的内存占用超过80G?根据这个回答,System部分是所有没有归类为其他类型的所有种类的数据的总称,因此该部分的数据比较复杂,原因可能来自各个方面,例如备份、Homebrew等。总之,慢慢再看看吧。
  • 升级build-tools版本失配,导致clang无法使用。升级为Monterey 12.6后,运行clang后,出现
    022-09-17 09:38:54.865 xcodebuild[66371:2256936] [MT] DVTPlugInLoading: Failed to load code for plug-in com.apple.dt.IDESimulatorAvailability (/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin), error = Error Domain=NSCocoaErrorDomain Code=3588 "dlopen(/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability, 0x0109): Symbol not found: (_OBJC_CLASS_$_SimDiskImage)
      Referenced from: '/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability'
      Expected in: '/Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/CoreSimulator'" UserInfo={NSLocalizedFailureReason=The bundle couldn’t be loaded., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability, NSDebugDescription=dlopen(/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability, 0x0109): Symbol not found: (_OBJC_CLASS_$_SimDiskImage)
      Referenced from: '/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability'
      Expected in: '/Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/CoreSimulator', NSBundlePath=/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin, NSLocalizedDescription=The bundle “IDESimulatorAvailability” couldn’t be loaded.}, dyldError = dlopen(/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability, 0x0000): Symbol not found: (_OBJC_CLASS_$_SimDiskImage)
      Referenced from: '/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability'
      Expected in: '/Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/CoreSimulator'
    2022-09-17 09:38:54.936 xcodebuild[66371:2256936] [MT] DVTAssertions: ASSERTION FAILURE in /System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot2/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/DVTFrameworks/DVTFrameworks-21303/DVTFoundation/PlugInArchitecture/DataModel/DVTPlugIn.m:374
    Details:  Failed to load code for plug-in com.apple.dt.IDESimulatorAvailability (/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin)
    Please ensure Xcode packages are up-to-date — try running 'xcodebuild -runFirstLaunch'.
    
    显得十分复杂。不过方法也给出了提示:xcodebuild -runFirstLaunch,应该是一个比较通用的解决开发工具版本不适配的问题。
  • brew安装的java包运行错误@@HOMEBREW_JAVA@@/bin/java: No such file or directory。原因是从瓶子镜像安装依赖于 Java 的公式目前无法正常工作,brew需要清单才能正确替换@@HOMEBREW_JAVA@@。尝试重置HOMEBREW_BOTTLE_DOMAIN
    HOMEBREW_BOTTLE_DOMAIN= brew reinstall pdftk-java
    
  • brew版本更新问题,reset homebrew-core tap to the latest version —— brew update-reset

Visual Studio

  • 动态库与静态库的后缀混淆。在windows下,动态库DLL并不是一个单独的文件,而是至少包括.dll.lib两个文件,分别位于binlib目录下。但windows的静态库以lib后缀,通过后缀区分文件的方法在这里就不适用了。需要查看bin目录下是否具有同名的.dll来确定是否为动态库。当然也可以使用其他工具。
  • 动态库的组成复杂,包括dlllibpdb等等多个文件。有机会应当摘录一下解释

Haskell

  • 调用signum -1时报错:Non type-variable argument in the constraint: Num (a -> a),根据回答另一个
    • Num (a->a)表示代码试图使用一个a->a类型的值匹配Num类型 ,产生错误
    • Haskell函数调用具有最高优先级,因此实际的调用是(signum -) 1,自然产生了错误,正确的调用为signum (-1)
  • 总的说,haskell中的负数一般都使用(-N)的形式,即使这样,-本来是一个二元运算符,这里也是特殊情况了。
  • vscode jupyter拓展更换Haskell kernel,在命令行可以验证安装完整性,在拓展却一直失效,jupyter ouput显示总在尝试下载另一个版本的GHC。经过长久的摸索后,根据Ihaskell最后一栏的提示:
    The kernel keeps dying (IHaskell + Stack)

    The default instructions globally install IHaskell with support for only one version of GHC. If you’ve e.g. installed an lts-10 IHaskell and are using it with an lts-9 project the mismatch between GHC 8.2 and GHC 8.0 will cause this error. Stack also has the notion of a ‘global project’ located at ~/.stack/global-project/ and the stack.yaml for that project should be on the same LTS as the version of IHaskell installed to avoid this issue.

    看来是haskell对于版本依赖的要求较严格,而stack管理器存在global project的概念,需要和ihaskell的编译版本保持一致。

Ubuntu

  • 尝试用apt安装“本地应用”失败。在使用不同版本的库软件的场景下(使用旧版的openssl),直接使用apt安装会导致版本降级,影响系统软件的使用,但尝试下载deb包后安装到本地目录出现了各种问题,因此记录最直接的方法,从源码安装,一般为:
    apt-get source <package_name> && cd <source_name>
    less REDAME && less INSTALL  # 检查一遍总没问题
    ./configure --prefix=<local_dir> shared # 确保默认为动态库
    make && make test && make install
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值