Permanently add a directory to PYTHONPATH?

前端 未结 19 1303
别那么骄傲
别那么骄傲 2020-11-22 01:12

Whenever I use sys.path.append, the new directory will be added. However, once I close python, the list will revert to the previous (default?) values. How do I

19条回答
  •  爱一瞬间的悲伤
    2020-11-22 01:27

    This is an update to this thread which has some old answers.

    For those using MAC-OS Catalina or some newer (>= 10.15), it was introduced a new Terminal named zsh (a substitute to the old bash).

    I had some problems with the answers above due to this change, and I somewhat did a workaround by creating the file ~/.zshrc and pasting the file directory to the $PATH and $PYTHONPATH

    So, first I did:

    nano ~/.zshrc
    

    When the editor opened I pasted the following content:

    export PATH="${PATH}:/Users/caio.hc.oliveira/Library/Python/3.7/bin"
    export PYTHONPATH="${PYTHONPATH}:/Users/caio.hc.oliveira/Library/Python/3.7/bin"
    

    saved it, and restarted the terminal.

    IMPORTANT: The path above is set to my computer's path, you would have to adapt it to your python.

提交回复
热议问题