添加到python path mac os x [英] Add to python path mac os x

查看:448
本文介绍了添加到python path mac os x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想

import sys
sys.path.append("/home/me/mydir")

正在将目录附加到我的pythonpath

is appending a dir to my pythonpath

如果我打印sys.path,我的目录就在其中.

if I print sys.path my dir is in there.

然后我打开一个新命令,它不再存在.

Then I open a new command and it is not there anymore.

但是Python不能以某种方式导入我保存在该目录中的模块.

But somehow Python cant import modules I saved in that dir.

我在做什么错了?

我阅读了.profile或.bash_profile将解决问题.

I read .profile or .bash_profile will do the trick.

我是否必须添加:

PATH="/Me//Documents/mydir:$PYTHONPATH"
export PATH

要使其正常工作?

推荐答案

sys.path的修改仅适用于该Python解释器的生命.如果要永久执行此操作,则需要修改PYTHONPATH环境变量:

Modifications to sys.path only apply for the life of that Python interpreter. If you want to do it permanently you need to modify the PYTHONPATH environment variable:

PYTHONPATH="/Me/Documents/mydir:$PYTHONPATH"
export PYTHONPATH

请注意,PATH是可执行文件的系统路径,它是完全独立的.

Note that PATH is the system path for executables, which is completely separate.

**您可以在~/.bash_profile中编写以上内容,并使用source ~/.bash_profile

**You can write the above in ~/.bash_profile and the source it using source ~/.bash_profile

这篇关于添加到python path mac os x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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