Python 不解释已更改的文件,使用过时的 .pyc

发布于 2024-10-31 16:24:22 字数 241 浏览 2 评论 0原文

昨天使用 Google App Engine 用 python 进行开发时,它停止运行当前版本的脚本。 即使 .py 源已更改,它似乎也运行以前预编译的 .pyc,而不是执行最新版本。

错误消息实际上引用了最新来源中的正确行。除非该行的位置发生了变化,否则它会引用先前发生错误的位置的行。

删除 .pyc 文件会导致从当前版本重新创建它们。目前删除所有 .pycs 是一个糟糕的解决方法。

我怎样才能找到问题的根本原因?

Using the Google App Engine to develop in python yesterday it stopped running the current version of the script.
Instead of executing the most recent version it seems to run the previously pre-compiled .pyc even if the .py source was changed.

Error messages actually quotes the correct line from the most current source. Except if the position of the line changed, then it quotes the line which is in the place where the error occurred previously.

Deleting .pyc files causes them to be recreated from the current version. Deleting all .pycs is a poor workaround for now.

How can I get to the root cause of the problem?

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

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

发布评论

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

评论(3

太傻旳人生 2024-11-07 16:24:22

你检查过你的系统时钟吗?我相信 python 根据时间戳确定是使用 .pyc 还是 .py。如果您的系统时钟被推迟,那么它会将 .pyc 文件视为较新的文件,直到系统时钟赶上上次构建它们的时间。

Did you check your system clock? I believe python determine whether to use the .pyc or .py based on timestamps. If your system clock got pushed back, then it would see the .pyc files as newer until the system clock caught up to the last time they were built.

追星践月 2024-11-07 16:24:22

您是否在与编译它们的系统不同的系统上编辑 .py 文件?

如果 .py 文件的修改日期比 .pyc 文件的修改日期新,编译器将重新编译 .py 文件。

它选择使用 .pyc 文件这一事实表明您的 .py 文件具有较旧的修改日期。仅当您的 .py 文件在不同的系统上进行修改,然后将其复制到要使用的系统,并且编辑环境/系统的时钟设置在运行时环境/系统的时钟后面时,才有可能实现这一点。

Are you editing the .py files on a different system than where they are being compiled ?

The compiler recompiles the .py files if its modification date is newer than the modification date of the .pyc file.

The fact that it is picking the .pyc file for use points to the fact that your .py file has an older modification date. This is only possible if your .py file is being modified on a different system and then being copied to the one where it is to be used and the editing environment/system's clock is set behind the runtime enviroment/system's clock.

沒落の蓅哖 2024-11-07 16:24:22

以下步骤暂时解决了该问题:

  1. 从“应用程序”文件夹中删除 GoogleAppEngineLauncher。
  2. 重命名文件 ~/Library/Application Support/GoogleAppEngineLauncher/Projects.plist (例如 Project.plist.backup
  3. 重命名文件 ~/Library/Preferences/com.google.GoogleAppEngineLauncher.plist (例如 com.google.GoogleAppEngineLauncher.plist.backup)
  4. 再次下载并安装 Google App Engine Launcher。
  5. 使用“文件”、“添加现有应用程序...”再次添加您的项目,不要忘记设置您之前设置的任何标志,

或者它甚至可以启动 GAEL 一次,然后关闭它。将备份的首选项文件放回原处,以避免重新

配置:事实证明,这暂时解决了这个问题。
奇怪的是,当从命令行运行应用程序服务器时,它可以工作,例如

dev_appserver.py testproject/ -p 8082 --debug

The following steps solved the issue temporarily:

  1. Delete GoogleAppEngineLauncher from your Applications folder.
  2. Rename the file ~/Library/Application Support/GoogleAppEngineLauncher/Projects.plist (e.g. Project.plist.backup
  3. Rename the file ~/Library/Preferences/com.google.GoogleAppEngineLauncher.plist (e.g. com.google.GoogleAppEngineLauncher.plist.backup)
  4. Download and install Google App Engine Launcher again.
  5. Use "File", "Add existing application…" to add your projects again, do not forget to set any flags you had set before.

Alternatively it might even work starting GAEL once, closing it and putting your backed up preference files back into place as to avoid having to reconfigure.

Edit: Turns out that fixes it… temporarily. Not exactly a very easy issue to debug.
Weirdly enough it works when running the appserver from the command line, such as

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