简体   繁体   English

修改 sys.path

[英]Modifying sys.path

PYTHON 3.3 I have my HDD partitioned with programmes on "C" and data on "D" one NTFS and the other fat32. PYTHON 3.3 我的硬盘分区有“C”上的程序和“D”上的数据,一个是NTFS,另一个是fat32。 I've downloaded examples of code from one of the popular manuals onto "D".我已将其中一本流行手册中的代码示例下载到“D”上。 Running sys.path does not show these.运行 sys.path 不会显示这些。 I've looked, but cannot find the sys.path file to permanently add my "path".我看过了,但找不到 sys.path 文件来永久添加我的“路径”。 I can have the sys.path come up in IDLE, but making changes here are only temporary I believe.我可以让 sys.path 出现在 IDLE 中,但我相信在这里进行更改只是暂时的。 It is a small irritation to have to "go looking" each time.每次都必须“去看”是一种小烦恼。 I'd really appreciate some comments, and apologize if this has already been answered somewhere else.我真的很感激一些评论,如果已经在其他地方回答了这个问题,我深表歉意。

您可以修改环境变量PYTHONPATH来调整 Python 在导入时查找模块的默认路径。

For instance, to add the directory /home/me/mypy to the path, just do:例如,要将目录 /home/me/mypy 添加到路径中,只需执行以下操作:

import sys导入系统

sys.path.append("/home/me/mypy") sys.path.append("/home/me/mypy")

source: http://www.johnny-lin.com/cdat_tips/tips_pylang/path.html来源: http : //www.johnny-lin.com/cdat_tips/tips_pylang/path.html

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM