gpt4 book ai didi

python - "import site' 失败;使用 -v 进行回溯”- mac os lion,python 2.7,子进程

转载 作者:太空宇宙 更新时间:2023-11-04 06:25:33 25 4
gpt4 key购买 nike

我正在尝试在 python 中运行一个子进程,这是我的代码的一部分:

def update(self):
currentTime = strftime("%d.%m.%y %H:%M", gmtime()) #strftime("%d-%m-%y %H:%M", gmtime)
resultString = "======== " + currentTime + " ========\n\n"
bzrMergeCommand = "cd %s ; /usr/local/bin/bzr merge" % self._directoryName
print "Getting the updated code from bzr..."
mergeResult = sp.Popen(bzrMergeCommand, shell=True, stdout=sp.PIPE, stderr=sp.PIPE, cwd= self._directoryName)

communicated = mergeResult.communicate()

但它无法运行,这是我遇到的异常:

 'import site' failed; use -v for traceback Traceback (most recent call
last): File "/usr/local/bin/bzr", line 21, in <module>
import os File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py",
line 398, in <module>
import UserDict File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.py",
line 84, in <module>
_abcoll.MutableMapping.register(IterableUserDict) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/abc.py",
line 109, in register
if issubclass(subclass, cls): File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/abc.py",
line 151, in __subclasscheck__
if subclass in cls._abc_cache: File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_weakrefset.py",
line 69, in __contains__
return ref(item) in self.data TypeError: cannot create weak reference to 'classobj' object

我在谷歌上搜索并阅读了很多关于“TypeError: cannot create weak reference to 'classobj' object”的内容: https://stackoverflow.com/questions/7753181/making-my-python-script-executable-causes-a-import-site-failed-use-v-for-tra

这里:https://github.com/pypa/virtualenv/issues/108

有什么想法吗?

最佳答案

出现的错误来自 bzr,而不是您的脚本。尝试运行 python 并输入 import site 如果失败,则您的 python 安装可能有问题。

此外,作为一般规则,除非您有理由在 Popen 中设置 shell=True,否则最好设置 shell=False。

关于python - "import site' 失败;使用 -v 进行回溯”- mac os lion,python 2.7,子进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8635351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com