atom-editor-修改脚本包的python sys.path

时间:2019-02-19 20:54:53

标签: python atom-editor

我正在使用atom和脚本包设置python ide。我想在sys.path中为python添加另一个目录,这样就不必安装其他软件包。使用配置运行选项时遇到问题。

下面是一些代码,演示了我要完成的工作(我正在原子内部运行此代码)

import sys

print(sys.executable)
print(sys.version)
# where to look for modules
for p in sys.path:
    print(p)
print("\n")

try: # one install of matplotlib in "jupyter" virtualenv
    import matplotlib
    print("imported successfully\n")
except:
    print("did not import matplotlib\n")

print("inserting new path folder inside script\n")
sys.path.insert(0, "/Users/jakekirsch/.pyenv/versions/jupyter3/lib/python3.6/site-packages")

for p in sys.path:
    print(p)


print("\n")
try:
    import matplotlib
    print("imported successfully\n")
except:
    print("did not import matplotlib\n")


import os
for p in os.environ['PATH'].split(":"):
    print(p)

结果

/Users/jakekirsch/.ve/strava_dashboard/bin/python
3.6.0 (default, Feb 28 2018, 15:01:58) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
/Users/jakekirsch/workspace/strava_dashboard
/Users/jakekirsch/.ve/strava_dashboard/lib/python36.zip
/Users/jakekirsch/.ve/strava_dashboard/lib/python3.6
/Users/jakekirsch/.ve/strava_dashboard/lib/python3.6/lib-dynload
/Users/jakekirsch/.pyenv/versions/3.6.0/lib/python3.6
/Users/jakekirsch/.ve/strava_dashboard/lib/python3.6/site-packages


did not import matplotlib

inserting new path folder

/Users/jakekirsch/.pyenv/versions/jupyter3/lib/python3.6/site-packages
/Users/jakekirsch/workspace/strava_dashboard
/Users/jakekirsch/.ve/strava_dashboard/lib/python36.zip
/Users/jakekirsch/.ve/strava_dashboard/lib/python3.6
/Users/jakekirsch/.ve/strava_dashboard/lib/python3.6/lib-dynload
/Users/jakekirsch/.pyenv/versions/3.6.0/lib/python3.6
/Users/jakekirsch/.ve/strava_dashboard/lib/python3.6/site-packages


imported successfully

脚本包说您可以使用命令和环境变量来执行脚本,但是我一直无法弄清楚这些选项中要放什么

我用这些变量尝试过的一些事情

    在命令中使用
  • python,在命令参数中使用-c "import sys; sys.path.insert(0, '/Users/jakekirsch/.pyenv/versions/jupyter3/lib/python3.6/site-packages')" ,但这没用

  • $PATH=/Users/jakekirsch/.pyenv/versions/jupyter3/lib/python3.6/site-packages:$PATH在“环境变量”中(但是这并没有什么意义,因为这告诉了原子在哪里寻找python版本?)

  • $PYTHONPATH=/Users/jakekirsch/.pyenv/versions/jupyter3/lib/python3.6/site-packages在“环境变量”中-也不起作用

0 个答案:

没有答案