PyCharm 无法在导入时看到我新编译的 .pyc 文件。

huangapple go评论67阅读模式
英文:

PyCharm cannot see my newly compiled .pyc see on import

问题

我在使用PyCharm,有一个名为foo.py的文件。foo.py文件中有用户名和密码的base64表示。我正在编译foo.py,以使其对人类不可读。我通过终端运行命令:

python -m py_compile foo.py

我可以在pychache文件夹中看到已编译的.py文件,命名为foo.cpython-39.pyc。

我删除foo.py。

当我添加import foo 这一行时,PyCharm指示找不到该模块。

如果保留foo.py,那么导入行当然没问题。

如果我将.pyc文件从pycache文件夹复制并重命名到根文件夹,并将其命名为foo.pyc,PyCharm仍然指示找不到该模块。

我以前做过这个,所以我知道这是可能的,但显然我漏掉了一步。有人知道可能是什么步骤吗?

英文:

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?

答案1

得分: 2

这可能是缓存问题或配置问题,
你可以尝试清除缓存,选择“文件”,然后选择“无效化缓存/重启”,然后选择“无效化并重启”。
你也可以检查.pyc文件是否在__pycache__目录中。

英文:

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

huangapple
  • 本文由 发表于 2023年3月20日 22:58:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75791899.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定