microsoft / microsoft/vcpkg

[duktape] pyyaml installation fails on macOS (does not block port installing)

Open
#14,741 1 comment 0 reactions 3 assignees View on GitHub

@Cheney-W is already working on this.

Since Feb 20, 2024.

category:port-feature
Dominant language
CMake
Stars
27.5k
Forks
7.7k
Avg merge
2d 19h
Merged PRs (30d)
321

Description

**Host Environment:**
- OS: macOS
- I'm using macOS 10.14.6 and its associated tools' versions (Xcode 11.3.1, Python 2.7.16), but it should apply to all (supported) macOS version.

**Steps To Reproduce:**
`./vcpkg install duktape`

**Failure Logs:**
Printed to the console:
```
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

[Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-36033.pth'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

/Library/Python/2.7/site-packages/

Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

https://pythonhosted.org/setuptools/easy_install.html

Please make the appropriate changes for your system and try again.

```

**Additional context:**
This does not prevent duktape from being built and installed if the user installs pyyaml manually.

This issue is fairly easy to trace back to its source. in `ports/duktape/portfile.cmake`, there is the following code:
```cmake
if(NOT EXISTS ${PYTHON2_DIR}/easy_install${EXECUTABLE_SUFFIX})
# ...
else()
execute_process(COMMAND ${PYTHON2_DIR}/easy_install${EXECUTABLE_SUFFIX} pyyaml)
endif()
```
It's this `execute_process` that's resulting in the error message being printed. This is because the system-wide `site-packages` directory on macOS requires root permissions to write to.

I see three possible solutions for this:
- Change this (on macOS) to run `sudo easy_install pyyaml`.
- Change this (on macOS) to run `easy_install --user pyyaml`, as installing just for the user does not require root.
- Don't attempt to install pyyaml on macOS, and post a message to the user telling them to install it themselves.

I was initially under the impression that pyyaml required libyaml to be installed (system-wide) due to the output I got from `easy_install`, but it turns out I was wrong, as it's an optional dependency. If you're interested, here's the error message for this:
```
In file included from ext/_yaml.c:596:
ext/_yaml.h:2:10: fatal error: 'yaml.h' file not found
#include
^~~~~~~~
1 error generated.
Error compiling module, falling back to pure Python
```

With this in mind, a solution to this *should* also make sure that the output of `easy_install` is redirected away from the terminal, either to vcpkg's logs or to its own log. Error messages like this could easily confuse users and make them think the build failed when it didn't.

This error relates to #14662, as this issue was exposed with Python 2 being fixed, and this issue was mentioned in the PR's description and comments.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.