python - Adding custom dir to PYTHONPATH -
i've been trying add custom directory pythonpath
following advice on post permanently add directory pythonpath. i'm using bash on mac, if that's relevant. did:
open ~/.bash_profile
export pythonpath="${pythonpath}:/users/zhengnan/library/python/2.7/lib/python/site-packages"
, savesource ~/.bash_profile
there 2 problems:
- when ran
sys.path
inside python ide, intended dir still didn't show up. - when fired python in terminal , ran
sys.path
there, dir did show up, other directories didn't match got previous step.
specifically, got running sys.path
inside ide. intended dir couldn't found.
sys.path ['', '/applications/spyder-py2.app/contents/resources', '/applications/spyder-py2.app/contents/resources/lib/python27.zip', '/applications/spyder-py2.app/contents/resources/lib/python2.7', '/applications/spyder-py2.app/contents/resources/lib/python2.7/plat-darwin', '/applications/spyder-py2.app/contents/resources/lib/python2.7/plat-mac', '/applications/spyder-py2.app/contents/resources/lib/python2.7/plat-mac/lib-scriptpackages', '/applications/spyder-py2.app/contents/resources/lib/python2.7/lib-tk', '/applications/spyder-py2.app/contents/resources/lib/python2.7/lib-old', '/applications/spyder-py2.app/contents/resources/lib/python2.7/lib-dynload', '/applications/spyder-py2.app/contents/resources/lib/python2.7/site-packages.zip', '/applications/spyder-py2.app/contents/resources/lib/python2.7/site-packages', '/applications/spyder-py2.app/contents/resources/lib/python2.7/ipython/extensions', '/users/zhengnan/.ipython']
and got running sys.path
terminal. intended dir third element in list.
sys.path ['', '/users/zhengnan', '/users/zhengnan/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/extras/lib/python', '/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', '/system/library/frameworks/python.framework/versions/2.7/extras/lib/python/pyobjc']
i should mention reason want add custom dir pythonpath
every time pip install
package, gets installed in /users/zhengnan/library/python/2.7/lib/python/site-packages
, don't want sys.path.append
every time run script. please advise. thanks.
there's lot going on here.
fundamentally, python using in ide not python using in terminal. why pip install
doesn't put things in right place.
the easiest solution modify $path
environment variable when type python
in terminal, same version ide using. guess ide's python
/applications/spyder-py2.app/contents/resources/bin/python
, in case rid of pythonpath
setting .bash_profile
, add:
export path="/applications/spyder-py2.app/contents/resources/bin:$path"
assuming pip
available in same place, should able pip install
things without needing muck pythonpath
.
the other problem here environment variables set in shell, e.g., in .bash_profile
, have no impact on environment visible applications. possible set environment variables visible os x applications (e.g., see this question), it's tricky , wouldn't advise it.
an alternate solution, if it's available, tell ide python
should using, , point @ whichever 1 visible terminal.
Comments
Post a Comment