Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRACKER: Getting Started with Meson/Bug Reports #49683

Open
3 of 4 tasks
lithomas1 opened this issue Nov 13, 2022 · 29 comments
Open
3 of 4 tasks

TRACKER: Getting Started with Meson/Bug Reports #49683

lithomas1 opened this issue Nov 13, 2022 · 29 comments
Labels
Build Library building on various platforms Master Tracker High level tracker for similar issues

Comments

@lithomas1
Copy link
Member

lithomas1 commented Nov 13, 2022

Background

In #49115, we are adding support for a new build system meson. This build system addresses some of the flaws of the setuptools-based build system, such as race conditions on parallel builds. It is also much simpler and easier to understand, and we'll be able to clean up a bunch of build related code once it's merged.

How to build/test with meson

# Create a new conda environment, or update your existing one
conda env create --file=environment.yml
# conda env update --file environment.yml --prune # For updating your existing environment, make sure "pandas-dev" is activated 
pip install oldest-supported-numpy>=0.10 # Needed since pip will not auto pull dependencies in no-build-isolation mode

# This is the build command. 
# On your first run, it'll create the build directory(named builddir here).
# Subsequent builds will re-use it.
pip install . -ve --no-build-isolation --config-settings="builddir=builddir" 

# If you want to debug, pass -Ddebug=true, e.g.
pip install . -ve --no-build-isolation --config-settings builddir="builddir" --config-settings setup-args="-Dbuildtype=debug"

# Test command (same as with pandas built by setuptools)
# e.g.
# Note: If you built pandas in editable mode, you now don't have to rebuild the C extensions every time you change a C/Cython file. It will now be automatically rebuilt on import.
pytest pandas

Timeline

  • Enable meson based builds in the CI( BLD: Setup meson builds #49115)
  • Move to using a stable version of meson/meson-python once all fixes have been upstreamed, and released.
  • Update documentation for setting up and building pandas with meson.
    - Mostly done. The debugging docs need to be updated
  • Remove all setuptools code.

Ideally, meson build support and removal of setuptools should be fully complete by 2.1 (the next minor release).

Known Issues

N/A.

Purpose of this thread

I've opened this thread to get some feedback and to track any build issues users might be having with meson.

@lithomas1 lithomas1 added Build Library building on various platforms Master Tracker High level tracker for similar issues labels Nov 13, 2022
@lithomas1 lithomas1 added this to the 2.0 milestone Nov 13, 2022
@fangchenli
Copy link
Member

fangchenli commented Nov 28, 2022

I propose a more gradual approach to meson (merge #49115).

  1. switch to nonvendor versioneer BLD: use nonvendor versioneer #49924.
  2. move project metadata to pyproject.toml BLD: Move options to pyproject.toml #49917
  3. enable PEP 517 using setuptools; make all necessary changes to CI and doc.
  4. merge all meson build scripts, and add a separate CI job to test meson.

At this point, almost everything in #49115 would be included. Then we could wait for the editable wheel and all the other necessary features/fixes on meson. When everyone is satisfied, we then modify the backend setting in pyproject.toml to make the final switch.

@lithomas1
Copy link
Member Author

I would not go forward with setuptools PEP 517, since it's just going to get replaced by meson, and you can't have two build systems in pyproject.toml.

The reason it is safe to modify the backend setting in pyproject.toml now, is because that it doesn't break people with editable installs(pip is smart enough to fall back to setup.py develop).

At this point, almost everything in #49115 would be included. Then we could wait for the editable wheel and all the other necessary features/fixes on meson. When everyone is satisfied, we then modify the backend setting in pyproject.toml to make the final switch.

The problem is that meson builds won't work until the build backend is set to pyproject.toml. I would also really not prefer waiting. It is really hard to keep the meson PR open and up to date, and even if you can't really use meson locally without the editable installs, I think the reduction in CI time is well worth it.

@mroeschke mroeschke modified the milestones: 2.0, 3.0 Feb 8, 2023
@lithomas1 lithomas1 pinned this issue May 11, 2023
@MarcoGorelli
Copy link
Member

Am trying to build pandas locally with meson. I'm on commit c96dbb7

here's what I've done:

python3.10 -m virtualenv .venv
. .venv/bin/activate
pip install -r requirements-dev.txt 
python -m pip install -ve . --no-build-isolation

and here's what I get:

Using pip 23.1.2 from /home/marcogorelli/pandas-dev-2/.venv/lib/python3.10/site-packages/pip (python 3.10)
Obtaining file:///home/marcogorelli/pandas-dev-2
  Running command Checking if build backend supports build_editable
  Checking if build backend supports build_editable ... done
  Running command Preparing editable metadata (pyproject.toml)
  + meson setup /home/marcogorelli/pandas-dev-2 /home/marcogorelli/pandas-dev-2/build/cp310 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --vsenv --native-file=/home/marcogorelli/pandas-dev-2/build/cp310/meson-python-native-file.ini
  The Meson build system
  Version: 1.0.1
  Source dir: /home/marcogorelli/pandas-dev-2
  Build dir: /home/marcogorelli/pandas-dev-2/build/cp310
  Build type: native build
  Project name: pandas
  Project version: 2.1.0.dev0+779.gc96dbb77eb
  C compiler for the host machine: cc (gcc 11.3.0 "cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0")
  C linker for the host machine: cc ld.bfd 2.38
  C++ compiler for the host machine: c++ (gcc 11.3.0 "c++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0")
  C++ linker for the host machine: c++ ld.bfd 2.38
  Cython compiler for the host machine: cython (cython 0.29.33)
  Host machine cpu family: x86_64
  Host machine cpu: x86_64
  Program python found: YES (/home/marcogorelli/pandas-dev-2/.venv/bin/python)
  Found pkg-config: /usr/bin/pkg-config (0.29.2)

  ../../pandas/meson.build:9:0: ERROR: Tried to form an absolute path to a dir in the source tree.
  You should not do that but use relative paths instead, for
  directories that are part of your project.

  To get include path to any directory relative to the current dir do

  incdir = include_directories(dirname)

  After this incdir will contain both the current source dir as well as the
  corresponding build dir. It can then be used in any subdirectory and
  Meson will take care of all the busywork to make paths work.

  Dirname can even be '.' to mark the current directory. Though you should
  remember that the current source and build directories are always
  put in the include directories by default so you only need to do
  include_directories('.') if you intend to use the result in a
  different subdirectory.

  Note that this error message can also be triggered by
  external dependencies being installed within your source
  tree - it's not recommended to do this.


  A full log can be found at /home/marcogorelli/pandas-dev-2/build/cp310/meson-logs/meson-log.txt
  error: subprocess-exited-with-error
  
  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /home/marcogorelli/pandas-dev-2/.venv/bin/python /home/marcogorelli/pandas-dev-2/.venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py prepare_metadata_for_build_editable /tmp/tmph1bxuey_
  cwd: /home/marcogorelli/pandas-dev-2
  Preparing editable metadata (pyproject.toml) ... error
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

has anyone come across this?

@lithomas1
Copy link
Member Author

Hm. I think the issue might be that the venv is stored in a folder within the pandas repo?
(so the numpy package would be installed somewhere in .venv)

In general, I don't think meson likes absolute paths if they are within the repo you're trying to build.

We might need to steal scipy's code for this.
Maybe something like https://github.com/scipy/scipy/blob/bae3476b8a245866f5f7f1b824a0a7919f3880a9/scipy/meson.build#L54-L58?

@lithomas1 lithomas1 modified the milestones: 3.0, 2.1 May 17, 2023
@eli-schwartz
Copy link
Contributor

eli-schwartz commented May 17, 2023

  Note that this error message can also be triggered by
  external dependencies being installed within your source
  tree - it's not recommended to do this.

This snippet of the error message was added by @rgommers to provide a hint about the problem. The relpath trick seems apropos here, indeed.

(More generally, the long-term idea is to create some dependency interface for numpy, so people can just use that directly and not need to worry about running numpy.get_include() via manual code snippets.)

@rgommers
Copy link
Contributor

We might need to steal scipy's code for this.
Maybe something like https://github.com/scipy/scipy/blob/bae3476b8a245866f5f7f1b824a0a7919f3880a9/scipy/meson.build#L54-L58?

Indeed, that should fix it - you need a few more lines, down to:

np_dep = declare_dependency(include_directories: inc_np)

@MarcoGorelli
Copy link
Member

MarcoGorelli commented May 18, 2023

Hm. I think the issue might be that the venv is stored in a folder within the pandas repo?

That's right - I've now created a virtualenv in a different folder (~/.virtualenvs/pandas), and it all works like a charm

Admittedly the pandas docs do say to do that, but I'm so used to python -m venv .venv from virtually every other project that I missed that (and it used to work fine when using setup.py, so I thought it was optional to create it in a different folder. Perhaps I'll clarify the docs noting that it's not optional)

@fangchenli
Copy link
Member

I ran into this today.

(pandas-dev) fangchenli@Fangchens-MacBook-Pro-2 pandas-fangchenli % pip install -e . --no-build-isolation -v
Using pip 23.1.2 from /Users/fangchenli/mambaforge/envs/pandas-dev/lib/python3.10/site-packages/pip (python 3.10)
Obtaining file:///Users/fangchenli/Workspace/pandas-fangchenli
  Running command Checking if build backend supports build_editable
  Checking if build backend supports build_editable ... done
  Running command Preparing editable metadata (pyproject.toml)
  + meson setup --reconfigure /Users/fangchenli/Workspace/pandas-fangchenli /Users/fangchenli/Workspace/pandas-fangchenli/build/cp310 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --vsenv --native-file=/Users/fangchenli/Workspace/pandas-fangchenli/build/cp310/meson-python-native-file.ini
  Cleaning... 0 files.
  The Meson build system
  Version: 1.0.1
  Source dir: /Users/fangchenli/Workspace/pandas-fangchenli
  Build dir: /Users/fangchenli/Workspace/pandas-fangchenli/build/cp310
  Build type: native build
  Project name: pandas
  Project version: 2.1.0.dev0+901.g4d217a42f0
  C compiler for the host machine: arm64-apple-darwin20.0.0-clang (clang 14.0.6 "clang version 14.0.6")
  C linker for the host machine: arm64-apple-darwin20.0.0-clang ld64 609
  C++ compiler for the host machine: arm64-apple-darwin20.0.0-clang++ (clang 14.0.6 "clang version 14.0.6")
  C++ linker for the host machine: arm64-apple-darwin20.0.0-clang++ ld64 609
  Cython compiler for the host machine: cython (cython 0.29.34)
  Host machine cpu family: aarch64
  Host machine cpu: aarch64
  Program python found: YES (/Users/fangchenli/mambaforge/envs/pandas-dev/bin/python3.10)
  Build targets in project: 54

  pandas 2.1.0.dev0+901.g4d217a42f0

    User defined options
      Native files: /Users/fangchenli/Workspace/pandas-fangchenli/build/cp310/meson-python-native-file.ini
      buildtype   : release
      b_ndebug    : if-release
      b_vscrt     : md

  Found ninja-1.11.1 at /Users/fangchenli/mambaforge/envs/pandas-dev/bin/ninja
  + /Users/fangchenli/mambaforge/envs/pandas-dev/bin/ninja
  [1/79] Generating pandas/_libs/algos_common_helper_pxi with a custom command
  [2/79] Generating pandas/_libs/hashtable_class_helper_pxi with a custom command
  [3/79] Generating pandas/_libs/algos_take_helper_pxi with a custom command
  [4/79] Generating pandas/_libs/khash_primitive_helper_pxi with a custom command
  [5/79] Generating pandas/_libs/index_class_helper_pxi with a custom command
  [6/79] Generating pandas/_libs/intervaltree_helper_pxi with a custom command
  [7/79] Generating pandas/_libs/sparse_op_helper_pxi with a custom command
  [8/79] Generating pandas/_libs/hashtable_func_helper_pxi with a custom command
  [9/79] Linking target pandas/_libs/arrays.cpython-310-darwin.so
  ld: warning: -pie being ignored. It is only used when linking a main executable
  [10/79] Linking target pandas/_libs/hashing.cpython-310-darwin.so
  ld: warning: -pie being ignored. It is only used when linking a main executable
  [11/79] Linking target pandas/_libs/indexing.cpython-310-darwin.so
  ld: warning: -pie being ignored. It is only used when linking a main executable
  [12/79] Linking target pandas/_libs/internals.cpython-310-darwin.so
  ld: warning: -pie being ignored. It is only used when linking a main executable
  [13/79] Generating write_version_file with a custom command
  [14/79] Compiling C object pandas/_libs/tslibs/timedeltas.cpython-310-darwin.so.p/meson-generated_pandas__libs_tslibs_timedeltas.pyx.c.o
  FAILED: pandas/_libs/tslibs/timedeltas.cpython-310-darwin.so.p/meson-generated_pandas__libs_tslibs_timedeltas.pyx.c.o
  arm64-apple-darwin20.0.0-clang -Ipandas/_libs/tslibs/timedeltas.cpython-310-darwin.so.p -Ipandas/_libs/tslibs -I../../pandas/_libs/tslibs -I../../../../mambaforge/envs/pandas-dev/lib/python3.10/site-packages/numpy/core/include -I../../pandas/_libs/include -I/Users/fangchenli/mambaforge/envs/pandas-dev/include/python3.10 -fvisibility=hidden -fcolor-diagnostics -DNDEBUG -w -std=c99 -O3 -DNPY_NO_DEPRECATED_API=0 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /Users/fangchenli/mambaforge/envs/pandas-dev/include -D_FORTIFY_SOURCE=2 -isystem /Users/fangchenli/mambaforge/envs/pandas-dev/include -MD -MQ pandas/_libs/tslibs/timedeltas.cpython-310-darwin.so.p/meson-generated_pandas__libs_tslibs_timedeltas.pyx.c.o -MF pandas/_libs/tslibs/timedeltas.cpython-310-darwin.so.p/meson-generated_pandas__libs_tslibs_timedeltas.pyx.c.o.d -o pandas/_libs/tslibs/timedeltas.cpython-310-darwin.so.p/meson-generated_pandas__libs_tslibs_timedeltas.pyx.c.o -c pandas/_libs/tslibs/timedeltas.cpython-310-darwin.so.p/pandas/_libs/tslibs/timedeltas.pyx.c
  pandas/_libs/tslibs/timedeltas.cpython-310-darwin.so.p/pandas/_libs/tslibs/timedeltas.pyx.c:755:10: fatal error: 'src/datetime/pd_datetime.h' file not found
  #include "src/datetime/pd_datetime.h"
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1 error generated.
  [15/79] Compiling C object pandas/_libs/lib.cpython-310-darwin.so.p/src_parser_tokenizer.c.o
  [16/79] Compiling C object pandas/_libs/index.cpython-310-darwin.so.p/meson-generated_pandas__libs_index.pyx.c.o
  FAILED: pandas/_libs/index.cpython-310-darwin.so.p/meson-generated_pandas__libs_index.pyx.c.o
  arm64-apple-darwin20.0.0-clang -Ipandas/_libs/index.cpython-310-darwin.so.p -Ipandas/_libs -I../../pandas/_libs -I../../../../mambaforge/envs/pandas-dev/lib/python3.10/site-packages/numpy/core/include -I../../pandas/_libs/include -I/Users/fangchenli/mambaforge/envs/pandas-dev/include/python3.10 -fvisibility=hidden -fcolor-diagnostics -DNDEBUG -w -std=c99 -O3 -DNPY_NO_DEPRECATED_API=0 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /Users/fangchenli/mambaforge/envs/pandas-dev/include -D_FORTIFY_SOURCE=2 -isystem /Users/fangchenli/mambaforge/envs/pandas-dev/include -MD -MQ pandas/_libs/index.cpython-310-darwin.so.p/meson-generated_pandas__libs_index.pyx.c.o -MF pandas/_libs/index.cpython-310-darwin.so.p/meson-generated_pandas__libs_index.pyx.c.o.d -o pandas/_libs/index.cpython-310-darwin.so.p/meson-generated_pandas__libs_index.pyx.c.o -c pandas/_libs/index.cpython-310-darwin.so.p/pandas/_libs/index.pyx.c
  pandas/_libs/index.cpython-310-darwin.so.p/pandas/_libs/index.pyx.c:756:10: fatal error: 'khash_python.h' file not found
  #include "khash_python.h"
           ^~~~~~~~~~~~~~~~
  1 error generated.

@lithomas1
Copy link
Member Author

You'll need to remove the build folder I think, and do a clean rebuild.

I don't think meson tracked when the include directory changed, so didn't mark the affected files as needing a rebuild.

@WillAyd
Copy link
Member

WillAyd commented Jun 23, 2023

When running in a docker container where there is no command python but instead just python3, running:

python3 -m pip install -ve . --no-build-isolation --config-settings=builddir="cython-debug" --config-settings=setup-args="-Dbuildtype=debug"

I get an error ../meson.build:5:13: ERROR: Program or command 'python' not found or not executable. Easy enough to resolve with a symlink but guessing meson should handle this more robustly? Especially since it is being explicitly invoked with python3

@WillAyd
Copy link
Member

WillAyd commented Jun 23, 2023

There are also some challenges getting the Cython debugger to work with meson. In setuptools you could hack this by adding kwargs["gdb_debug"] = True to the cythonize call. That adds a cython_debug folder to the source tree that cy run will pick up. Not sure if/how meson could handle that

@eli-schwartz
Copy link
Contributor

eli-schwartz commented Jun 23, 2023

I get an error ../meson.build:5:13: ERROR: Program or command 'python' not found or not executable. Easy enough to resolve with a symlink but guessing meson should handle this more robustly? Especially since it is being explicitly invoked with python3

version: run_command(['python', 'generate_version.py', '--print'], check: true).stdout().strip(),

Meson itself doesn't run python here -- if this were python3 though, then run_command would either look up a python3 command or fall back to using the same sys.executable (regardless of precise name) that is being used to run meson's own code.

There are also some challenges getting the Cython debugger to work with meson. In setuptools you could hack this by adding kwargs["gdb_debug"] = True to the cythonize call. That adds a cython_debug folder to the source tree that cy run will pick up. Not sure if/how meson could handle that

What happens if you add --gdb to cython_args in meson?

@WillAyd
Copy link
Member

WillAyd commented Jun 23, 2023

Ah cool thanks for the insight. So we should just make that python3 huh?

For Cython, I got it to work doing similar to what you suggest:

cython_args = ['--include-dir', meson.current_build_dir()]
if get_option('buildtype') == 'debug'
    cython_args += ['--gdb']
endif

Then passing cython args to the extension module

The nuance from there is that you need to run cygdb from the build folder, not project root. I think cygdb is supposed to allow you to specify where to find the Cython debug files, but there might be a bug in that for now. A few things to work on but I think I'll have a PR up in a few hours to help on these items

@johannes-mueller
Copy link
Contributor

After reading the docs I am unsure how I am supposed to rebuild the cython extensions once I modified a cython file. In times of setuptools I did something like python setup.py build_ext. What is the canonical way in the meson era?

@lithomas1
Copy link
Member Author

lithomas1 commented Sep 2, 2023

@marenwestermann
Copy link
Contributor

I tried to re-build pandas with meson yesterday. I had built it before via setup.py. I ran the following commands:

python -m pip uninstall pandas
python -m pip install -ve . --no-build-isolation --config-settings editable-verbose=true

When trying to build pandas with meson I got the following error:

(pandas-dev) ➜  pandas-maren git:(main) python -m pip install -ve . --no-build-isolation --config-settings editable-verbose=true

Using pip 24.0 from /Users/maren/mambaforge/envs/pandas-dev/lib/python3.10/site-packages/pip (python 3.10)
Obtaining file:///Users/maren/open-source/pandas-maren
  Running command Checking if build backend supports build_editable
  Checking if build backend supports build_editable ... done
  Running command Preparing editable metadata (pyproject.toml)
  + meson setup --reconfigure /Users/maren/open-source/pandas-maren /Users/maren/open-source/pandas-maren/build/cp310 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --vsenv --native-file=/Users/maren/open-source/pandas-maren/build/cp310/meson-python-native-file.ini
  Cleaning... 0 files.
  The Meson build system
  Version: 1.2.1
  Source dir: /Users/maren/open-source/pandas-maren
  Build dir: /Users/maren/open-source/pandas-maren/build/cp310
  Build type: native build
  Project name: pandas
  Project version: 3.0.0.dev0+486.g03717bcc5a
  C compiler for the host machine: arm64-apple-darwin20.0.0-clang (clang 16.0.6 "clang version 16.0.6")
  C linker for the host machine: arm64-apple-darwin20.0.0-clang ld64 609
  C++ compiler for the host machine: arm64-apple-darwin20.0.0-clang++ (clang 16.0.6 "clang version 16.0.6")
  C++ linker for the host machine: arm64-apple-darwin20.0.0-clang++ ld64 609
  Cython compiler for the host machine: cython (cython 3.0.9)
  Host machine cpu family: aarch64
  Host machine cpu: aarch64
  Program python found: YES (/Users/maren/mambaforge/envs/pandas-dev/bin/python)
  Build targets in project: 54

  pandas 3.0.0.dev0+486.g03717bcc5a

    User defined options
      Native files: /Users/maren/open-source/pandas-maren/build/cp310/meson-python-native-file.ini
      buildtype   : release
      vsenv       : True
      b_ndebug    : if-release
      b_vscrt     : md

  Found ninja-1.11.1 at /Users/maren/mambaforge/envs/pandas-dev/bin/ninja

  Visual Studio environment is needed to run Ninja. It is recommended to use Meson wrapper:
  /Users/maren/mambaforge/envs/pandas-dev/bin/meson compile -C .
  + /Users/maren/mambaforge/envs/pandas-dev/bin/ninja
  [1/78] Linking target pandas/_libs/arrays.cpython-310-darwin.so
  [2/78] Linking target pandas/_libs/groupby.cpython-310-darwin.so
  [3/78] Generating write_version_file with a custom command
  [4/78] Compiling C object pandas/_libs/pandas_datetime.cpython-310-darwin.so.p/src_vendored_numpy_datetime_np_datetime.c.o
  [5/78] Compiling C object pandas/_libs/pandas_datetime.cpython-310-darwin.so.p/src_vendored_numpy_datetime_np_datetime_strings.c.o
  [6/78] Compiling C object pandas/_libs/pandas_datetime.cpython-310-darwin.so.p/src_datetime_date_conversions.c.o
  [7/78] Compiling C object pandas/_libs/pandas_datetime.cpython-310-darwin.so.p/src_datetime_pd_datetime.c.o
  [8/78] Compiling C object pandas/_libs/join.cpython-310-darwin.so.p/meson-generated_pandas__libs_join.pyx.c.o
  FAILED: pandas/_libs/join.cpython-310-darwin.so.p/meson-generated_pandas__libs_join.pyx.c.o
  arm64-apple-darwin20.0.0-clang -Ipandas/_libs/join.cpython-310-darwin.so.p -Ipandas/_libs -I../../pandas/_libs -I../../../../mambaforge/envs/pandas-dev/lib/python3.10/site-packages/numpy/core/include -I../../pandas/_libs/include -I/Users/maren/mambaforge/envs/pandas-dev/include/python3.10 -fvisibility=hidden -fcolor-diagnostics -DNDEBUG -w -std=c11 -O3 -DNPY_NO_DEPRECATED_API=0 -DNPY_TARGET_VERSION=NPY_1_21_API_VERSION -ftree-vectorize -fPIC -fstack-protector-strong -O2 -pipe -isystem /Users/maren/mambaforge/envs/pandas-dev/include -D_FORTIFY_SOURCE=2 -isystem /Users/maren/mambaforge/envs/pandas-dev/include -MD -MQ pandas/_libs/join.cpython-310-darwin.so.p/meson-generated_pandas__libs_join.pyx.c.o -MF pandas/_libs/join.cpython-310-darwin.so.p/meson-generated_pandas__libs_join.pyx.c.o.d -o pandas/_libs/join.cpython-310-darwin.so.p/meson-generated_pandas__libs_join.pyx.c.o -c pandas/_libs/join.cpython-310-darwin.so.p/pandas/_libs/join.pyx.c
  pandas/_libs/join.cpython-310-darwin.so.p/pandas/_libs/join.pyx.c:1203:10: fatal error: 'khash_python.h' file not found
  #include "khash_python.h"
           ^~~~~~~~~~~~~~~~
  1 error generated.
  [9/78] Linking target pandas/_libs/pandas_datetime.cpython-310-darwin.so
  [10/78] Compiling C object pandas/_libs/interval.cpython-310-darwin.so.p/meson-generated_pandas__libs_interval.pyx.c.o
  FAILED: pandas/_libs/interval.cpython-310-darwin.so.p/meson-generated_pandas__libs_interval.pyx.c.o
  arm64-apple-darwin20.0.0-clang -Ipandas/_libs/interval.cpython-310-darwin.so.p -Ipandas/_libs -I../../pandas/_libs -I../../../../mambaforge/envs/pandas-dev/lib/python3.10/site-packages/numpy/core/include -I../../pandas/_libs/include -I/Users/maren/mambaforge/envs/pandas-dev/include/python3.10 -fvisibility=hidden -fcolor-diagnostics -DNDEBUG -w -std=c11 -O3 -DNPY_NO_DEPRECATED_API=0 -DNPY_TARGET_VERSION=NPY_1_21_API_VERSION -ftree-vectorize -fPIC -fstack-protector-strong -O2 -pipe -isystem /Users/maren/mambaforge/envs/pandas-dev/include -D_FORTIFY_SOURCE=2 -isystem /Users/maren/mambaforge/envs/pandas-dev/include -MD -MQ pandas/_libs/interval.cpython-310-darwin.so.p/meson-generated_pandas__libs_interval.pyx.c.o -MF pandas/_libs/interval.cpython-310-darwin.so.p/meson-generated_pandas__libs_interval.pyx.c.o.d -o pandas/_libs/interval.cpython-310-darwin.so.p/meson-generated_pandas__libs_interval.pyx.c.o -c pandas/_libs/interval.cpython-310-darwin.so.p/pandas/_libs/interval.pyx.c
  pandas/_libs/interval.cpython-310-darwin.so.p/pandas/_libs/interval.pyx.c:1259:10: fatal error: 'khash_python.h' file not found
  #include "khash_python.h"
           ^~~~~~~~~~~~~~~~
  1 error generated.
  [11/78] Compiling C object pandas/_libs/algos.cpython-310-darwin.so.p/meson-generated_pandas__libs_algos.pyx.c.o
  FAILED: pandas/_libs/algos.cpython-310-darwin.so.p/meson-generated_pandas__libs_algos.pyx.c.o
  arm64-apple-darwin20.0.0-clang -Ipandas/_libs/algos.cpython-310-darwin.so.p -Ipandas/_libs -I../../pandas/_libs -I../../../../mambaforge/envs/pandas-dev/lib/python3.10/site-packages/numpy/core/include -I../../pandas/_libs/include -I/Users/maren/mambaforge/envs/pandas-dev/include/python3.10 -fvisibility=hidden -fcolor-diagnostics -DNDEBUG -w -std=c11 -O3 -DNPY_NO_DEPRECATED_API=0 -DNPY_TARGET_VERSION=NPY_1_21_API_VERSION -ftree-vectorize -fPIC -fstack-protector-strong -O2 -pipe -isystem /Users/maren/mambaforge/envs/pandas-dev/include -D_FORTIFY_SOURCE=2 -isystem /Users/maren/mambaforge/envs/pandas-dev/include -MD -MQ pandas/_libs/algos.cpython-310-darwin.so.p/meson-generated_pandas__libs_algos.pyx.c.o -MF pandas/_libs/algos.cpython-310-darwin.so.p/meson-generated_pandas__libs_algos.pyx.c.o.d -o pandas/_libs/algos.cpython-310-darwin.so.p/meson-generated_pandas__libs_algos.pyx.c.o -c pandas/_libs/algos.cpython-310-darwin.so.p/pandas/_libs/algos.pyx.c
  pandas/_libs/algos.cpython-310-darwin.so.p/pandas/_libs/algos.pyx.c:1208:10: fatal error: 'khash_python.h' file not found
  #include "khash_python.h"
           ^~~~~~~~~~~~~~~~
  1 error generated.
  [12/78] Compiling C object pandas/_libs/pandas_parser.cpython-310-darwin.so.p/src_parser_tokenizer.c.o
  [13/78] Compiling Cython source /Users/maren/open-source/pandas-maren/pandas/_libs/missing.pyx
  warning: /Users/maren/open-source/pandas-maren/pandas/_libs/tslibs/util.pxd:188:38: noexcept clause is ignored for function returning Python object
  warning: /Users/maren/open-source/pandas-maren/pandas/_libs/tslibs/util.pxd:193:40: noexcept clause is ignored for function returning Python object
  [14/78] Compiling Cython source /Users/maren/open-source/pandas-maren/pandas/_libs/index.pyx
  FAILED: pandas/_libs/index.cpython-310-darwin.so.p/pandas/_libs/index.pyx.c
  cython -M --fast-fail -3 --include-dir /Users/maren/open-source/pandas-maren/build/cp310/pandas/_libs '-X always_allow_keywords=true' /Users/maren/open-source/pandas-maren/pandas/_libs/index.pyx -o pandas/_libs/index.cpython-310-darwin.so.p/pandas/_libs/index.pyx.c
  warning: /Users/maren/open-source/pandas-maren/pandas/_libs/tslibs/util.pxd:188:38: noexcept clause is ignored for function returning Python object
  warning: /Users/maren/open-source/pandas-maren/pandas/_libs/tslibs/util.pxd:193:40: noexcept clause is ignored for function returning Python object

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
          if not util.is_bool_object(val):
              raise KeyError(val)
          return <uint8_t>val


  cdef class MaskedBoolEngine(MaskedUInt8Engine):
                              ^
  ------------------------------------------------------------

  /Users/maren/open-source/pandas-maren/pandas/_libs/index.pyx:823:28: First base of 'MaskedBoolEngine' is not an extension type
  [15/78] Compiling Cython source /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable.pyx
  FAILED: pandas/_libs/hashtable.cpython-310-darwin.so.p/pandas/_libs/hashtable.pyx.c
  cython -M --fast-fail -3 --include-dir /Users/maren/open-source/pandas-maren/build/cp310/pandas/_libs '-X always_allow_keywords=true' /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable.pyx -o pandas/_libs/hashtable.cpython-310-darwin.so.p/pandas/_libs/hashtable.pyx.c
  warning: /Users/maren/open-source/pandas-maren/pandas/_libs/tslibs/util.pxd:188:38: noexcept clause is ignored for function returning Python object
  warning: /Users/maren/open-source/pandas-maren/pandas/_libs/tslibs/util.pxd:193:40: noexcept clause is ignored for function returning Python object
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:7:5: Exception check on 'to_khcomplex64_t' will always require the GIL to be acquired. Declare 'to_khcomplex64_t' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:12:5: Exception check on 'to_khcomplex128_t' will always require the GIL to be acquired. Declare 'to_khcomplex128_t' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:211:5: Exception check on 'append_data_complex128' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_complex128' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_complex128' to allow an error code to be returned.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:226:5: Exception check on 'append_data_complex64' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_complex64' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_complex64' to allow an error code to be returned.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:241:5: Exception check on 'append_data_float64' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_float64' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_float64' to allow an error code to be returned.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:256:5: Exception check on 'append_data_float32' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_float32' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_float32' to allow an error code to be returned.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:265:5: Exception check on 'append_data_int64' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_int64' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_int64' to allow an error code to be returned.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:280:5: Exception check on 'append_data_int32' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_int32' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_int32' to allow an error code to be returned.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:295:5: Exception check on 'append_data_int16' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_int16' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_int16' to allow an error code to be returned.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:310:5: Exception check on 'append_data_int8' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_int8' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_int8' to allow an error code to be returned.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:325:5: Exception check on 'append_data_string' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_string' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_string' to allow an error code to be returned.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:340:5: Exception check on 'append_data_uint64' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_uint64' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_uint64' to allow an error code to be returned.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:355:5: Exception check on 'append_data_uint32' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_uint32' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_uint32' to allow an error code to be returned.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:370:5: Exception check on 'append_data_uint16' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_uint16' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_uint16' to allow an error code to be returned.
  performance hint: /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:385:5: Exception check on 'append_data_uint8' will always require the GIL to be acquired.
  Possible solutions:
        1. Declare 'append_data_uint8' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
        2. Use an 'int' return type on 'append_data_uint8' to allow an error code to be returned.

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
              self.ao.resize(self.data.n, refcheck=False)
              self.data.m = self.data.n
          self.external_view_exists = True
          return self.ao

      cdef void append(self, int64_t x):
           ^
  ------------------------------------------------------------

  /Users/maren/open-source/pandas-maren/pandas/_libs/hashtable_class_helper.pxi:679:9: Signature not compatible with previous declaration
  [16/78] Compiling C object pandas/_libs/internals.cpython-310-darwin.so.p/meson-generated_pandas__libs_internals.pyx.c.o
  [17/78] Compiling C object pandas/_libs/lib.cpython-310-darwin.so.p/meson-generated_pandas__libs_lib.pyx.c.o
  ninja: build stopped: subcommand failed.
  error: subprocess-exited-with-error

  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /Users/maren/mambaforge/envs/pandas-dev/bin/python /Users/maren/mambaforge/envs/pandas-dev/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py prepare_metadata_for_build_editable /var/folders/_6/1_k05w8n7mq50j5l_w81snrw0000gn/T/tmpsawqz5hy
  cwd: /Users/maren/open-source/pandas-maren
  Preparing editable metadata (pyproject.toml) ... error
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

I'm on an Apple M1 Pro computer and I'm on commit 03717bc with pandas version 3.0.0.dev0+486.g03717bcc5a.

@marenwestermann
Copy link
Contributor

marenwestermann commented Mar 24, 2024

After starting again from scratch (removing my local pandas repo and cloning it again as well as creating a new dev environment) I was able to successfully build pandas with meson. The good old "Have you tried turning it off and on again?" did the trick. 😄

@Aloqeely
Copy link
Member

Building pandas through a virtual environment works well for me, but today I tried doing it using a Docker container but it failed, to setup (Windows), I ran:

docker build -t pandas-dev .
docker run -it --rm -v ${PWD}:/home/pandas pandas-dev

Then:

python -m pip install -ve . --no-build-isolation --config-settings editable-verbose=true

Output:

 ../../meson.build:5:13: ERROR: Command `/home/pandas/generate_version.py --print` failed with status 127.

  A full log can be found at /home/pandas/build/cp310/meson-logs/meson-log.txt
  error: subprocess-exited-with-error

  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

And in the log file it said something about ‘python3\r’: No such file or directory (Don't recall the exact error).
I've managed to fix it by running dos2unix /home/pandas/generate_version.py which converts the file from windows-style line ending to unix-style (from this post https://askubuntu.com/questions/896860/usr-bin-env-python3-r-no-such-file-or-directory)

Is there a better way to fix this issue?

@eli-schwartz
Copy link
Contributor

Building pandas through a virtual environment works well for me, but today I tried doing it using a Docker container but it failed, to setup (Windows)

I don't know what you mean by this.

I've managed to fix it by running dos2unix /home/pandas/generate_version.py which converts the file from windows-style line ending to unix-style (from this post https://askubuntu.com/questions/896860/usr-bin-env-python3-r-no-such-file-or-directory)

Is there a better way to fix this issue?

Why was it ever in Windows-style to begin with? This sounds like git was very badly misconfigured to cause git clone to automatically convert all files in the repository away from their actual format and over to Windows line endings. This broke everything, and the first error was that the generate_version.py script couldn't parse as a script.

@Aloqeely
Copy link
Member

I don't know what you mean by this.

Just wanted to mention that I have successfully built pandas using Meson build system before.
But this time when using Meson and Docker, I am unable to

Why was it ever in Windows-style to begin with?

No clue, I don't ever remember playing around with my git installation

@eli-schwartz
Copy link
Contributor

When I say I don't know what you mean, I don't know what it means to build with Linux paths in docker, but with the word "Windows" in parentheses.

@Aloqeely
Copy link
Member

I just wanted to highlight that I am on a Windows machine

@Pooya-Oladazimi
Copy link

Pooya-Oladazimi commented Apr 25, 2024

python -m pip install -ve . --no-build-isolation --config-settings editable-verbose=true

OS: Linux Debian
Env Installation method: mamba

I am not sure if this is related or not. But I just installed Pandas from source and faced these issues in order:

Issue1

ModuleNotFoundError: No module named 'mesonpy'

Fixed:

pip install meson-python

Issue2

meson-python: error: Could not find ninja version 1.8.2 or newer.

Fixed:

pip install --force-reinstall ninja

Issue3

../../meson.build:5:13: ERROR: Command `/home/USER/miniforge3/bin/python3.10 /home/USER/PATH_TO_PANDAS/pandas/generate_version.py --print` failed with status 1.

Fixed:

pip install versioneer

Issue4

Detecting compiler via: `cython -V` -> [Errno 2] No such file or directory: 'cython'

Fixed:

pip install cython

Issue5

missing Numpy

fixed:

pip install numpy

After this it worked and I could import pandas and check the version.
I hope it will be useful.

@eli-schwartz
Copy link
Contributor

eli-schwartz commented Apr 25, 2024

https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-no-build-isolation

Disable isolation when building a modern source distribution. Build dependencies specified by PEP 518 must be already installed if this option is used.

So you have to manually install those build dependencies, which is rather awkward in the extreme. Back in the day, it just installed whichever ones you didn't yet have installed...

python -m build is better here as it has separate options for disabling build isolation vs skipping dependency checks, and by default it will error out if you're missing dependencies. However it also only builds and doesn't install in editable mode, which IIRC means it can't support editable mode at all.

This is arguably a bug in the editable installs standard itself.

@vkhodygo
Copy link

vkhodygo commented Jun 5, 2024

My Linux Meson build fails successfully. I tried to run in it a fresh environment, no result so far.

python -m pip install -ve . --no-build-isolation --config-settings editable-verbose=true
Using pip 24.0 from /home/USER/micromamba/envs/pandas-dev/lib/python3.10/site-packages/pip (python 3.10)
Obtaining file:///tmp/pandas
  Running command Checking if build backend supports build_editable
  Checking if build backend supports build_editable ... done
  Running command Preparing editable metadata (pyproject.toml)
  + meson setup /tmp/pandas /tmp/pandas/build/cp310 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --vsenv --native-file=/tmp/pandas/build/cp310/meson-python-native-file.ini
  The Meson build system
  Version: 1.2.1
  Source dir: /tmp/pandas
  Build dir: /tmp/pandas/build/cp310
  Build type: native build
  Project name: pandas
  Project version: 3.0.0.dev0+1079.g9e7abc84a1
  C compiler for the host machine: /home/USER/micromamba/envs/pandas-dev/bin/x86_64-conda-linux-gnu-cc (gcc 12.3.0 "x86_64-conda-linux-gnu-cc (conda-forge gcc 12.3.0-7) 12.3.0")
  C linker for the host machine: /home/USER/micromamba/envs/pandas-dev/bin/x86_64-conda-linux-gnu-cc ld.bfd 2.40
  C++ compiler for the host machine: /home/USER/micromamba/envs/pandas-dev/bin/x86_64-conda-linux-gnu-c++ (gcc 12.3.0 "x86_64-conda-linux-gnu-c++ (conda-forge gcc 12.3.0-7) 12.3.0")
  C++ linker for the host machine: /home/USER/micromamba/envs/pandas-dev/bin/x86_64-conda-linux-gnu-c++ ld.bfd 2.40
  Cython compiler for the host machine: cython (cython 3.0.10)
  Host machine cpu family: x86_64
  Host machine cpu: x86_64
  Program python found: YES (/home/USER/micromamba/envs/pandas-dev/bin/python)

  ../../pandas/meson.build:1:15: ERROR: Command `/home/USER/micromamba/envs/pandas-dev/bin/python -c '
  import os
  import numpy as np
  try:
      # Check if include directory is inside the pandas dir
      # e.g. a venv created inside the pandas dir
      # If so, convert it to a relative path
      incdir = os.path.relpath(np.get_include())
  except Exception:
      incdir = np.get_include()
  print(incdir)
       '` failed with status 1.

  A full log can be found at /tmp/pandas/build/cp310/meson-logs/meson-log.txt
  error: subprocess-exited-with-error
  
  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /home/USER/micromamba/envs/pandas-dev/bin/python /home/USER/micromamba/envs/pandas-dev/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py prepare_metadata_for_build_editable /tmp/tmp9ki4obxi
  cwd: /tmp/pandas
  Preparing editable metadata (pyproject.toml) ... error
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

meson-log.txt

@lithomas1
Copy link
Member Author

Do you have a copy of numpy installed?

@vkhodygo
Copy link

vkhodygo commented Jun 6, 2024

@lithomas1 I do. Is this relevant somehow? What's the point of a virtual environment if it still relies on system packages?

@pwm1234-sri
Copy link

As @Aloqeely mentions, I reported the same issue in #59000. As I mentioned in that issue, I do not know how CRLF's got in the file. My suggestion is to add eol=lf to line 1 in .gitattributes, but I readily admit I am no expert in the proper way to configure line-endings in git. This, however, is the suggestion in the vscode dev container documentation for a different but related issue.

@Liam3851
Copy link
Contributor

Liam3851 commented Nov 27, 2024

I have the same error as @vkhodygo (#49683 (comment)) but on Windows. Was there ever a fix? To confirm, numpy is installed in the activated conda environment. This is the error on the meson log, not sure what to make of it:

'utf-8' codec can't decode byte 0x90 in position 2: invalid start byte
Unusable script 'G:\\Miniconda3\\envs\\pandas-dev\\python.exe'
Program python found: YES (G:\Miniconda3\envs\pandas-dev\python.exe)
Running command: G:\Miniconda3\envs\pandas-dev\python.exe -c "
import os
import numpy as np
try:
    # Check if include directory is inside the pandas dir
    # e.g. a venv created inside the pandas dir
    # If so, convert it to a relative path
    incdir = os.path.relpath(np.get_include())
except Exception:
    incdir = np.get_include()
print(incdir)
     "
--- stdout ---

--- stderr ---
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized

Running that command at the command line works just fine, including with the provided -c script, making it all the more puzzling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Library building on various platforms Master Tracker High level tracker for similar issues
Projects
None yet
Development

No branches or pull requests