将目录永久添加到 PYTHONPATH? [英] Permanently add a directory to PYTHONPATH?

查看:56
本文介绍了将目录永久添加到 PYTHONPATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我使用 sys.path.append 时,都会添加新目录.但是,一旦我关闭 python,列表将恢复到以前的(默认?)值.如何将目录永久添加到 PYTHONPATH?

Whenever I use sys.path.append, the new directory will be added. However, once I close python, the list will revert to the previous (default?) values. How do I permanently add a directory to PYTHONPATH?

推荐答案

您需要将您的新目录添加到环境变量 PYTHONPATH 中,并用冒号与之前的内容隔开.在任何形式的 Unix 中,您都可以在适合您使用的任何 shell(.profile 或其他,取决于您最喜欢的 shell)的启动脚本中使用命令执行此操作,该命令再次取决于有问题的外壳;在 Windows 中,您可以通过系统 GUI 来实现.

You need to add your new directory to the environment variable PYTHONPATH, separated by a colon from previous contents thereof. In any form of Unix, you can do that in a startup script appropriate to whatever shell you're using (.profile or whatever, depending on your favorite shell) with a command which, again, depends on the shell in question; in Windows, you can do it through the system GUI for the purpose.

superuser.com 可能是进一步询问的更好地方,即如果您需要有关如何在您选择的平台和 shell 中丰富环境变量的详细信息,请查看更多详细信息,因为它不是真正的编程问题本身.

superuser.com may be a better place to ask further, i.e. for more details if you need specifics about how to enrich an environment variable in your chosen platform and shell, since it's not really a programming question per se.

这篇关于将目录永久添加到 PYTHONPATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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