0

I wonder if this is all a PATH issue. I have MacBook Pro 12.6, with homebrew. No pyenv or virtualenv. (perhaps I should..) I am using nvim. When I start iterm it launches python to the python command prompt rather than my zsh prompt. When I ctrl D it goes straight to the zshell prompt with no complaints.

Last login: Sun Oct 23 10:07:06 on ttys001
/etc/zshrc:7: command not found: locale
Python 3.9.6 (default, Sep 19 2022, 18:46:30)
[Clang 14.0.0 (clang-1400.0.29.201)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

My /etc/paths is

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

My .zshenv is

export PATH=/Users/np/.local/bin:$PATH

My .zsh_profile is

export PATH="$PATH:/usr/bin"
export PATH="$PATH:/usr/sbin"
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
export PATH=/opt/homebrew/bin:$PATH

PATH=/.local/bin:$PATH
PATH=/bin:/usr/bin:/usr/local/bin:${PATH}

#clipboard 
set clipboard=unnamed

#oh-my-zsh
export ZSH="$HOME/.oh-my-zsh"
source $ZSH/oh-my-zsh.sh


#Theme
ZSH_THEME="powerlevel10k/powerlevel10k"

#Plugins
plugins=(git zsh-autosuggestions  z )
source $ZSH/oh-my-zsh.sh

#/opt/homebrew/etc/profile.d/z.sh


#aliases
source ~/.zsh_aliases

#P10k
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
source /Users/np/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/sbin:$PATH"```

I know the PATH entries are a mess.

I don't know how to fix the PATHS and dont have a clear idea of the priorities and orders for PATHS if indeed that is the issue. I know that my path to homebrew should be loaded first so that the system uses homebrew links before system links.

I think this is something to do with my multiple pythons and I need advice on wihich to delete, - presumably all except the homebrew and native mac ones as I mainly use homebrew.

Here is

Which -a python
/opt/homebrew/bin/python3
/usr/bin/python3
/usr/local/bin/python3
/opt/homebrew/bin/python3
/usr/local/bin/python3
/opt/homebrew/bin/python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
/usr/bin/python3
capnahab
  • 343
  • 3
  • 14
  • Reinstalled neovim and that has fixed the Python not found error on nvim startup, but why is python launching? – capnahab Oct 23 '22 at 16:24
  • 2
    Check all of the [startup files](https://zsh.sourceforge.io/Intro/intro_3.html). The symptoms you describe would occur if there's a `python` command in `~/.zshrc`. – Gairfowl Oct 24 '22 at 00:30
  • The error message you posted, clearly mentions .zshrc, and you post every other startup file except this one. Please post all **relevant** information here. – user1934428 Oct 24 '22 at 11:07
  • .zshrc now above. – capnahab Oct 24 '22 at 16:16
  • This is basically a troubleshooting issue. The zsh startup sequence is a program or, actually, a sequence of programs. It is [documented](https://zsh.sourceforge.io/Doc/Release/Files.html#Files) in the zsh manual. Debug it like you would any other program. – Ture Pålsson Oct 29 '22 at 06:53

2 Answers2

1

My suggestion is to start with an empty zshrc/zprofile and work back slowly from there. Add in a few lines at a time until you have what you want. Adding items one change at a time and testing is the best way to get out of this hole and find out where the included script is that is causing your issues. Once you add in a line that causes the python prompt to appear, you'll know where to dig in deeper.


This is not going to explicitly solve your issues, but I'd like to share a setup that has worked for me:

For myself, I've found a more manageable way to tame my zsh settings are to break it out into multiple files. In the ~/.zshrc and ~/.zprofile I have a single line:

source ~/zsetup/main

If your zshrc and zprofile should be different, then create separate entrypoints, but do re-use common sources.

The contents of ~/zsetup is a git repo that I back in source control (with any secrets added to my .gitignore). I have configuration files and simple zsh sources modularized into small files specific to their purpose which are sourced from zsetup/main. The git repo allows me to view audits of how I changed my settings over time and allows me to quickly get back up and running when I format my laptop or move to a new one.

Example of zsetup/main is:

basedir=$(dirname "$0")

# Add any setup I need for brew
source "$basedir/brew"

# Add paths for things like PATH, LDFLAGS, CPPFLAGS, etc
source "$basedir/path"

# Add common operations that I do daily.
source "$basedir/aliases"

# All my fun coloring of my zsh prompt
source "$basedir/prompt"

# Environment variables needed for myapplication1
source "$basedir/myapplication1"

# Environment variables needed for myapplication2
source "$basedir/myapplication2"

# etc ...

Example for my zsetup/path looks like:

export PATH=$(brew --prefix python@3.10):$PATH
export PATH=~/Library/Python/3.10/bin:$PATH

export PATH=$(brew --prefix go):$PATH

export LDFLAGS=-L$(brew --prefix openssl@1.1)/lib
export CPPFLAGS=-I$(brew --prefix openssl@1.1)/include

# etc ...

Some fun functions I have setup in zsetup/aliases:

proxy="http://some.proxy:82"
alias with_proxy="http_proxy=$proxy https_proxy=$proxy"

alias dev_vm="ssh my.work.machine.address"

# etc ...

Hope this helps you out!

flakes
  • 21,558
  • 8
  • 41
  • 88
0

When you open a new terminal instance, part of the startup process runs source ~/.zshrc

The source command takes each line in the file and runs it in your current shell session.

If you want to find which line is launching the interactive python interpreter, you can run each line from .zshrc one by one until you find one that launches python.

You should also check the contents of any other files sourced within the rc file.

If I were to hazard a guess, I would say you probably have a misconfigured alias in ~/.zsh_aliases

aliases are not just 1 to 1 text replacements, when you define an alias that involves a subshell command then that subshell will execute when the alias is first defined.

for instance something like alias py=$(python)will cause you to enter an interactive python session when the alias is first defined. Which occurs when you start up a new terminal session.

Pierre Baudin
  • 397
  • 1
  • 10