0
main.py如何在导入其他.py文件时运行.pyc文件?
import other
def main():
other.test()
main()
other.py
def test():
print("Hello")
通过使用python3 -m py_compile *.py
,我可以有2个pyc文件。
但是,main.pyc
不能运行,如果有no module named other
,这是我从终端得到的错误。
这个想法是将整个项目从.py
编译到.pyc
,这样人们可以在不共享源代码的情况下运行它们。
那么,如何运行这个main.pyc
其中导入其他库,而不共享源代码?
你试过直接执行other.pyc吗? – georgexsh
其实我试过了。但是,如果在.pyc文件中没有函数调用,你认为会发生什么?请看看上面的other.py文件。即使它转换为.pyc,它里面仍然没有函数调用。 @georgexsh – idontknoooo
这对我有用,你的环境是什么? – georgexsh