简体   繁体   English

如何调用存储在我的网络上的不同 python 脚本?

[英]How can I call a different python script that is stored on my network?

I have a TKinter script that lets the user choose from a list of existing scripts, input the variables that particular script requires, and then passes the variables to that script to be run.我有一个 TKinter 脚本,它允许用户从现有脚本列表中进行选择,输入特定脚本所需的变量,然后将变量传递给要运行的脚本。 When all files are stored locally it goes off without a hitch.当所有文件都存储在本地时,它会顺利运行。 Once I tried to move it onto the network, so that colleagues can use it, it stopped executing the script.一旦我试图将它移动到网络上,以便同事可以使用它,它就停止执行脚本。

There is no error message, just nothing happens.没有错误消息,只是没有任何反应。 For troubleshooting simplicity I wrote a simple script that just calls a second script that prints "success", and the same issue happens where the simple scripts work locally, but not when stored on the network.为了简化故障排除,我编写了一个简单的脚本,它只调用打印“成功”的第二个脚本,同样的问题发生在简单脚本在本地工作的情况下,但在存储在网络上时不会发生。

Script1.py:脚本1.py:

import os
path=r'G:/files/Script2.py'
os.system(path)

Script2.py:脚本2.py:

print("success")

No error messages, and if I try os.path.exists(path) it returns "True".没有错误消息,如果我尝试 os.path.exists(path) 它返回“True”。

os.system(path) returns no errors even when the path is known to be incorrect.即使已知路径不正确,os.system(path) 也不会返回任何错误。

If I do try open(path) for a path that is actually incorrect I get: FileNotFoundError: [Errno 2] No such file or directory.如果我尝试 open(path) 一个实际上不正确的路径,我会得到: FileNotFoundError: [Errno 2] 没有这样的文件或目录。

I also tried setting path equal to the global drive name instead of G, using the IP address, changing the direction of the slashes, putting in double slashes after G:, and not using r''.我还尝试设置路径等于全局驱动器名称而不是 G,使用 IP 地址,更改斜杠的方向,在 G: 后放置双斜杠,而不是使用 r''。 Everything gives me the same result.一切都给了我相同的结果。

I also tried using path=os.getcwd()+"//Script2.py" since currently the files are all in the same folder on the network, again no success.我也尝试使用 path=os.getcwd()+"//Script2.py" 因为目前这些文件都在网络上的同一个文件夹中,同样没有成功。

I am currently accessing the network through a VPN from home.我目前正在通过家中的 VPN 访问网络。

From googling I came up with these, but couldn't get a solution from them either:通过谷歌搜索,我想出了这些,但也无法从他们那里得到解决方案:

Accessing a network folder through a python program Using Python, how can I access a shared folder on windows network? 通过python程序访问网络文件夹使用Python,如何访问windows网络上的共享文件夹?

use a python3 or python keyword before之前使用 python3 或 python 关键字

os.system("sudo python3 {}".format(path))

or:或者:

os.system(f"sudo python3 {path}")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python-如何在IDE中使用不同的命令行参数调用脚本? - Python - How can i call the script with different command line arguments from within my IDE? 如何为网络中的不同节点分配不同的颜色? - How can I assign different colors to different nodes in my network? 如何改善循环Python脚本,在每个循环中针对不同条件涉及不同的数学运算? - How can I improve my looping Python script, involving different mathematical operations for different conditions on each loop? 如何从python脚本调用python脚本 - How can I call a python script from a python script 如何在服务器上托管 function,我可以从我的 python 脚本调用它? - How do I host a function on a server, which I can call from my python script? 如何从 Python 脚本中创建存储过程? - How can I create stored procedure from within Python script? 我如何从后缀服务器中获取我的别名,然后调用一个调用python程序的shell脚本? - How can I have my alias from a postfix server call a shell script that calls a python program? 如何重新启动python 3脚本? - How can I restart my python 3 script? 如何从不同的脚本调用方法? (Python) - How do I call a method from a different script? (Python) 在Github中,我可以从存储库之外的其他仓库运行python脚本吗? - In Github, can I run a python script from a different repo than where it's stored?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM