1

I'm using PyCharm and I have file foo.py. foo.py has a username and base64 representation of a password inside of it. I'm compiling foo.py so it's no longer readable by human eyes.

I'm running a command via the terminal

python -m py_compile foo.py

I can see the compiled .pyc file in the pychache folder named foo.cpython-39.pyc.

I remove foo.py.

When I add the line import foo, PyCharm indicates it cannot find the module.

If foo.py is retained, then of course the import line is fine.

If I copy and rename the .pyc file from the pycache folder to the root folder, calling it foo.pyc, PyCharm still indicates that it cannot find the module.

I have done this before so I know it's possible, but there is obviously a step I'm missing. Does anyone have any idea what that might be?

Dan
  • 97
  • 1
  • 7
  • Not directly related, but I'm not sure it's safe to just compile file to pyc. You can decompile it (See https://stackoverflow.com/a/59608342/15923186 ). – Gameplay Mar 20 '23 at 15:08
  • 1
    It's for local testing, not productionised code. It's just a way to ensure if anyone's watching a screenshare that there's absolutely no chance a plain text password can be seen. – Dan Mar 20 '23 at 15:13

1 Answers1

2

It is a cache issue or maybe a configuration issue,

You could try to clear the cach, go File then Invalidate Caches / Restart... then Invalidate and Restart

You can also check that the .pyc files are in the pycache directory

Saxtheowl
  • 4,136
  • 5
  • 23
  • 32
  • Looks like clearing the cache may have solved the issue as I didn't touch the file system while doing that. Or, the reboot that PyCharm does was what solved it. In any case I now have no "foo.py" file but a working import module. Thanks. – Dan Mar 20 '23 at 15:17
  • You welcome :) dont forget to validate the answer if you think it fixed your problem – Saxtheowl Mar 20 '23 at 15:32