This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Windows line endings of pyc file detected on Ubuntu
Type: Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: serhiy.storchaka, vladinko0
Priority: normal Keywords:

Created on 2020-03-17 12:09 by vladinko0, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg364417 - (view) Author: Vladimir (vladinko0) Date: 2020-03-17 12:09
I have problem to run pyc file on one machine with Ubuntu Server 18.04.4 LTS.

This is my source code of the file:

#!/root/PycharmProjects/Project/venv/bin/python3.7
print("Hi")

When I compile it in python console with commands:

import py_compile
py_compile.compile('test2.py')

I get test2.cpython-37.pyc file. Then I add execution access by

chmod +x test2.cpython-37.pyc

If I run

./test2.cpython-37.pyc

on first machine (Ubuntu Server 18.04.4 LTS) I get simple "Hi".

But if I run similarly compiled file on other machine with the same OS - Ubuntu Server 18.04.4 LTS, I get:

./test2.cpython-37.pyc: line 1: $'B\r\r': command not found
./test2.cpython-37.pyc: line 2: syntax error near unexpected token `)'
./test2.cpython-37.pyc: line 2: `z�p^=�@s
                                          ed�dS)ZHiN)�print�rrtest2.py<module>�'

It looks like it is reading Windows line endings. But why? It is created, compiled and run on Ubuntu machine.

How can I solve this issue, and run this pyc file with the right result on second machine?
msg364419 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-03-17 12:26
pyc files are not executable files. If you can run it on your machine it means that you have installed some loader hook which allow you to run files which are not machine executable files and not shell scripts. It seems it is not installed on your other machine. This hook is not a part of Python. You have to find what additional software is installed on your first machine and install the necessary parts on your other machine.
History
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84173
2020-03-17 12:26:59serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg364419

resolution: third party
stage: resolved
2020-03-17 12:09:46vladinko0create