首先占坑,准备收录日常遇到的小坑,不能让宝贵的经验白白流失
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
- 注意到CSDN markdwon能够允许使用http anchor来标识图片的对齐方式(alignments)。相对于使用native html,这个显然更加简洁。但是在网上查阅How do I center an image in the README.md file on GitHub?和Markdown and image alignment得知显然不是普适方案,起码需要一个额外的CSS文件。
但是结合html和css,markdwon的布局能力能够得到极大的增强,这显然到更细致的应用层次了,需酌情处理。
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
两个文件,分别位于bin
和lib
目录下。但windows的静态库以lib
后缀,通过后缀区分文件的方法在这里就不适用了。需要查看bin
目录下是否具有同名的.dll
来确定是否为动态库。当然也可以使用其他工具。 - 动态库的组成复杂,包括
dll
、lib
、pdb
等等多个文件。有机会应当摘录一下解释
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