2

I have several packages installed with pip which should/have been able to be run from the command line. For example, pipreqs as well as a local package that I have created both have been and should run from the command line, respectively.

However, as soon as I upgraded to MacOS Catalina, the terminal changed from bash to zsh. Now, no Python commands from the command-line are available. I beleve that this may be caused by the bash_profile, but it seems to be configured correctly.

Are there any settings that must be modified or PATHs added to the bash_profile upon upgrade? I have found that these commands all work when typing bash -login and running them in bash in the terminal, but not in zsh.

Contents of ~/.bash_profile:

export VARENV="kt2LrUtW8UVwMO3axMa8l4byPbs"
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

# Setting PATH for Python 3.8
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
export PATH

# Setting PATH for Python 3.8
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
export PATH

# Setting PATH for Python 3.8
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
export PATH


# support python packages
export PATH=$PATH:~/.local/bin

# support pipreqs
export PATH=${PATH}:/usr/local/bin/pipreqs/pipreqs.py


test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"




export PATH="$HOME/.cargo/bin:$PATH"

Attempting to run pipreqs (or other command-line modules):

~ pipreqs -h
zsh: command not found: pipreqs

Python version: 3.8 pipreqs found when running python3 -m pip list (since pip list and pip3 list only show up for Python 2).

Edit: running the following commands gives the following results echo "$PATH" | tr : '\n'

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/go/bin
/usr/local/munki
/opt/X11/bin

trying to reinstall pipreqs:

Installing collected packages: pipreqs 

WARNING: The script pipreqs is installed in '/Library/Frameworks/Python.framework/Versions/3.8/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. 

Successfully installed pipreqs-0.4.10 –

SOLUTION: The contents of .zshrc are different from .bash_profile. You need to migrate them in order to support Python and the libraries.

  1. type open ~/.bash_profile
  2. type open ~/.zshrc
  3. copy the PATH for Python 3 to .zshrc and add the following line: export PATH=$PATH:~/.local/bin
  4. save the file
  5. go back the terminal, and type source ~/.zshrc
  6. restart terminal and it works
oguz ismail
  • 1
  • 16
  • 47
  • 69
Destaq
  • 655
  • 9
  • 23
  • Upgrading a Mojave box to Catalina does not automatically migrate you to zsh. What exactly did you do to switch shells? What's in your Bash configuration? Where is `pipreqs` installed and how is that directory added to your `PATH` in Bash? – tripleee Jul 09 '20 at 15:47
  • `echo "$PATH" | tr : '\n'` displays the directories of your `PATH` in a vaguely human-friendly format. – tripleee Jul 09 '20 at 15:49
  • `pip3 list` should specifically run the Python 3 version of `pip`, and thus list your Python 3 packages. – tripleee Jul 09 '20 at 15:55
  • > Upgrading a Mojave box to Catalina does not automatically migrate you to zsh. When I upgraded, it said that my default shell was now zsh. The bash configuration can be seen above, I added it here. `pip3 -V` yield the Python 2 version of pip, so I am reluctant to use that. @tripleee – Destaq Jul 09 '20 at 15:59
  • running `echo "$PATH" | tr : '\n'` yields: /usr/local/bin /usr/bin /bin /usr/sbin /sbin /usr/local/go/bin /usr/local/munki /opt/X11/bin – Destaq Jul 09 '20 at 15:59
  • I am getting a warning about it not being on PATH though. Installing collected packages: pipreqs WARNING: The script pipreqs is installed in '/Library/Frameworks/Python.framework/Versions/3.8/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed pipreqs-0.4.10 – Destaq Jul 09 '20 at 16:01
  • That's with zsh, right? Please [edit] your question to update it with these details. Then you get to format them properly, too. – tripleee Jul 09 '20 at 16:01
  • The `PATH` additions in your `.bash_profile` look like they should all be added to your zsh startup files (except it's pointless to add the same stuff twice, or generally to `export PATH` because it's quite likely already exported). – tripleee Jul 09 '20 at 16:03
  • https://stackoverflow.com/questions/42870537/zsh-command-cannot-found-pip seems similar, but only has horrible pseudo-answers. – tripleee Jul 09 '20 at 16:07
  • It's a bit unclear, you're right. I can't even seem to be able to find my `.zshrc` file. – Destaq Jul 09 '20 at 16:09
  • https://stackoverflow.com/questions/23978540/how-to-make-zsh-on-a-mac-10-9-use-python-2-7-6-instead-of-apples-preinstalled-2 shows how to solve this, although the paths you want to add are obviously different. – tripleee Jul 09 '20 at 16:09
  • If it doesn't exist, just create it in your home directory. – tripleee Jul 09 '20 at 16:09
  • You're correct, this did it! What I had to do was open both `.zshrc` and `.bash_profile`, copy the Python path and the python package path to `.zshrc`, save, and restart! I'll create an answer so others can benefit as well. – Destaq Jul 09 '20 at 16:13
  • @tripleee Quick question - before you asked me to install it with `pip install -e .`, which I did. However, I can't seem to figure out how to uninstall it and the `statistics` command remains... – Destaq Jul 09 '20 at 16:28
  • If you set it up in a virtual environment like I suggested, just `deactivate` that env. If you installed it system-wide, you should be able to `pip3 uninstall` it with the same privileges. Maybe you need to temporarily restore your `PYTHONPATH` to whatever it was when you installed. – tripleee Jul 09 '20 at 16:33
  • @tripleee Well I installed it system-wide since I am unfamiliar with venvs. When I run `python3 -m pip list` it does not show up, but I am still able to run the `statistics` command. – Destaq Jul 09 '20 at 16:36
  • What does `type statistics` in your shell return? – tripleee Jul 09 '20 at 16:40
  • Edit: I just deleted the statistics executable in the Python framework and removed the eggs distribution. – Destaq Jul 09 '20 at 16:46

1 Answers1

0

zsh has its own (five) startup files. See http://zsh.sourceforge.net/Intro/intro_3.html for details.

LeadingEdger
  • 604
  • 4
  • 7
  • Is there some specific command I should then write when creating the Python packages to somehow get them to run on `zsh` as well? – Destaq Jul 09 '20 at 16:07