NovFora Dev

help with python script crashing on import sys

Sebastian King

Sebastian King

2 months ago

i dont understand why this is happening -- i just want to read a file and print it out but every time i run my script it says something about an invalid argument or module not found which makes no sense because everything looks right in the folder. could someone tell me what i did wrong? im really stressed about this project being due tomorrow and i cant find anything on google that matches my error message exactly -- should i try reinstalling python entirely or is

Ethan Hughes

Ethan Hughes

2 months ago

import sys should never crash by itself unless you have already monkeypatched sys, remapped builtins.open, or are running in a severely compromised environment (like a malicious wrapper script that replaces standard library modules).

Before debugging further, check:

  1. Circular imports. If this is at the top of file B and file A imports B, you can get bizarre failure modes depending on when sys gets touched.
  2. PYTHONPATH pollution. Run python -c "import sys; print(sys.path)" to see if a local directory named 'sys' or similar is shadowing the standard library.
  3. Bytecode corruption/environment mismatch. If you compiled C extensions against one Python version but are running another, you can get segfaults on startup.

Can you provide the traceback? Knowing whether it fails at import sys vs inside a function that uses sys makes a big difference.

Join the conversation to leave a reply.

Sign in to reply

Related topics