Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法找到mkdir,未找到文件_Python_Panda3d - Fatal编程技术网

Python 无法找到mkdir,未找到文件

Python 无法找到mkdir,未找到文件,python,panda3d,Python,Panda3d,我在做一个游戏,我做了一个日志系统。它生成一个新目录并在其中生成一个.log文件。 我今天发布了它,却发现它不起作用。这对我来说很好,但对其他人来说却不行。我试过makedirs,但没用。代码如下: if not os.path.exists('C:/ToontownRebuilt/src/user/logs/'): os.mkdir('C:/ToontownRebuilt/src/user/logs/client') self.notify.info('Made new dir

我在做一个游戏,我做了一个日志系统。它生成一个新目录并在其中生成一个.log文件。 我今天发布了它,却发现它不起作用。这对我来说很好,但对其他人来说却不行。我试过makedirs,但没用。代码如下:

if not os.path.exists('C:/ToontownRebuilt/src/user/logs/'):
    os.mkdir('C:/ToontownRebuilt/src/user/logs/client')
    self.notify.info('Made new directory to save logs.')
这是一个向我报告错误的人得到的回溯:

:ClientStart: Reading user/preferences.json...
Traceback (most recent call last):
File "C:\ToontownRebuilt\src\dependencies\panda\python\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\ToontownRebuilt\src\dependencies\panda\python\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\ToontownRebuilt\src\toontown\toonbase\ClientStart.py", line 94, in <module>
__builtin__.launcher = TTSLauncher()
File "toontown\launcher\TTSLauncher.py", line 34, in __init__
WindowsError: [Error 3] The system cannot find the path specified: 'C:/ToontownRebuilt/src/user/logs/client'

在此问题上的任何帮助都将不胜感激。这让我很沮丧。它对我有效,但对其他人无效。为什么?我怎样才能修好它?另外,如果这个问题不好,你能评论一下如何改进它的一些技巧吗?谢谢D

其他用户可能没有调用的目录

    ToontownRebuilt
    user

缩短为:

    os.mkdir('user/logs/client')
如果路径必须固定,则可以使用try..except语句

if not os.path.exists('C:/ToontownRebuilt/src/user/logs/'):
    try:
         os.mkdir('C:/ToontownRebuilt/src/user/logs/client')
         print('Made new directory to save logs.')
    except:
         print("Unable to create C:/ToontownRebuilt/src/logs/client\nPlease create manually and try again.")

您是否确定您的用户正在运行具有写入和执行权限的脚本/可执行文件?@SeanM这可能是问题所在。我需要试着让他们以管理员的身份运行它。有没有一种简单的方法可以在python脚本中请求管理员权限?解决此问题的最简单方法是尝试…除非Rolf建议,或者制作一个包含所有目录的新安装程序,而不是依赖os.mkdir来创建所需的目录。然后,这将导致无法自己创建日志的错误。通过使用try..除了创建日志之外,我设法为用户修复了它。谢谢大家的帮助看起来它能解决这个问题。至少在一定程度上,他们将能够玩这个游戏。明天他们会醒着,我会告诉你这对他们是否有效。这非常有效。我和他们在制作日志时也犯了同样的错误,所以这也很好。这并不能解决问题,它只是打印一条自定义错误消息…@Sindarus是的,它会这样做,并通知用户如何解决问题。也许您有一个解决方案,可以在不知道管理员密码的情况下解决权限问题。如果是这样的话,我很想看一看,你愿意发布你自己的答案吗?他们会的,因为我制作了一个提取到C:\的安装程序。它对我有效,所以应该对他们有效,但事实并非如此。不过,谢谢你投了2美分。
if not os.path.exists('C:/ToontownRebuilt/src/user/logs/'):
    try:
         os.mkdir('C:/ToontownRebuilt/src/user/logs/client')
         print('Made new directory to save logs.')
    except:
         print("Unable to create C:/ToontownRebuilt/src/logs/client\nPlease create manually and try again.")