Emmet B
Emmet B

Reputation: 5531

Python3 does not compile source files

I cannot compile with Python 3, i.e. the .pyc files are not generated.

For example:

python -m py_compile test.py

generates test.pyc

Hovewer,

python3 -m py_compile test.py

does not generate test.pyc

test.py

print("hello world")

Why?

Upvotes: 1

Views: 398

Answers (1)

MrRolling
MrRolling

Reputation: 2265

In Python 3, you can find .pyc file in the __pycache__ directory, beside your test.py script.

From terminal:

$ python3 -m py_compile test.py
$ ls __pycache__
 test.cpython-36.pyc

Inside python3

Use py_compile module:

>>> import py_compile
>>> py_compile.compile('test.py')

See: https://docs.python.org/3/library/py_compile.html

Upvotes: 1

Related Questions