18

I am trying to install poetry using the following command

curl -sSL https://install.python-poetry.org | python3 -

but it is failing with the following exception:

Exception: This build of python cannot create venvs without using symlinks

Below is the text detailing the error

Retrieving Poetry metadata

# Welcome to Poetry!

This will download and install the latest version of Poetry,
a dependency and package manager for Python.

It will add the `poetry` command to Poetry's bin directory, located at:

/Users/DaftaryG/.local/bin

You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.

Installing Poetry (1.2.1): Creating environment
Traceback (most recent call last):
  File "<stdin>", line 940, in <module>
  File "<stdin>", line 919, in main
  File "<stdin>", line 550, in run
  File "<stdin>", line 571, in install
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
  File "<stdin>", line 643, in make_env
  File "<stdin>", line 629, in make_env
  File "<stdin>", line 309, in make
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/venv/__init__.py", line 66, in __init__
    self.symlinks = should_use_symlinks(symlinks)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/venv/__init__.py", line 31, in should_use_symlinks
    raise Exception("This build of python cannot create venvs without using symlinks")
Exception: This build of python cannot create venvs without using symlinks

I already have symlinks installed so not having that does not seem to be the problem. Would anyone know the cause of this error?

6 Answers6

25

Not the best solution, but you can install it using Homebrew, if you have it. That's what I did.

brew install poetry
Alex
  • 282
  • 3
  • 3
4

I had the same error.

In my case, the problem was the global version of python set by pyenv was not python 3.x.

So

pyenv global 3.x.x

fixed it.

j0hnta
  • 41
  • 2
4

Had the same problem. The above solutions did not work. The brew install was not a good solution for me (see this post on why).

So I noodled around a bit and this worked and is only a tweaked version of the official recommended installation (which is not brew install)

Specifically, when specifying the major+minor versioning, it worked.

pyenv install 3.10.1
pyenv global 3.10.1
curl -sSL https://install.python-poetry.org | python3.10 -

Using anything else than major.minor (e.g. python python3 or python3.10.1) resulted in the symlink error you had.

alps
  • 93
  • 7
  • but this fixes poetry to a specific version of python, isn't that bad? – azizbro Feb 27 '23 at 07:07
  • per the doc, this will install Poetry in a new virtual environment to isolate it from the rest of your system. So you just have to be specific with regard to the python version in the virtual environment when you install it on a mac vs let it autodetect the one selected (which does not seem to work on mac with the current version of the custom installer invoked using curl) – alps Mar 01 '23 at 05:42
  • that's the value of using pyenv (fixing installs to a version). once you create a pyenv version, check `which python` / `which python3` to make sure you're referencing your pyenv version in the command above. – neonwatty Mar 24 '23 at 19:17
  • For me, I had to set the last command like this: `curl -sSL https://install.python-poetry.org | ~/.pyenv/versions/3.10.1/bin/python3.10 - ` – mayo Jul 28 '23 at 14:45
3

if you are installing poetry on the clean macOS (without brew and pyenv) you can use following steps:

  1. you need to install official Python distributive. The easiest way to download it from the official site https://www.python.org/downloads/
  2. next you need to go to Applications > Python folder > double click on Install Certificates.command file (without this step you will get the next error https://github.com/python-poetry/poetry/issues/449)
  3. now you can install Poetry via
curl -sSL https://install.python-poetry.org | python3.11 -

(!) make sure you replaced python3 with actual Python version you installed (python3.11 in the example above)

Mikhail Tokarev
  • 2,843
  • 1
  • 14
  • 35
1

For anyone looking for an alternative to homebrew for installation, the discussion on this poetry issue helped me find a solution:

The issue here is the macOS-provided python is not relocatable, so venv creates a broken python when using --copies / symlinks=False as our installer does.

Essentially, to solve this problem, download a distribution of python directly from python.org. For whatever reason, the poetry installation command isn't compatible with whatever distribution comes pre-built on a Mac.

Daniel Long
  • 1,162
  • 14
  • 30
0

Adding the specific minor version of the Python I had installed in my machine did the job, without needing brew nor pyenv:

python3 --version
>>> Python 3.9.6

curl -sSL https://install.python-poetry.org | python3.9 -
>>> (...)
>>> Installing Poetry (1.5.1): Done
Aleix CC
  • 1,601
  • 1
  • 7
  • 18