Python导入失败与消息:valueError:源代码字符串不能包含null字符

发布于 2025-02-11 18:36:26 字数 240 浏览 2 评论 0原文

我使用M1 MacBook Pro。我的Python程序以前工作开始失败。该程序将在本文标题中的错误消息中失败,在每种情况下,这都是由于程序中的导入语句所致。其他人也提出了类似的问题,但是没有一个答案解决了我的问题。不同的解决方案解决了他们的个人问题。这些解决方案都没有解决我的问题。

我检查了我的模块是否有空字符,没有。有人说问题是Python的口译员。我重新加载了它,但没有解决问题。

我无法想象是什么原因导致了这个新问题。有帮助吗?

I use an M1 MacBook Pro. My Python programs started to fail when they had worked before. The programs would fail with the error message in the title of this post and in each case it was due to an import statement in the program. Others have asked similar questions, but none of the answers solved my problem. Different solutions fixed their individual problems. None of the solutions fixed my problem.

I checked my modules for null characters and there were none. Someone said the problem was the Python interpreter. I reloaded it and that did not fix the problem.

I can't imagine what is causing this new problem. Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

洛阳烟雨空心柳 2025-02-18 18:36:26

事实证明,问题是由于我对模块文件制成的一些别名,以便更容易访问它们。我从文件名中删除了“别名”一词,使其与我保留在.Local文件夹中的模块文件的名称相同。

我将别名文件放在保留程序的文件夹中。显然,从该文件夹运行程序时,Python试图从同一文件夹中发现的别名加载模块。别名文件中有空字符。有些程序也不会在Visual Studio代码IDE中运行。显然,Python在文件夹中使用别名搜索,然后在.local /.../ site-packages文件夹中搜索。我以我的别名文件的名义将“别名”一词放回。解决了问题。

The problem turned out to be due to some aliases I made of the module files in order to have easier access to them. I had removed the word alias from the file names, making them the same as the name of the module files that I keep in the .local folder.

I put the alias files in a folder where I keep my programs. Evidently, when running a program from that folder, Python was trying to load the modules from the aliases it found in the same folder. The alias files have null characters in them. Some programs wouldn't run in Visual Studio Code IDE as well. Evidently Python searched in the folder with the aliases before searching in the .local/.../site-packages folder. I put the word alias back in the name of my alias files. That fixed the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文