pyc

How to find out the magic number for the .pyc header in Python 3

好久不见. 提交于 2021-02-07 11:26:16
问题 Python bytecode (.pyc) files have a header that starts with a magic number that changes between Python versions. How can I (programmatically) find out that number for the current Python version in order to generate a valid header? I'm currently hard-coding the one for Python 3.7.1, but that means I now depend on a specific Python version. This answer does exactly what I want using py_compile.MAGIC , but that does not seem to exist anymore in Python 3. How can I do the equivalent in Python 3?

Cant seem to decompile “PYC” After running it through pyinstxtractor

半城伤御伤魂 提交于 2021-01-27 13:54:54
问题 pyinstxtractor runs to completion without problem, and then suggests to decompress the PYC to get the final .PY file (my goal) However when I tried to use uncompyle2, uncompyle6, and plethora of other tools none of them worked. (Magic Number Mismatch!) Which means that the file outputted is not a .PYC file... I opened the outputted file with a hex editor and I can see the source code decoded from hex however Im not able to extract that code in an efficient manner.. It's filled with .'s which

py文件编译为pyc

不打扰是莪最后的温柔 提交于 2020-03-01 01:50:27
什么是pyc文件 pyc是一种二进制文件,是由py文件经过编译后,生成的文件,是一种byte code,py文件变成pyc文件后,加载的速度有所提高,而且pyc是一种跨平台的字节码,是由python的虚拟机来执行的,这个是类似于JAVA或者.NET的虚拟机的概念。pyc的内容,是跟python的版本相关的,不同版本编译后的pyc文件是不同的,2.5编译的pyc文件,2.4版本的python是无法执行的。 为什么需要pyc文件 这个需求太明显了,因为py文件是可以直接看到源码的,如果你是开发商业软件的话,不可能把源码也泄漏出去吧?所以就需要编译为pyc后,再发布出去。当然,pyc文件也是可以反编译的,不同版本编译后的pyc文件是不同的,根据python源码中提供的opcode,可以根据pyc文件反编译出py文件源码,网上可以找到一个反编译python2.3版本的pyc文件的工具,不过该工具从python2.4开始就要收费了,如果需要反编译出新版本的pyc文件的话,就需要自己动手了(俺暂时还没这能力^--^),不过你可以自己修改python的源代码中的opcode文件,重新编译python,从而防止不法分子的破解。 生成单个pyc文件 python就是个好东西,它提供了内置的类库来实现把py文件编译为pyc文件,这个模块就是 py_compile 模块。 使用方法非常简单,如下所示

importing a module in Idle shell

巧了我就是萌 提交于 2020-01-12 15:52:14
问题 I'm trying to learn python and I'm having trouble importing a module. I have a .pyc file that I'm trying to import into idle shell called dfa.pyc I have the file in a folder called xyz. I navigate to this folder using: os.chdir('/Users/xxx/Desktop/xyz') So now, if I try to run the command: from dfa import * i get the error: ImportError: No module named dfa If i run the command: os.path.isfile('dfa.pyc') it returns true. Can someone explain how i can get the dfa.pyc file imported? Thanks 回答1:

Changing the directory where .pyc files are created

痞子三分冷 提交于 2019-12-28 13:41:38
问题 Is there a way to change the directory where .pyc file are created by the Python interpreter? I saw two PEPs about that subject (0304 and 3147), but none seems to be implemented in the default interpreter (I'm working with Python 3). Did I miss something ? 回答1: There's no way to change where the .pyc files go. Python 3.2 implements the __pycache__ scheme whereby all the .pyc files go into a directory named __pycache__ . Python 3.2 alpha 1 is available now if you really need to keep your

Changing the directory where .pyc files are created

不问归期 提交于 2019-12-28 13:41:13
问题 Is there a way to change the directory where .pyc file are created by the Python interpreter? I saw two PEPs about that subject (0304 and 3147), but none seems to be implemented in the default interpreter (I'm working with Python 3). Did I miss something ? 回答1: There's no way to change where the .pyc files go. Python 3.2 implements the __pycache__ scheme whereby all the .pyc files go into a directory named __pycache__ . Python 3.2 alpha 1 is available now if you really need to keep your

Remove .pyc files from Git remote repository

被刻印的时光 ゝ 提交于 2019-12-20 08:24:21
问题 Accidentally, I have pushed the .pyc files to the master repository. Now I want to delete them but I can´t do it. Is there any way to remove them directly from the Bitbucket site? 回答1: Remove .pyc files using git rm *.pyc . If this not work use git rm -f *.pyc Commit git commit -a -m 'all pyc files removed' Push git push In future commits you can ignore .pyc files by creating a .gitignore file 回答2: No, you cannot delete them directly from the BitBucket interface but you can delete them in

How to run a Python project using __pycache__ folder?

北慕城南 提交于 2019-12-18 17:55:44
问题 I want to run a Pythonic project using Python compilation ( .pyc or __pycache__ ). In order to do that in Python2 , I haven't any problem. Here is a simplified example in a Python2 project: Project tree: test2 ├── main.py └── subfolder ├── __init__.py └── sub.py Compile: python -m compileall test2 Project tree after the compile: test2 ├── main.py ├── main.pyc └── subfolder ├── __init__.py ├── __init__.pyc ├── sub.py └── sub.pyc As you can see, several .pyc manually generated. Now I can run

Python pyc possible when power cycling?

被刻印的时光 ゝ 提交于 2019-12-12 17:30:45
问题 Wondering if python is able to institute checks within their compile-phase of a given py to pyc to guard against a corrupt pyc due to sudden power-down of the system(and disk). When the system comes back up will the pyc that may exist be checked for integrity and if its considered suspect, regenerated? 回答1: As far as I know, the compile-to-bytecode process works the same as normal make in how it handles recompilation; it checks if the compiled files are older than the source files, and if

How do virtual machines render GUI?

ぃ、小莉子 提交于 2019-12-12 04:53:13
问题 So I have been doing a lot of reading about execution environments (Python's, JVM...) and I am starting to implement one on my own. It is a register-based environment written in C. I have a basic byte code format defined and the execution is going pretty smooth so far. My question is how does VEs render GUIs. In a more detailed description about my work so far, my VE has a screen buffer (experimenting with it). Every time I poke it, I output the screen buffer completely to know the output. So