Can I modify the sys.path for python when using the script package?

I am setting up a python ide with atom and the script package. I’d like to add another directory to sys.path for python so that I do not have to install a bunch of additional packages each time I’m working on a new virtual environment. I’m having trouble using configure run options.

Below is a bit of code that demonstrates what I’m trying to accomplish (I am running this inside of atom)

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

    # matplotlib is not installed on this environment this will fail
    try: 
        import matplotlib
        print("imported successfully\n")
    except:
        print("did not import matplotlib\n")
    
    #there is one install of matplotlib in "jupyter" virtualenv
    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)

results

/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

the script package says you can execute the script with commands and environment variables, however I haven’t been able to figure out what to put in these options

Some things I’ve tried with these variables

  • python in command and -c "import sys; sys.path.insert(0, '/Users/jakekirsch/.pyenv/versions/jupyter3/lib/python3.6/site-packages')" in command arguments[1] but that didn’t work

  • $PATH=/Users/jakekirsch/.pyenv/versions/jupyter3/lib/python3.6/site-packages:$PATH in the the “environment variables” (however this doesn’t really make sense, because that’s telling atom where to look for the python version?)

  • $PYTHONPATH=/Users/jakekirsch/.pyenv/versions/jupyter3/lib/python3.6/site-packages in the “environment variables” - also didn’t work, not sure why

If you don’t find someone who can answer your question here, you might want to ask at the script repository.

I personally think that script is too limited for serious use, especially since it has some flaws in its design (it doesn’t correctly handle files with spaces in their paths) and is mostly abandoned. I highly recommend process-palette, which gives you many options, not just a few. Like script, the process-palette output pane is not able to handle requests for user input, but it’s easier to spawn terminals and you can tell process-palette to do things that script can’t like sending the entire output of your script to a new tab in Atom.

Thanks for the tip, didn’t realize script was mostly abandoned. I’ll try out process-palette then