.pyc 文件在哪里?

发布于 2024-10-20 02:18:56 字数 149 浏览 2 评论 0原文

我是Python的新手,因此这是一个愚蠢的问题。

据我了解,首次执行 *.py 程序时,字节码会创建到 *.pyc 中并使用,直到 *.py 文件发生更改。

在项目中哪里可以找到这个 *.pyc 字节码?

我会想到 bin,但什么也没有

I am a complete newb to python, hence a silly question.

As i understand, upon first execution of a *.py program, byte code is created into *.pyc and used until a change in *.py file.

Where might this *.pyc bytecode be found in a project?

I would think bin, but nothing is there

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

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

发布评论

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

评论(4

注定孤独终老 2024-10-27 02:18:56

为导入的模块创建一个 *.pyc 文件,并将它们放置在包含 .py 文件的同一目录中。但是...没有为程序的主脚本创建 .pyc 文件。换句话说...如果您在命令行上调用“python myscript.py”,则不会有 myscript.py 的 .pyc 文件。

这就是 Python 2.x 的行为方式。但是,在 Python 3.x 中,.pyc 文件保存在 __pycache__ 目录中。有关详细信息,请参阅 David Glick 的回答。

[编辑:添加了有关 Python 3.x 的注释。]

A *.pyc file is created for imported modules, and they are placed in the same directory containing the .py file. However... no .pyc file is created for the main script for your program. In other words... if you call "python myscript.py" on the command line, there will be no .pyc file for myscript.py.

This is how Python 2.x behaves. However, in Python 3.x the .pyc files are saved in a __pycache__ directory. See David Glick's answer for details.

[edit: Added note about Python 3.x.]

双手揣兜 2024-10-27 02:18:56

在Python中< 3.2、.pyc文件与.py文件放在同一目录下。

在Python 3.2中,编译后的文件放置在__pycache__子目录中,并且根据创建它们的Python解释器而以不同的方式命名。 (这对于从多个版本的 Python 导入相同的 Python 模块的人很有用。)请参阅 http://docs.python.org/dev/whatsnew/3.2.html#pep-3147-pyc-repository-directories 了解更多信息。

In Python < 3.2, the .pyc files are placed in the same directory as the .py file.

In Python 3.2, the compiled files are placed in a __pycache__ subdirectory, and are named differently depending on which Python interpreter created them. (This can be useful to people importing the same Python modules from multiple versions of Python.) See http://docs.python.org/dev/whatsnew/3.2.html#pep-3147-pyc-repository-directories for more information.

女中豪杰 2024-10-27 02:18:56

它们总是在包含的任何目录中创建您的 .py 文件。此外,它们是为导入的模块创建的,而不是为您直接运行的文件创建的。

如果您想创建 .pyc 文件,启动 Python 解释器并导入您选择的模块。

They are always created in whatever directory contains your .py files. Also, they are created for imported modules, not files that you directly run.

If you want to create .pyc files, boot up a Python interpreter and just import the modules of your choosing.

北方的巷 2024-10-27 02:18:56

.pyc 文件通常创建在与其对应的文件相同的目录中。例如,my_file.py 和 my_file.pyc 应该位于同一位置。

The .pyc files are normally created in the same directory as the files that they correspond to. E.g., both my_file.py and my_file.pyc should be in the same location.

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