Why does my python script break after compiling?

rangeme

I'm checking out how much of a performance increase I get after compiling a python script. After research looking into this issue I don't think I will actually see an increase in performance with the script I have written because I found out that once the script is loaded, the execution time doesn't increase. I still would like to know why this is failing to run after compiling as this is my first time trying this. Here is my script

#!/bin/python3
from datetime import datetime
start = datetime.now()

import psutil

BYTES_PER_GB = 1024*1024*1024

# Memory
m = psutil.virtual_memory()
#total = m.total/BYTES_PER_GB 
#available = m.available/BYTES_PER_GB
#used = m.used/BYTES_PER_GB
m_free= m.free/BYTES_PER_GB
m_percent = m.percent

# Swap
s = psutil.swap_memory()
s_free = s.free/BYTES_PER_GB
s_percent = s.percent

print(' %.1fG (%.1f%%)  %.1fG (%.1f%%)' % (m_free, m_percent, s_free, s_percent))
print(' %.1fG (%.1f%%)  %.1fG (%.1f%%)' % (m_free, m_percent, s_free, s_percent))

print(datetime.now() - start)

I'm trying to compile with this line

python3 -m py_compile memory

In my print statements I have some special characters from font awesome. Not sure if that would cause a problem but if it doesn't show up correctly in my post then that's what that is.

The output when I try to run the compiled file is

./memorycpython-35.pyc: line 1: $'\026\r\r': command not found
./memorycpython-35.pyc: line 2: �k�W��@s�ddlmZej�ZddlZdZej�Zejeej: command not found
./memorycpython-35.pyc: line 3: syntax error near unexpected token `)'
./memorycpython-35.pyc: line 3: `ej
                                �Z
                                  e
e                                      je
 j  Ze�eej�e�dS)�)datetimeNiii@)rZnow�startZpsutilZ
                                                                   BYTES_PER_GBZvirtual_memory�mZfreeZm_freeZpercentZ   m_percentZ
              swap_memory�sZs_freeZ s_percent�print�rr�memory<module>s



       '
   ^[[?62;c^[[?62;c

EDIT

To narrow down the problem I wrote the following script

#!/bin/python3
print("Hello World!")

This is the output

./testcpython-35.pyc: line 1: $'\026\r\r': command not found
./testcpython-35.pyc: line 2: syntax error near unexpected token `)'
./testcpython-35.pyc: line 2: `�r�W%�@sed�dS)z
                                               Hello World!N)�print�rr�./test<module>s'

Compiled using

python3 -m py_compile ./test

This creates a file in __pycache__/ called testcpython-35.pyc which I then do chmod +x testcpython-35.pyc and ./testcpython-35.pyc

rangeme

It appears my issue is the ./testcpython-35.pyc part. When I run python3 testcpython-35.pyc, independent on whether I did chmod +x ./testcpython-35.pyc, the output is scrabbled. As long as I run the compiled program by first specifying what program to run it with, python3, it outputs Hello World! as expected.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

why does RewriteCond %{SCRIPT_FILENAME} !-d break my RewriteRule

From Dev

why does RewriteCond %{SCRIPT_FILENAME} !-d break my RewriteRule

From Dev

Why does my Python script not work at all?

From Dev

Why does my python script delete itself?

From Dev

Why does my UI break after my laptop has turned off the screen because of inactivity?

From Dev

Why does my cross-compiling fail?

From Dev

Why does my script suddenly exit after a command?

From Dev

Why does my shell script exit after changing users?

From Java

Why does adding </script> in a comment break the parser?

From Dev

Why does uint break my for loop?

From Dev

Why does my edit/update route break?

From Dev

Why does my download queue break when called faster after each other?

From Dev

Why does my p-element follow immediately after the last without a break in between?

From Dev

Why does my Python script fail with syntax errors?

From Dev

Why does running my Python script start taking a screenshot?

From Dev

Why does my python multiprocessing script run on Windows but not on Linux?

From Dev

Why does my Python script fail with syntax errors?

From Dev

Why does this python multiprocessing script slow down after a while?

From Dev

Why does inlining my accessors break my code?

From Dev

Why does my AMD CPU have trouble compiling applications?

From Dev

Why my program break after return from other function?

From Dev

Why does Javascript's Date() function break for my birthday in Safari?

From Dev

Why does `log_slow_queries` break `my.cnf`?

From Dev

Why does adding a show/hide feature break my AngularJS code?

From Dev

MongoDB Java client - why does `sort` seem to break my query?

From Dev

Why does my Javascript break in IE8?

From Dev

Why does calling focus() break my CSS transition?

From Dev

Why does my Netbeans debugger break into a commented line of code?

From Dev

Why does cloning a repo break my yii2 app?

Related Related

  1. 1

    why does RewriteCond %{SCRIPT_FILENAME} !-d break my RewriteRule

  2. 2

    why does RewriteCond %{SCRIPT_FILENAME} !-d break my RewriteRule

  3. 3

    Why does my Python script not work at all?

  4. 4

    Why does my python script delete itself?

  5. 5

    Why does my UI break after my laptop has turned off the screen because of inactivity?

  6. 6

    Why does my cross-compiling fail?

  7. 7

    Why does my script suddenly exit after a command?

  8. 8

    Why does my shell script exit after changing users?

  9. 9

    Why does adding </script> in a comment break the parser?

  10. 10

    Why does uint break my for loop?

  11. 11

    Why does my edit/update route break?

  12. 12

    Why does my download queue break when called faster after each other?

  13. 13

    Why does my p-element follow immediately after the last without a break in between?

  14. 14

    Why does my Python script fail with syntax errors?

  15. 15

    Why does running my Python script start taking a screenshot?

  16. 16

    Why does my python multiprocessing script run on Windows but not on Linux?

  17. 17

    Why does my Python script fail with syntax errors?

  18. 18

    Why does this python multiprocessing script slow down after a while?

  19. 19

    Why does inlining my accessors break my code?

  20. 20

    Why does my AMD CPU have trouble compiling applications?

  21. 21

    Why my program break after return from other function?

  22. 22

    Why does Javascript's Date() function break for my birthday in Safari?

  23. 23

    Why does `log_slow_queries` break `my.cnf`?

  24. 24

    Why does adding a show/hide feature break my AngularJS code?

  25. 25

    MongoDB Java client - why does `sort` seem to break my query?

  26. 26

    Why does my Javascript break in IE8?

  27. 27

    Why does calling focus() break my CSS transition?

  28. 28

    Why does my Netbeans debugger break into a commented line of code?

  29. 29

    Why does cloning a repo break my yii2 app?

HotTag

Archive