my-macbook:~ aidan$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/path/to/dir', ...
Mathew的答案适用于终端python shell,但在我的例子中,它不适用于空闲shell,因为在我用Python2.7.7替换所有版本之前,已经存在许多版本的python。 我是如何用懒散来解决这个问题的。
cd /Applications/Python\ 2.7/IDLE.app/Contents/Resources/
sudo nano idlemain.py
,如果需要,请输入密码。os.chdir(os.path.expanduser('~/Documents'))
这一行之后,我添加了sys.path.append("/Users/admin/Downloads....")
注意:用要添加python模块的目录替换引号的内容不知道为什么Matthew的解决方案对我不起作用(可能是我正在使用OSX10.8,或者可能与macports有关)。但我在文件末尾添加了以下内容
~/.profile
我的目录现在在pythonpath上-
我可以从那个目录导入模块。
对
sys.path
的修改只适用于该Python解释器的生命周期。如果要永久执行此操作,则需要修改PYTHONPATH
环境变量:注意,
PATH
是可执行文件的系统路径,它是完全独立的。**您可以在
~/.bash_profile
中编写上述内容,并使用source ~/.bash_profile
将其源代码编写出来相关问题 更多 >
编程相关推荐