PythonPath环境变量不保存MACOS

发布于 2025-01-21 01:40:08 字数 1022 浏览 4 评论 0原文

运行 echo $PYTHONPATH 返回一个空行:

freddy@dave ~ % echo $PYTHONPATH

freddy@dave ~ %

echo $PATH

freddy@dave ~ % echo $PATH
/opt/homebrew/bin:/opt/homebrew/sbin: ...

为用户 freddy 返回正确的 .bash_profile

# Fig pre block. Keep at the top of this file.
export PATH="${PATH}:${HOME}/.local/bin"
eval "$(fig init bash pre)"

# Use Python 3.10, not homebrew
export PYTHONPATH="/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10"

export PATH="/opt/homebrew/bin:${PATH}"
source ~/.bash_profile

# Fig post block. Keep at the bottom of this file.
eval "$(fig init bash post)"% 

为什么echo $PYTHONPATH 不返回任何内容?我如何将它分配给我的Python3.10路径?

  • 我尝试重新启动,这对我运行 source ~/.bash_profile 没有帮助
  • (这只是在执行后关闭终端?)
  • 测试变量:export TEST="TEST" 也回显空行

正如评论所暗示的那样,我正在尝试使用 Python3.10 而不是我的 Homebrew 安装,这是针对某些系统软件包的

Running echo $PYTHONPATH returns a blank line:

freddy@dave ~ % echo $PYTHONPATH

freddy@dave ~ %

echo $PATH returns properly

freddy@dave ~ % echo $PATH
/opt/homebrew/bin:/opt/homebrew/sbin: ...

.bash_profile for user freddy:

# Fig pre block. Keep at the top of this file.
export PATH="${PATH}:${HOME}/.local/bin"
eval "$(fig init bash pre)"

# Use Python 3.10, not homebrew
export PYTHONPATH="/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10"

export PATH="/opt/homebrew/bin:${PATH}"
source ~/.bash_profile

# Fig post block. Keep at the bottom of this file.
eval "$(fig init bash post)"% 

Why does echo $PYTHONPATH return nothing? And how do I assign it to my Python3.10 path?

  • I've tried restarting, this does not help
  • I've run source ~/.bash_profile (this just closes the terminal after execution though?)
  • A test variable: export TEST="TEST" also echos a blank line

As the comment suggests, I'm trying to use Python3.10 instead of my Homebrew installation, which is for some system packages

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2025-01-28 01:40:08

我使用的是 zsh,而不是 bash


我将 PYTHONPATH 移至 .zshrc,它现在保存为环境变量。

但是,我选择了 pyenv 设置。并将以下内容添加到我的 .zshrc 文件中:

eval "$(pyenv init --path)"

https://stackoverflow.com/a/69378384/14141223

I am using zsh, not bash.


I moved PYTHONPATH to .zshrc and it saves as an environment variable now.

However, I have opted for the pyenv setup. And have added the following to my .zshrc file:

eval "$(pyenv init --path)"

https://stackoverflow.com/a/69378384/14141223

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文