Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么vim中的sys.path与shell中的sys.path不同?_Python_Vim_Macvim - Fatal编程技术网

Python 为什么vim中的sys.path与shell中的sys.path不同?

Python 为什么vim中的sys.path与shell中的sys.path不同?,python,vim,macvim,Python,Vim,Macvim,如果我在vim中执行命令执行“python import sys;print(sys.path)”,我会得到以下路径列表: ['/Users/<myuser>/.vim/bundle/python-mode/pymode/libs', '/Users/<myuser>/.vim/bundle/python-mode', '/Users/<myuser>', '/Users/<myuser>/Library/Python/2.7/lib/python

如果我在vim中执行命令
执行“python import sys;print(sys.path)”
,我会得到以下路径列表:

['/Users/<myuser>/.vim/bundle/python-mode/pymode/libs', '/Users/<myuser>/.vim/bundle/python-mode', '/Users/<myuser>', '/Users/<myuser>/Library/Python/2.7/lib/python/site-packages', '/usr/local/Cellar/python/2.7
.14_3/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.14_3/Framework
s/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.14_3/Framew
orks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/pytho
n/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/usr/local/Cellar/pyt
hon/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '_vim_path_']
使用
python
,列表如下:

['', '/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg', '/Library/Python/2.7/site-packages/percol-0.2.1-py2.7.egg', '/Library/Python/2.7/site-packages/cmigemo-0.1.6-py2.7.egg', '/Library/Python/2.7/site-packages/six-1.11.0-py2.7.egg', '/Library/Python/2.7/site-packages', '/Users/shizhz', '/Users/shizhz/Library/Python/2.7/lib/python/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']
这让我感到困扰的原因是我正在用vim中的设置python环境,但由于vim中python的
sys.path
不包含所有python库的完整列表路径(例如
/Library/python/
下的目录),这使得自动完成对于某些第三方库不起作用。例如,
请求
位于我的计算机上的
/Library/Python/2.7/site packages/
,但当我在键入时尝试触发自动完成时,什么也没有发生(即使手动使用
C-X C-O
),当我执行
执行“Python showdbg()”
时,调试消息是:

DBG: source: import requests
class _PyCmplNoType:
    def __getattr__(self,name):
        return None

DBG: parser: <type 'exceptions.ImportError'>, No module named requests
DBG: locals: <type 'exceptions.ImportError'>, No module named requests [import requests]
DBG: get_completions('request.','')
DBG: completion: <type 'exceptions.NameError'>,name 'request' is not defined [stmt='request']
DBG:source:导入请求
类_PyCmplNoType:
def _ugetattr _;(self,name):
一无所获
DBG:解析器:,没有名为请求的模块
DBG:locals:,没有名为requests的模块[导入请求]
DBG:get_completions('请求','')
DBG:completion:,未定义名称“request”[stmt='request']
但是,如果我将
/Library/Python/2.7/site packages/
附加到
sys.path
,它将非常有效。然后我的问题

  • 为什么这两个列表不同,vim如何初始化sys.path
  • 在vim中添加所有python库位置的最佳实践是什么

shell中的
python
(而不是
bpython
)有什么好处?嗨@cdarke,我在问题中添加了
python
列表。
DBG: source: import requests
class _PyCmplNoType:
    def __getattr__(self,name):
        return None

DBG: parser: <type 'exceptions.ImportError'>, No module named requests
DBG: locals: <type 'exceptions.ImportError'>, No module named requests [import requests]
DBG: get_completions('request.','')
DBG: completion: <type 'exceptions.NameError'>,name 'request' is not defined [stmt='request']