简体   繁体   English

dyld:库未加载:@executable_path/../.Python

[英]dyld: Library not loaded: @executable_path/../.Python

A while ago I had both Python 2.7 and 3.5 installed on my Mac and was able to use them both successfully.不久前,我在 Mac 上安装了 Python 2.7 和 3.5,并且能够成功使用它们。 Not too long ago, I installed Anaconda and IPython.不久前,我安装了 Anaconda 和 IPython。 I have used those for a couple weeks for prototyping and in-console programming.我已经将它们用于原型设计和控制台内编程几个星期。

After I went back to the regular Python for my Django and Flask projects, I discovered an unpleasant thing.在我为我的 Django 和 Flask 项目回到常规 Python 之后,我发现了一件不愉快的事情。 Namely, whenever I try to run python or python3 I get the following error:即,每当我尝试运行pythonpython3我都会收到以下错误:

dyld: Library not loaded: @executable_path/../.Python
  Referenced from: /Users/name/anaconda3/bin/python3
  Reason: image not found
Abort trap: 6

When I run conda I also get the same error.当我运行conda我也遇到同样的错误。

If I create a new virtual environment with virtualenv django-project , I am able to activate it, and it allows me to run Python 2.7 successfully.如果我使用virtualenv django-project创建一个新的虚拟环境,我就可以激活它,它允许我成功运行 Python 2.7。

My question is the following: How can I fix python and python3 for the command line while also retaining the working Anaconda and IPython?我的问题如下:如何修复命令行的pythonpython3 ,同时保留工作的 Anaconda 和 IPython? How can I make sure that the virtual environments are able to carry Python 3?如何确保虚拟环境能够承载 Python 3?

I also use macOS and I never mess with or even deal with the system python.我也使用 macOS,我从不搞乱甚至处理系统 python。 I've installed python3 via Homebrew ( https://brew.sh ) and I always use a virtual environment.我已经通过 Homebrew ( https://brew.sh ) 安装了 python3 并且我总是使用虚拟环境。 I have one in my home directory (my default) and I have one for each project I'm working on.我的主目录中有一个(我的默认目录),我正在处理的每个项目都有一个。

Your rule of thumb should be to never run 'pip' if you aren't within a virtualenv.如果您不在 virtualenv 中,您的经验法则应该是永远不要运行“pip”。 Check with $ echo $VIRTUAL_ENV .检查$ echo $VIRTUAL_ENV

To create/recreate the virtual environment in python3 with the currently installed libraries:使用当前安装的库在 python3 中创建/重新创建虚拟环境:

  • Get into your project directory and active your virtualenv.进入您的项目目录并激活您的 virtualenv。
  • (optional) Dump your requirements via pip: $ pip freeze > requirements.txt (可选)通过 pip 转储您的需求: $ pip freeze > requirements.txt
  • Nuke your virtual environment directory if you have one: $ rm -rf .venv如果您有虚拟环境目录,请$ rm -rf .venv$ rm -rf .venv
  • Deactivate it: $ deactivate停用它: $ deactivate
  • Create a new one with python3: $ virtualenv -p python3 .venv用 python3 创建一个新的: $ virtualenv -p python3 .venv
  • Activate it: $ source .venv/bin/activate激活它: $ source .venv/bin/activate
  • (optional) Install your requirements: $ pip install -r requirements.txt (可选)安装您的要求: $ pip install -r requirements.txt
  • Profit.利润。

You can skip the steps for writing and reading the requirements.txt if you just want to create a new virtual environment and then install only the modules you want/need later.如果您只想创建一个新的虚拟环境,然后只安装您想要/稍后需要的模块,您可以跳过编写和读取 requirements.txt 的步骤。

firstly, to reduce your confusion n which python you are using you could try the following 2 commands in Linux or mac where bash shell is installed:首先,为了减少您对正在使用的 python 的混淆,您可以在安装了 bash shell 的 Linux 或 mac 中尝试以下 2 个命令:

$ which python or $ which python3 $ which python 或 $ which python3

in my case, it outputs the python paths I am using with pyenv [with fish shell] [$ is a shell sign]在我的例子中,它输出我在 pyenv [with fish shell] [$ is a shell sign] 中使用的 python 路径

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 macOS 11.6/Xcode 13 上的诗歌安装失败:dyld:未加载库:@executable_path/../Python3 - poetry install fails on macOS 11.6/Xcode 13: dyld: Library not loaded: @executable_path/../Python3 AWS SAM CLI 全新安装引发错误 - dyld:未加载库:@executable_path/../.Python - AWS SAM CLI Fresh install throws error - dyld: Library not loaded: @executable_path/../.Python 如何解决“dyld:库未加载:@executable_path ..”错误 - How to resolve "dyld: Library not loaded: @executable_path.." error 弃用警告:executable_path 已弃用 selenium python - DeprecationWarning: executable_path has been deprecated selenium python 我可以从Python设置@executable_path吗 - Can I set @executable_path from Python MacOS 上的 Python“dyld:库未加载”- 错误 - Python on MacOS "dyld: Library not loaded" - error SeleniumLibrary 不接受 executable_path - SeleniumLibrary doesn't accept executable_path 解决 PyCharm python 错误 - dyld: 库未加载 - Resolving PyCharm python error - dyld: Library not loaded SyntaxError:IPython中的execute_path语法无效 - SyntaxError: invalid syntax with executable_path in ipython Selenium 服务忽略可执行文件路径? - Selenium Service ignoring executable_path?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM