简体   繁体   English

将 PYTHONPATH 添加到 .zprofile/.bash_profile

[英]Adding PYTHONPATH to .zprofile/.bash_profile

I need to add the contents of a directory called Python with many folders in it containing python scripts to my PYTHONPATH in zsh to allow them to be imported.我需要将名为 Python 的目录的内容添加到我在 zsh 中的 PYTHONPATH 中,其中包含许多包含 python 脚本的文件夹,以允许导入它们。 So far I am planning on using a for loop to iterate through the directories and add the script paths to the PYTHONPATH like so:到目前为止,我计划使用 for 循环遍历目录并将脚本路径添加到 PYTHONPATH,如下所示:

for dir in /Users/will/Python/*

do

... ...

done完毕

if [ -f ~/.zprofile ];如果 [ -f ~/.zprofile ]; then source ~/.zprofile fi然后来源 ~/.zprofile fi

Im not sure what to do next or if this is in any way correct and any help is appreciated.我不确定下一步该做什么,或者这是否正确,并且感谢任何帮助。

You can do你可以做

DIRS=(/Users/will/Python/**) # Store all the subdirectories in this variable
export PYTHONPATH=${(j<:>)DIRS}:$PYTHONPATH  # prepend those subdirectories to PYTHONPATH 

To know more about the prepend syntax see this要了解有关前置语法的更多信息,请参阅

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

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