英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论