何时使用sys.path.append和修改%PYTHONPATH%就足够了 [英] When to use sys.path.append and when modifying %PYTHONPATH% is enough

查看:429
本文介绍了何时使用sys.path.append和修改%PYTHONPATH%就足够了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,原来我从PYTHONPATH定义中错过了一个分号。但这只有我到目前为止。由于某种原因,我的脚本没有作为计划任务(在WinXP上),直到我明确地将目录从PYTHONPATH添加到我的脚本的顶部。

So, it turned out i was missing a semi-colon from my PYTHONPATH definition. But this only got me so far. for some reason, my script did NOT work as a scheduled task (on WinXP) until I explicitly added a directory from PYTHONPATH to the top of my script.

问题是:
什么时候我需要明确地附加一些东西到我的路径,什么时候可以只依靠环境变量?

Question is: When do I need to explicitly append something to my path and when can I simply rely on the environment variables?

推荐答案

也许您没有按照正确的凭据(登录名)运行计划的任务。在系统属性对话框中定义环境变量时,它们可以是用户级别还是系统级别。如果您将PYTHONPATH定义为用户级别,那么您的计划任务必须作为该用户运行才能正确设置。我相信使系统级别意味着它将适用于所有用户,除非他们有自己的值定义。

Perhaps you're not running the scheduled task under the right credentials (log-in name). When you define environment variables in System Properties dialog, they can be either User-level or System-level. If you defined PYTHONPATH as User-level then your scheduled task must run as that user for it to be set properly. I believe making it System-level would mean it would apply to all users unless they have their own value defined.

下面是一个屏幕截图,显示了一个环境变量的设置。在Windows XP和Windows 7中都是类似的。右侧对话框的上半部分显示当前的用户级设置,下半部分列出了所有系统级别的设置。

Below is a screenshot showing where one sets environment variables. It's similar in both Windows XP and Windows 7. The top half of the right-hand dialog box shows the current User-level settings, and the bottom half lists all the System-level ones.

如果PYTHONPATH出现在上层用户级别组中的名称列表中,则可以先将其删除,然后将相同名称加上相关联的值添加到下级系统级别组中,从而有效地将其移动到另一个名称列表中。要保存一点打字,您可以在之前编辑用户级变量删除它,以便首先复制其当前值,然后单击取消退出操作。这样,当您制作新系统级副本时,您就可以将复制的值粘贴到其中。

If PYTHONPATH appears in the list of names in the upper User-level group, you can effectively move it to the other lower one by first deleting and then adding one of the same name plus associated value to the lower System-level set. To save a little typing, you can Edit the user-level variable before you Delete it to be given a chance to first copy its current value, then Cancel-out of the operation. That way, when you make the New System-level copy you'll be able to simply paste the copied value into it.

这篇关于何时使用sys.path.append和修改%PYTHONPATH%就足够了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆