0

I'd like to have my environment "PATH" variable the same in both python and bash. This is not currently the case. Is python (via anaconda) installed incorrectly?

From python:

import os
os.environ["PATH"].split(os.pathsep)

['/Users/redacted/anaconda/bin',
 '/Users/redacted/anaconda/condabin',
 '/usr/bin',
 '/bin',
 '/usr/sbin',
 '/sbin']

From bash (converted to list):

printenv

['/Users/redacted/anaconda/bin',
 '/usr/local/bin',
 '/usr/bin',
 '/bin',
 '/usr/sbin',
 '/sbin',
 '/usr/local/sbin']

Python environment PATH lacks '/usr/local/bin' and '/usr/local/sbin'. Any ideas on why this might be happening and/or how I can fix it?

Ghoti
  • 457
  • 2
  • 13
  • 2
    `'PATH'!='PYTHONPATH'` – mad_ Mar 09 '20 at 20:39
  • How and where is your Python interpreter started? Are you starting it *from that copy of bash*, or is it being started from somewhere else (an ide, a cron job, a systemd service, etc)? – Charles Duffy Mar 09 '20 at 20:39
  • 1
    The first place to start is looking at the environment of the parent process to that Python interpreter (whether that parent process is `cron`, `atd`, or whatever else). If its PATH matches its parent's PATH, then whatever's going on that's surprising has nothing to do with Python. – Charles Duffy Mar 09 '20 at 20:41
  • @mad_, where does this question refer to `PYTHONPATH`? – Charles Duffy Mar 09 '20 at 20:41
  • @Ghoti, ...the next thing to look at is *what steps get run when starting `python`*. If there's a shell function or alias intercepting the `python` command and doing something fancy, we want to know what that is. Using `set -x` to turn on tracing in your shell is a good place to start. (Of course, if you're using an IDE, then whatever's changing your PATH is almost certainly inside that IDE itself and not necessarily something that's happening in shell at all). – Charles Duffy Mar 09 '20 at 20:42
  • @CharlesDuffy how I initiate the python script will vary. I generally work with it via Spyder interpreter launched with Anaconda. Also trying to make the script run via bash python3.6 call. Seems the environment may be different depending on how the script is initiated. Going to test running from bash and see if it changes. – Ghoti Mar 09 '20 at 20:48
  • Partially. I can update the python path manually, but I'm not able to get the bash path from within python (when run via GUI, still haven't tested it via bash). I'm going to try to save the environment in a specific location and reference it with envbash. – Ghoti Mar 09 '20 at 20:53
  • 1
    I settled on the same solution as "How to set PATH variable inside Spyder on Ubuntu." Script should run fine most of the time (via bash). I'll have to manually set the path when using the GUI for debugging. – Ghoti Mar 09 '20 at 21:40

0 Answers0