我还是很新的蟒蛇所以请原谅我,如果这是非常简单或极思考这个错误的方式。导演的Python在另一个文件夹查找模块
我有Python 2.7版安装。从我所了解的当我运行下面的代码时,它列出了它寻找模块的目录。
Python 2.7.12 (default, Oct 11 2016, 14:42:58)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print '\n'.join(sys.path)
/usr/local/lib/python2.7/site-packages
/usr/lib/python2.7/site-packages
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/readline
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
我有另一个目录,似乎有一堆我安装在它的python模块。 “/Library/Python/2.7/site-packages”
我想我需要做两件事情之一:
(1)直接蟒蛇在这额外的文件夹中查找模块。 我该怎么做?
(2)在它已经被引导到的文件夹中的一个安装模块。我一直在使用pip来安装模块,我认为pip正在安装到这个额外的导演。 如何检查pip是否安装到此文件夹?如何更改pip安装软件包的位置?
谢谢!
一个简单的解决方法就是将代码附加到代码中的'sys.path'中,例如'sys.path.append( '/库/ Python的/ 2.7 /站点包')'。这应该在依赖这个目录的'import'之前完成。 –
查看安装有pip的任何给定库的位置,使用pip show命令:'C:\ Users \ ...> pip show numpy'寻找线路位置:' – Aaron
感谢,@ jmd_dk,这对我很有用!谢谢。任何方式来告诉它永久引用这个目录,而不是必须把我的代码? – user1500158