我创建了一个名为sampleenv
的虚拟环境,但是当我在sampleenv中启动jupyter notebook时,我注意到它是从我另一个名为openfaceenv
的虚拟环境引用/选择python包。这是在jupyter notebook中调用sys.path
和sys.executable
时的输出:
(sampleenv
内的jupyter笔记本)
import sys
print sys.path
[ '', '/Users/user/.virtualenvs/sampleenv/lib/python2.7/site-packages', ', '/Users/user/.virtualenvs/openfaceenv/lib/python2.7/site-packages/dlib-18.18.99-py2.7-macosx-10.10-x86_64.egg', '/用户/用户, '/用户/用户/ GIT-回购', '/Users/user/.virtualenvs/openfaceenv/lib/python27.zip', '/Users/user/.virtualenvs/openfaceenv/lib/python2.7', '/Users/user/.virtualenvs/openfaceenv/lib/python2.7/plat-darwin', '/Users/user/.virtualenvs/openfaceenv/lib/python2.7/plat-mac', '/Users/user/.virtualenvs/openfaceenv/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/user/.virtualenvs/openfaceenv/lib/python2.7/lib-tk', '/Users/user/.virtualenvs/openfaceenv/lib/python2.7/lib-old', '/Users/user/.virtualenvs/openfaceenv/lib/python2.7/lib-dynload', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/user/.virtualenvs/openfaceenv/lib/python2.7/site-packages', '/Users/user/.virtualenvs/openfaceenv/lib/python2.7/site-packages/IPython/extensions', '/Users/user/.ipython']
print sys.executable
/Users/user/.virtualenvs/openfaceenv/bin/python2.7
然而,当我在sampleenv中的命令行中运行ipython或python shell并获取sys.path和sys.executable时,它们都正确地找到了正确的路径,即
(在sampleenv
内的python shell或ipython shell中)
import sys
print sys.path
['','/ Users / user','/ Users / user / git-repos','/ Users / user / .virtualenvs / sampleenv / lib / python27.zip','/ Users / user /。 virtualenvs / sampleenv / lib / python2.7','/ Users / user / .virtualenvs / samplenv / lib / python2.7 / plat -darwin','/ Users / user / .virtualenvs / sampleenv / lib / python2.7 / plat-mac','/ Users / user / .virtualenvs / sampleenv / lib / python2.7 /plat-make / lib -scriptpackages','/ Users / user / .virtualenvs / sampleenv / lib / python2.7 / lib- tk','/ Users / user / .virtualenvs / samplev / lib / python2.7 / lib-old','/ Users / user / .virtualenvs / samplenv / lib / python2.7 / lib -dynload','/ usr /local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7','/ usr / local / Cellar / python / 2.7 / Frameworks / Pepy.framework / Version / 2.7 / lib / python2.7 / plat-darwin','/ usr / local / Cellar / python / 2.7 / Frameworks / Pepy.framework / Version / 7.7 / lib / python2.7 / lib -tk','/ usr / local / Cellar / python / 2.7.9 / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / plat-mac','/ usr / local / Cellar / python / 1.7.9 / Frame / Python .framework /版本/ 2.7 / lib / python2.7 / plat-mac / lib-scriptpackages','/ User / user / .virtualenvs / samplenv / lib / python2.7 / site -packages']
print sys.executable
'/用户/用户/ .virtualenvs / sampleenv / bin中/蟒'
为什么会这样?我怎样才能解决这个问题?此外,当我尝试切换到其他虚拟环境时,同样的问题,它指向openfaceenv
站点包的路径。我已经查看了相关的问题,但他们的解决方案并没有真正解决问题,我不想使用sys.path.append()
,我也尝试运行hash -r
,但结果相同。