“没有发现错误”模块。试图调用另一个目录中的函数

发布于 2025-02-04 02:05:51 字数 2386 浏览 4 评论 0原文

尝试调用该python文件中另一个目录中的yamlcreation()。 该文件的路径是

路径:bss_micro_svcs/bss_micro_svcs/kubectl.py

呼叫文件:“ kubectl.py”

    from bss_micro_svcs.kubectl_utils.templating_to_yaml import yamlCreation
      class Kube(Svcs):
        def startService(self, cluster_info, service, service_profile):
            yamlCreation()
            
    
    k=Kube()
    k.startService()

yamlcreation()函数在此名为“ templating_to_yaml.py”的python文件中 文件的路径是.. 路径:bss_micro_svcs/kubectl_utils/templating_to_yaml.py

function to be called is inside this file:"templating_to_yaml.py"

 
    file_loader = FileSystemLoader('bss_micro_svcs/bss_micro_svcs/yamls/templates')
    env = Environment(loader=file_loader)


    #deployment.yaml templating
    deployment_template=env.get_template('deployment.tmpl')
    deployment_output=deployment_template.render(deployment_name='nginx-deployment',deployment_app='nginx',deployment_replicas='3',deployment_container_name='nginx',deployment_image='nginx:1.14.2',deployment_container_port=80)


    deployment_outfile=open('bss_micro_svcs/bss_micro_svcs/yamls/services/integration/deployment.yaml','w')
    deployment_outfile.write(deployment_output)
    deployment_outfile.close()


    #*********************************************************************************************************************************************************#

    #service.yaml templating
    service_template=env.get_template('services.tmpl')
    service_output=service_template.render(service_name='integration-service',service_name_space='demo-sandbox',service_app='integration',service_port=8090,target_port=8090)

    service_outfile=open('bss_micro_svcs/bss_micro_svcs/yamls/services/integration/services.yaml','w')
    service_outfile.write(service_output)
    service_outfile.close()

出现错误:

┌──(bss_micro_svcs-jnO67Li7)(RK㉿kali)-[~/Desktop/servicelaunchmgr]
└─$ /home/RK/.local/share/virtualenvs/bss_micro_svcs-jnO67Li7/bin/python /home/RK/Desktop/servicelaunchmgr/bss_micro_svcs/bss_micro_svcs/kubectl.py
Traceback (most recent call last):
  File "/home/RK/Desktop/servicelaunchmgr/bss_micro_svcs/bss_micro_svcs/kubectl.py", line 2, in <module>
    from bss_micro_svcs.kubectl_utils.templating_to_yaml import yamlCreation
ModuleNotFoundError: No module named 'bss_micro_svcs'

Trying to call a function yamlCreation() which is in another directory into this python file ..
the path of this file is

path:bss_micro_svcs/bss_micro_svcs/kubectl.py

Calling File: "kubectl.py"

    from bss_micro_svcs.kubectl_utils.templating_to_yaml import yamlCreation
      class Kube(Svcs):
        def startService(self, cluster_info, service, service_profile):
            yamlCreation()
            
    
    k=Kube()
    k.startService()

yamlCreation() function is in this python file named "templating_to_yaml.py"
the path of the file is..
path:bss_micro_svcs/kubectl_utils/templating_to_yaml.py

function to be called is inside this file:"templating_to_yaml.py"

 
    file_loader = FileSystemLoader('bss_micro_svcs/bss_micro_svcs/yamls/templates')
    env = Environment(loader=file_loader)


    #deployment.yaml templating
    deployment_template=env.get_template('deployment.tmpl')
    deployment_output=deployment_template.render(deployment_name='nginx-deployment',deployment_app='nginx',deployment_replicas='3',deployment_container_name='nginx',deployment_image='nginx:1.14.2',deployment_container_port=80)


    deployment_outfile=open('bss_micro_svcs/bss_micro_svcs/yamls/services/integration/deployment.yaml','w')
    deployment_outfile.write(deployment_output)
    deployment_outfile.close()


    #*********************************************************************************************************************************************************#

    #service.yaml templating
    service_template=env.get_template('services.tmpl')
    service_output=service_template.render(service_name='integration-service',service_name_space='demo-sandbox',service_app='integration',service_port=8090,target_port=8090)

    service_outfile=open('bss_micro_svcs/bss_micro_svcs/yamls/services/integration/services.yaml','w')
    service_outfile.write(service_output)
    service_outfile.close()

GETTING AN ERROR:

┌──(bss_micro_svcs-jnO67Li7)(RK㉿kali)-[~/Desktop/servicelaunchmgr]
└─$ /home/RK/.local/share/virtualenvs/bss_micro_svcs-jnO67Li7/bin/python /home/RK/Desktop/servicelaunchmgr/bss_micro_svcs/bss_micro_svcs/kubectl.py
Traceback (most recent call last):
  File "/home/RK/Desktop/servicelaunchmgr/bss_micro_svcs/bss_micro_svcs/kubectl.py", line 2, in <module>
    from bss_micro_svcs.kubectl_utils.templating_to_yaml import yamlCreation
ModuleNotFoundError: No module named 'bss_micro_svcs'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

古镇旧梦 2025-02-11 02:05:52

您可以设置环境变量PythonPath,以便解释器可以知道在哪里开始寻找要导入的模块。我建议将其设置在根模块中。

参考: https://bic-berkeley.github.io/ Psych-214-Fall-2016/used_pythonpath.html

You could set environment variable PYTHONPATH so the interpreter could know where to start looking for the module to import. I would suggest to set it in the root module.

Reference: https://bic-berkeley.github.io/psych-214-fall-2016/using_pythonpath.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文