I have started a learning effort to teach myself python. The project started on my mac with python 2.7 as the installed version. On the advice from a friend, I installed poetry to do dependency handling. This worked extremely well.
Before long though I realized how out of date python 2.7 was and tried to upgrade. I did so through homebrew and that seemed to break a lot. python --versoin
still shows 2.7 and although I can call python3 --version
and see the correct my project still seems to be stuck on 2.7 even when #!/usr/bin/env python3
is at the top of the files. To make matters worse doing a poetry up
won't upgrade my python dependency in the project and changing that value in the pyproject.toml brakes everything. I have a dependency that seems to have broken along the way but can't do anything about it with broken poetry/python version mess. The error is below from the poetry.
So taking this from the top how do I get things to start using the correct version of python?
My bash_profile has
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH
poetry install
[EnvCommandError]
Command ['/Users/username/Library/Caches/pypoetry/virtualenvs/PyGameEngine-py2.7/bin/python', '-'] errored with the following return code -6, and output:
dyld: Library not loaded: @executable_path/../.Python
Referenced from: /Users/username/Library/Caches/pypoetry/virtualenvs/PyGameEngine-py2.7/bin/python
Reason: image not found
input was : import sys
if hasattr(sys, "real_prefix"):
print(sys.real_prefix)
elif hasattr(sys, "base_prefix"):
print(sys.base_prefix)
else:
print(sys.prefix)
Copying my answer from here
Interestingly, poetry is silently failing due to a missing package the tool itself relies on and continues to install a broken venv. Here's how you fix it.
sudo apt install python3-venv
poetry env remove python3
poetry install
I had to remove pytest, and then reinstall with poetry add pytest
.
EDIT: I ran into this issue again when upgrading a project from python3.7 to python3.8 - for this instead of installing python3-venv
, you'd want to install python3.8-venv
instead
If you are still having issues ( namely upgrading your packages to be python3 compliant, you may want to take a look at this answer )