How to install trax, jax, jaxlib on M1 Mac on macOS 12? - python

trax
New to trax, I'm trying to run it locally (macOS 12.1, Apple Silicon ARM M1 processor, 8GB RAM, Anaconda), but I'm running into some issues.
In an environment with python 3.8.5, I installed trax running pip3 install trax==1.3.9 inside an (Anaconda) conda environment. Later, I ran into issues when trying to import trax layers in my code with from trax import layers as tl
RuntimeError: This version of jaxlib was built using AVX instructions, which your CPU and/or operating system do not support. You may be able work around this issue by building jaxlib from source.
I rushed to start a new conda environment with python 3.10. Then ran into issue just trying to install trax:
macos ERROR: Could not find a version that satisfies the requirement tensorflow-text (from trax) (from versions: none)
ERROR: No matching distribution found for tensorflow-text
I then created a new environment with python 3.9. Installation went fine, but then ran into the same error importing layers:
RuntimeError: This version of jaxlib was built using AVX instructions, which your CPU and/or operating system do not support. You may be able work around this issue by building jaxlib from source.
installing jaxlib, jax before trax
I then tried building jaxlib from source following these instructions and got this error:
Building XLA and installing it in the jaxlib source tree...
./bazel-4.2.1-darwin-x86_64 run --verbose_failures=true --config=avx_posix --config=mkl_open_source_only :build_wheel -- --output_path=/my path/jax/dist --cpu=x86_64
ERROR: bazel does not currently work properly from paths containing spaces (/my path/jax).
b''
Traceback (most recent call last):
File "/my path/jax/build/build.py", line 524, in <module>
main()
File "/my path/jax/build/build.py", line 519, in main
shell(command)
File "/my path/jax/build/build.py", line 53, in shell
output = subprocess.check_output(cmd)
File "/myuserpath/opt/anaconda3/envs/mytraxenv/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/myuserpath/opt/anaconda3/envs/mytraxenv/lib/python3.9/subprocess.py", line 528, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['./bazel-4.2.1-darwin-x86_64', 'run', '--verbose_failures=true', '--config=avx_posix', '--config=mkl_open_source_only', ':build_wheel', '--', '--output_path=/my path/jax/dist', '--cpu=x86_64']' returned non-zero exit status 36.
Emphasis on the part that I initially missed that says: bazel does not currently work properly from paths containing spaces (/my path/jax).
I moved my /my path/ directory to a path without spaces /mypath/. Deleted and redownloaded jax directory. Still, the build (for CPU) with python build/build.py failed:
ERROR: /private/var/tmp/_bazel_a/2caf512c3c5e3f3f654bc58b48b8333a/external/llvm-project/llvm/BUILD.bazel:610:11: Generating code from table: include/llvm/IR/Intrinsics.td #llvm-project//llvm:intrinsic_XCore_gen__gen_intrinsic_enums__intrinsic_prefix_xcore_genrule failed: (Illegal instruction): bash failed: error executing command
(cd /private/var/tmp/_bazel_a/2caf512c3c5e3f3f654bc58b48b8333a/execroot/__main__ && \
exec env - \
PATH=/myuserpath/opt/anaconda3/envs/mytraxenv/bin:/myuserpath/opt/anaconda3/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin \
/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/darwin-opt/bin/external/llvm-project/llvm/llvm-tblgen -I external/llvm-project/llvm/include -I external/llvm-project/clang/include -I $(dirname external/llvm-project/llvm/include/llvm/IR/Intrinsics.td) -gen-intrinsic-enums -intrinsic-prefix=xcore external/llvm-project/llvm/include/llvm/IR/Intrinsics.td -o bazel-out/darwin-opt/bin/external/llvm-project/llvm/include/llvm/IR/IntrinsicsXCore.h')
Execution platform: #local_execution_config_platform//:platform
/bin/bash: line 1: 11140 Illegal instruction: 4 bazel-out/darwin-opt/bin/external/llvm-project/llvm/llvm-tblgen -I external/llvm-project/llvm/include -I external/llvm-project/clang/include -I $(dirname external/llvm-project/llvm/include/llvm/IR/Intrinsics.td) -gen-intrinsic-enums -intrinsic-prefix=xcore external/llvm-project/llvm/include/llvm/IR/Intrinsics.td -o bazel-out/darwin-opt/bin/external/llvm-project/llvm/include/llvm/IR/IntrinsicsXCore.h
Target //build:build_wheel failed to build
INFO: Elapsed time: 620.950s, Critical Path: 45.35s
INFO: 589 processes: 132 internal, 457 local.
FAILED: Build did NOT complete successfully
ERROR: Build failed. Not running target
FAILED: Build did NOT complete successfully
b''
Traceback (most recent call last):
File "/mypath/jax/build/build.py", line 524, in <module>
main()
File "/mypath/jax/build/build.py", line 519, in main
shell(command)
File "/mypath/jax/build/build.py", line 53, in shell
output = subprocess.check_output(cmd)
File "/myuserpath/opt/anaconda3/envs/mytraxenv/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/myuserpath/opt/anaconda3/envs/mytraxenv/lib/python3.9/subprocess.py", line 528, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['./bazel-4.2.1-darwin-x86_64', 'run', '--verbose_failures=true', '--config=avx_posix', '--config=mkl_open_source_only', ':build_wheel', '--', '--output_path=/mypath/jax/dist', '--cpu=x86_64']' returned non-zero exit status 1.
Tried again a couple of times (deleted and redownloaded jax directory) and the same line 528 in .../lib/python3.9/subprocess.py seemed to cause the issue but the output, while mostly the above, sometimes was slightly different. Making me suspect an issue with memory, given that I (admittedly) had not restarted my machine in weeks and it was starting to unresponsively slow.
I updated my XCode command line tools to version 12.2 (pretty sure).
I restarted my (8GB) machine. Deleted and redownloaded jax directory. I installed bazel version 5.0.0 with homebrew in case that would help. I was a bit concerned that it kept downloading an x86 version for my ARM processor. bazel installation went fine.
Started again from these instructions. The jaxlib build, though, made it clear that it wanted an earlier (4.2.1) version of bazel and downloaded it, as before:
b'\x1b[31mERROR: The project you\'re trying to build requires Bazel 4.2.1 (specified in /mypath/jax/.bazelversion), but it wasn\'t found in /opt/homebrew/Cellar/bazel/5.0.0/libexec/bin.\x1b[0m\n\nBazel binaries for all official releases can be downloaded from here:\n https://github.com/bazelbuild/bazel/releases\n\nYou can download the required version directly using this command:\n (cd "/opt/homebrew/Cellar/bazel/5.0.0/libexec/bin" && curl -fLO https://releases.bazel.build/4.2.1/release/bazel-4.2.1-darwin-x86_64 && chmod +x bazel-4.2.1-darwin-x86_64)\n'
Once again, a different error in the same line 528. Showing full run now:
b'\x1b[31mERROR: The project you\'re trying to build requires Bazel 4.2.1 (specified in /mypath/jax/.bazelversion), but it wasn\'t found in /opt/homebrew/Cellar/bazel/5.0.0/libexec/bin.\x1b[0m\n\nBazel binaries for all official releases can be downloaded from here:\n https://github.com/bazelbuild/bazel/releases\n\nYou can download the required version directly using this command:\n (cd "/opt/homebrew/Cellar/bazel/5.0.0/libexec/bin" && curl -fLO https://releases.bazel.build/4.2.1/release/bazel-4.2.1-darwin-x86_64 && chmod +x bazel-4.2.1-darwin-x86_64)\n'
Downloading bazel from: https://github.com/bazelbuild/bazel/releases/download/4.2.1/bazel-4.2.1-darwin-x86_64
bazel-4.2.1-darwin-x86_64 [########################################] 100%
Bazel binary path: ./bazel-4.2.1-darwin-x86_64
Bazel version: 4.2.1
Python binary path: /myuserpath/opt/anaconda3/envs/mytraxenv/bin/python
Python version: 3.9
NumPy version: 1.21.2
MKL-DNN enabled: yes
Target CPU: x86_64
Target CPU features: release
CUDA enabled: no
TPU enabled: no
ROCm enabled: no
Building XLA and installing it in the jaxlib source tree...
./bazel-4.2.1-darwin-x86_64 run --verbose_failures=true --config=avx_posix --config=mkl_open_source_only :build_wheel -- --output_path=/mypath/jax/dist --cpu=x86_64
INFO: Options provided by the client:
Inherited 'common' options: --isatty=0 --terminal_columns=80
INFO: Reading rc options for 'run' from /mypath/jax/.bazelrc:
Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'run' from /mypath/jax/.bazelrc:
Inherited 'build' options: --apple_platform_type=macos --macos_minimum_os=10.9 --announce_rc --define open_source_build=true --spawn_strategy=standalone --enable_platform_specific_config --define=no_aws_support=true --define=no_gcp_support=true --define=no_hdfs_support=true --define=no_kafka_support=true --define=no_ignite_support=true --define=grpc_no_ares=true -c opt --config=short_logs --copt=-DMLIR_PYTHON_PACKAGE_PREFIX=jaxlib.mlir.
INFO: Reading rc options for 'run' from /mypath/jax/.jax_configure.bazelrc:
Inherited 'build' options: --strategy=Genrule=standalone --repo_env PYTHON_BIN_PATH=/myuserpath/opt/anaconda3/envs/mytraxenv/bin/python --action_env=PYENV_ROOT --python_path=/myuserpath/opt/anaconda3/envs/mytraxenv/bin/python --distinct_host_configuration=false
INFO: Found applicable config definition build:short_logs in file /mypath/jax/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:avx_posix in file /mypath/jax/.bazelrc: --copt=-mavx --host_copt=-mavx
INFO: Found applicable config definition build:mkl_open_source_only in file /mypath/jax/.bazelrc: --define=tensorflow_mkldnn_contraction_kernel=1
INFO: Found applicable config definition build:macos in file /mypath/jax/.bazelrc: --config=posix
INFO: Found applicable config definition build:posix in file /mypath/jax/.bazelrc: --copt=-fvisibility=hidden --copt=-Wno-sign-compare --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
Loading:
Loading: 0 packages loaded
Analyzing: target //build:build_wheel (1 packages loaded, 0 targets configured)
Analyzing: target //build:build_wheel (8 packages loaded, 286 targets configured)
Analyzing: target //build:build_wheel (10 packages loaded, 4271 targets configured)
Analyzing: target //build:build_wheel (10 packages loaded, 4271 targets configured)
Analyzing: target //build:build_wheel (11 packages loaded, 4494 targets configured)
INFO: Analyzed target //build:build_wheel (11 packages loaded, 7417 targets configured).
INFO: Found 1 target...
[0 / 3] [Prepa] BazelWorkspaceStatusAction stable-status.txt
[21 / 233] Compiling src/google/protobuf/generated_enum_util.cc; 2s local ... (6 actions, 3 running)
[28 / 233] Compiling src/google/protobuf/extension_set.cc; 4s local ... (8 actions, 7 running)
[114 / 523] Compiling src/google/protobuf/generated_message_util.cc; 2s local ... (8 actions running)
[140 / 594] Compiling platform/c++11/src/nsync_semaphore_mutex.cc; 0s local ... (8 actions, 7 running)
[237 / 597] Compiling src/google/protobuf/util/message_differencer.cc; 0s local ... (8 actions running)
[252 / 597] Compiling src/google/protobuf/util/message_differencer.cc; 4s local ... (8 actions running)
[272 / 597] Compiling src/google/protobuf/descriptor.pb.cc; 8s local ... (8 actions running)
[296 / 597] Compiling src/google/protobuf/descriptor.cc; 12s local ... (8 actions running)
[315 / 597] Compiling src/google/protobuf/descriptor_database.cc; 2s local ... (5 actions running)
[487 / 1,963] Compiling src/compiler/python_generator.cc; 2s local ... (8 actions running)
[579 / 3,117] Compiling tensorflow/compiler/xla/service/cpu/runtime_single_threaded_conv3d.cc; 0s local ... (8 actions, 7 running)
[619 / 3,173] Compiling tensorflow/compiler/xla/service/cpu/runtime_single_threaded_conv3d.cc; 8s local ... (8 actions running)
[687 / 3,270] Compiling tensorflow/compiler/xla/service/cpu/runtime_single_threaded_conv3d.cc; 17s local ... (8 actions running)
[774 / 3,464] Compiling tensorflow/compiler/xla/service/cpu/runtime_single_threaded_conv2d.cc; 27s local ... (8 actions running)
[1,204 / 4,860] Compiling tensorflow/compiler/xla/service/cpu/runtime_single_threaded_conv2d.cc; 39s local ... (8 actions running)
[1,255 / 4,916] Compiling tensorflow/compiler/xla/service/cpu/runtime_matmul.cc; 52s local ... (8 actions running)
[1,340 / 5,042] Compiling tensorflow/compiler/xla/service/cpu/runtime_matmul.cc; 68s local ... (8 actions running)
[1,456 / 5,156] Compiling tensorflow/compiler/xla/service/cpu/runtime_matmul.cc; 86s local ... (8 actions, 7 running)
[1,661 / 5,704] Compiling tensorflow/compiler/xla/service/cpu/runtime_matmul.cc; 107s local ... (8 actions, 7 running)
[1,688 / 5,704] Compiling tensorflow/compiler/xla/service/cpu/runtime_matmul.cc; 132s local ... (8 actions, 7 running)
[1,721 / 5,704] Compiling tensorflow/compiler/xla/service/cpu/runtime_matmul.cc; 160s local ... (8 actions, 7 running)
[2,106 / 6,584] Compiling tensorflow/compiler/xla/service/cpu/runtime_matmul.cc; 192s local ... (8 actions, 7 running)
[2,342 / 7,067] Compiling tensorflow/compiler/xla/service/cpu/runtime_matmul.cc; 231s local ... (8 actions, 7 running)
[2,378 / 7,067] Compiling tensorflow/compiler/xla/service/cpu/runtime_matmul.cc; 274s local ... (8 actions, 7 running)
[2,422 / 7,067] Compiling src/cpu/rnn/ref_rnn.cpp; 75s local ... (8 actions, 7 running)
[2,452 / 7,067] Compiling src/cpu/x64/gemm/f32/jit_avx512_core_f32_copy_at_kern_part1_autogen.cpp; 54s local ... (8 actions, 7 running)
[2,500 / 7,067] Compiling src/cpu/x64/gemm/f32/jit_avx512_core_f32_copy_at_kern_part1_autogen.cpp; 119s local ... (8 actions, 7 running)
[2,577 / 7,067] Compiling src/common/memory_zero_pad.cpp; 74s local ... (8 actions, 7 running)
ERROR: /private/var/tmp/_bazel_a/f5e9a3325f07a1f02c52d821857db47c/external/org_tensorflow/tensorflow/compiler/xla/BUILD:69:17: ProtoCompile external/org_tensorflow/tensorflow/compiler/xla/xla.pb.h failed: (Illegal instruction): protoc failed: error executing command
(cd /private/var/tmp/_bazel_a/f5e9a3325f07a1f02c52d821857db47c/execroot/__main__ && \
exec env - \
PATH=/myuserpath/opt/anaconda3/envs/mytraxenv/bin:/myuserpath/opt/anaconda3/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin \
bazel-out/darwin-opt/bin/external/com_google_protobuf/protoc '--cpp_out=bazel-out/darwin-opt/bin/external/org_tensorflow' -Iexternal/org_tensorflow -Ibazel-out/darwin-opt/bin/external/org_tensorflow -Ibazel-out/darwin-opt/bin/external/com_google_protobuf/_virtual_imports/any_proto -Ibazel-out/darwin-opt/bin/external/com_google_protobuf/_virtual_imports/source_context_proto -Ibazel-out/darwin-opt/bin/external/com_google_protobuf/_virtual_imports/type_proto -Ibazel-out/darwin-opt/bin/external/com_google_protobuf/_virtual_imports/api_proto -Ibazel-out/darwin-opt/bin/external/com_google_protobuf/_virtual_imports/descriptor_proto -Ibazel-out/darwin-opt/bin/external/com_google_protobuf/_virtual_imports/compiler_plugin_proto -Ibazel-out/darwin-opt/bin/external/com_google_protobuf/_virtual_imports/duration_proto -Ibazel-out/darwin-opt/bin/external/com_google_protobuf/_virtual_imports/empty_proto -Ibazel-out/darwin-opt/bin/external/com_google_protobuf/_virtual_imports/field_mask_proto -Ibazel-out/darwin-opt/bin/external/com_google_protobuf/_virtual_imports/struct_proto -Ibazel-out/darwin-opt/bin/external/com_google_protobuf/_virtual_imports/timestamp_proto -Ibazel-out/darwin-opt/bin/external/com_google_protobuf/_virtual_imports/wrappers_proto external/org_tensorflow/tensorflow/compiler/xla/xla.proto)
Execution platform: #local_execution_config_platform//:platform
Target //build:build_wheel failed to build
INFO: Elapsed time: 631.189s, Critical Path: 283.35s
INFO: 2563 processes: 935 internal, 1628 local.
FAILED: Build did NOT complete successfully
ERROR: Build failed. Not running target
FAILED: Build did NOT complete successfully
b''
Traceback (most recent call last):
File "/mypath/jax/build/build.py", line 524, in <module>
main()
File "/mypath/jax/build/build.py", line 519, in main
shell(command)
File "/mypath/jax/build/build.py", line 53, in shell
output = subprocess.check_output(cmd)
File "/myuserpath/opt/anaconda3/envs/mytraxenv/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/myuserpath/opt/anaconda3/envs/mytraxenv/lib/python3.9/subprocess.py", line 528, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['./bazel-4.2.1-darwin-x86_64', 'run', '--verbose_failures=true', '--config=avx_posix', '--config=mkl_open_source_only', ':build_wheel', '--', '--output_path=/mypath/jax/dist', '--cpu=x86_64']' returned non-zero exit status 1.
I switched away from trying to build jaxlib. In late October 2021, a M1-compatible jaxlib wheel was released, so I tried:
pip install -U pip
pip install -U https://storage.googleapis.com/jax-releases/mac/jaxlib-0.1.74-cp39-none-macosx_11_0_arm64.whl
but got
ERROR: jaxlib-0.1.74-cp39-none-macosx_11_0_arm64.whl is not a supported wheel on this platform.
Tried upgrading python from 3.9 to 3.10, but got the same message.
Debugged by, in python, running
import platform
print(platform.machine())
which showed that my python is still running on x86 architechture, since "Anaconda doesn't yet provide packages for M1/ARM".
[see successful (so far) jaxlib installation in own answer below]
back to trax
After successfully installing jaxlib and jax, when trying to install trax with (miniforge’s)conda install trax I get:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- trax
Current channels:
- https://conda.anaconda.org/conda-forge/osx-arm64
- https://conda.anaconda.org/conda-forge/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
I tried installing as trax itself suggests but ran into an error building hp5y:
ERROR: Failed building wheel for h5py
ERROR: Could not build wheels for h5py, which is required to install pyproject.toml-based projects
Looking now into this error and also looking into doing it with miniforge again but using Anaconda's channel to install trax. I'll update when I get to it.
Any pointers or anyone who managed to install trax on an M1 Mac it by any different means?

jaxlib + jax
After someone claimed success using miniforge, I read this and watched this to clarify using Anaconda and miniforge together.
I installed miniforge with Apple's arm64 : Apple Silicon method. For some reason when I ran miniforge's conda init it set up the initialization code in ~/.bash_profile even though I'm using the zsh shell. I tried putting the code manually instead in ~/.zprofile but it wouldn't load on interactive shells, so I just ended up putting it where Anaconda had put its initialization code, in ~/zshrc.
This made miniforge the default manager. Following the very useful video above, I created a ~/.start_anaconda.sh script so I can use Anaconda as an alternative.
With miniforge I
created a new conda environment mytraxenv with conda create -n mytraxenv python=3 which has python 3.10.2 at the moment
activated the environment: conda activate mytraxenv
ran conda install numpy and conda install six to ensure numpy. six and wheel (installed by one of the previous two) were installed in my mytraxenv environment
tried again, with a slightly updated release (from here):
pip install -U pip
pip install -U https://storage.googleapis.com/jax-releases/mac/jaxlib-0.1.75-cp310-none-macosx_11_0_arm64.whl
This worked in installing jaxlib!
Then, I followed these instructions to install jax:
pip install --upgrade pip
pip install --upgrade "jax[cpu]"
That worked as well. Note that when running import jax in python it currently warns:
/mytraxenv/lib/python3.10/site-packages/jax/_src/lib/__init__.py:32: UserWarning: JAX on Mac ARM machines is experimental and minimally tested. Please see https://github.com/google/jax/issues/5501 in the event of problems.
warnings.warn("JAX on Mac ARM machines is experimental and minimally tested. "
trax
No success yet installing trax.

Anaconda Source build
As of Mon, 7th of Feb 2022, installing using an Anaconda installation of python fails as Anaconda does not provide arm wheels for python.
When they do provide them, building from source should work automatically. If it does not, clone the repository, and use the following:
python build/build.py --target_cpu darwin_arm64
If bazel does not build and you are using homebrew consider installing it, and removing the downloaded bazel files.
brew install bazel
rm -rf bazel-*
Arm64 Python wheels
I recommend downloading arm64 wheels from the official CPython website.
The executable will be in /usr/local/bin/python3, and so will pip3.
This should allow you to install jax using
/usr/local/bin/pip3 install --upgrade 'jax[cpu]'
To have access to the proper python with the command line/path, add the folder to the path.
export PATH=/usr/share/bin:$PATH
Virtual Env
I recommend against the above method, and instead to use to use virtual-env from here https://virtualenv.pypa.io, to create virtual environments as with anaconda, and install jax in a virtual environment as above.
Poetry
Poetry is an even better option since it uses virtual-env, and allows you to build your projects and list dependencies just as anaconda.
There is a minor caveat as I am writing this, installing scipy when defining dependencies with poetry results in an odd error, installing numpy and scipy manually using
poetry shell # to go to virtual environment for the project
pip install --upgrade 'jax[cpu]' jaxlib scipy numpy
Trax
Since anaconda is not option, installing hdf5 is a bit of a hassle, but it can be done with brew/homebrew. Assuming you have activated the correct venv:
brew install hdf5
export HDF5_DIR=/opt/homebrew/Cellar/hdf5/1.12.1
pip install trax
Unfortunately this results in the following error:
import trax
/Users/quinn/Library/Caches/pypoetry/virtualenvs/no-xNvLksOy-py3.9/lib/python3.9/site-packages/jax/_src/lib/__init__.py:32: UserWarning: JAX on Mac ARM machines is experimental and minimally tested. Please see https://github.com/google/jax/issues/5501 in the event of problems.
warnings.warn("JAX on Mac ARM machines is experimental and minimally tested. "
***************************************************************
Failed to import TensorFlow. Please note that TensorFlow is not installed by default when you install TFDS. This allow you to choose to install either `tf-nightly` or `tensorflow`. Please install the most recent version of TensorFlow, by following instructions at https://tensorflow.org/install.
***************************************************************
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/quinn/Library/Caches/pypoetry/virtualenvs/no-xNvLksOy-py3.9/lib/python3.9/site-packages/trax/__init__.py", line 18, in <module>
from trax import layers
File "/Users/quinn/Library/Caches/pypoetry/virtualenvs/no-xNvLksOy-py3.9/lib/python3.9/site-packages/trax/layers/__init__.py", line 23, in <module>
from trax.layers.activation_fns import *
File "/Users/quinn/Library/Caches/pypoetry/virtualenvs/no-xNvLksOy-py3.9/lib/python3.9/site-packages/trax/layers/activation_fns.py", line 26, in <module>
from trax import math
File "/Users/quinn/Library/Caches/pypoetry/virtualenvs/no-xNvLksOy-py3.9/lib/python3.9/site-packages/trax/math/__init__.py", line 18, in <module>
from trax.math import jax as jax_math
File "/Users/quinn/Library/Caches/pypoetry/virtualenvs/no-xNvLksOy-py3.9/lib/python3.9/site-packages/trax/math/jax.py", line 28, in <module>
import tensorflow_datasets as tfds
File "/Users/quinn/Library/Caches/pypoetry/virtualenvs/no-xNvLksOy-py3.9/lib/python3.9/site-packages/tensorflow_datasets/__init__.py", line 43, in <module>
from tensorflow_datasets.core import tf_compat
File "/Users/quinn/Library/Caches/pypoetry/virtualenvs/no-xNvLksOy-py3.9/lib/python3.9/site-packages/tensorflow_datasets/core/__init__.py", line 22, in <module>
tf_compat.ensure_tf_install()
File "/Users/quinn/Library/Caches/pypoetry/virtualenvs/no-xNvLksOy-py3.9/lib/python3.9/site-packages/tensorflow_datasets/core/tf_compat.py", line 48, in ensure_tf_install
import tensorflow as tf # pylint: disable=import-outside-toplevel
ModuleNotFoundError: No module named 'tensorflow'

Related

Poetry/Meson: How to use meson as a build backend with Cython files to install a Python/Cython package

I have a Python package that contains Cython code, similar to scikit-learn. I am trying to use poetry to do package management, but meson to handle the build process for Cython and possible c++ code. Before, when I was using the deprecated setuptools and distutils, I was able to do the following in scikit-learn:
pip install -e .
which built the Cython files and allowed them to be importable by sklearn's Python files. For example from _criterion import Criterion works, where _criterion.pxd/pyx is a Cython file that contains some variable named Criterion.
Now I am using poetry and meson and things do not work.
My Goals to Use Poetry and Meson
I would ideally like to be able to just do poetry install (or poetry build and poetry install), which should build and install things by using Meson to build local Cython/C++ files and then use poetry to handle other pip installable Python packages.
My Question
How do I correctly use poetry with meson to build my Cython files and install them along with other relevant Python dependencies to install my package?
My Attempt using just Meson incorrectly Cython files to the wrong environment
I instantiated my meson.build files such that running meson build in my repo's root directory works:
The Meson build system
Version: 0.63.2
Source dir: /Users/adam2392/Documents/scikit-tree
Build dir: /Users/adam2392/Documents/scikit-tree/build
Build type: native build
Project name: scikit-tree
Project version: 0.0.0.dev0
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
Host machine cpu family: aarch64
Host machine cpu: arm64
Library m found: YES
Program cython found: YES (/Users/adam2392/miniforge3/envs/sktree/bin/cython)
Program python3 found: YES (/Users/adam2392/miniforge3/envs/sktree/bin/python3)
Message: /Users/adam2392/miniforge3/envs/sktree/bin/python3
Message: /opt/homebrew/lib/python3.9/site-packages/
Found pkg-config: /opt/homebrew/bin/pkg-config (0.29.2)
Program _build_utils/cythoner.py found: YES (python /Users/adam2392/Documents/scikit-tree/sktree/_build_utils/cythoner.py)
Build targets in project: 1
scikit-tree 0.0.0.dev0
User defined options
backend: ninja
Found ninja-1.11.1 at /opt/homebrew/bin/ninja
When I then run meson install within the build/ directory:
(sktree) adam2392#Adams-MacBook-Pro build % meson install
ninja: Entering directory `/Users/adam2392/Documents/scikit-tree/build'
[3/3] Linking target sktree/tree/_unsup_criterion.cpython-39-darwin.so
ld: warning: -pie being ignored. It is only used when linking a main executable
Installing sktree/tree/_unsup_criterion.cpython-39-darwin.so to /opt/homebrew/lib/python3.9/site-packages/sktree/tree
Installing /Users/adam2392/Documents/scikit-tree/sktree/__init__.py to /opt/homebrew/lib/python3.9/site-packages/sktree
Installing /Users/adam2392/Documents/scikit-tree/sktree/_forest.py to /opt/homebrew/lib/python3.9/site-packages/sktree
Installing /Users/adam2392/Documents/scikit-tree/sktree/tree/__init__.py to /opt/homebrew/lib/python3.9/site-packages/sktree/tree
Installing /Users/adam2392/Documents/scikit-tree/sktree/tree/_classes.py to /opt/homebrew/lib/python3.9/site-packages/sktree/tree
which installs for example the Cython files into the incorrect Python environment (i.e. home-brew). I need it to be installed in my virtual environment.
My Attempt using Poetry doesn't work either
My pyproject.toml file has the following lines:
[build-system]
build-backend = "mesonpy"
requires = [
"meson-python>=0.11.0",
# `wheel` is needed for non-isolated builds, given that `meson-python`
# doesn't list it as a runtime requirement (at least in 0.10.0)
# See https://github.com/FFY00/meson-python/blob/main/pyproject.toml#L4
"wheel",
"setuptools<=65.5",
"packaging",
"Cython>=0.29.24",
"scikit-learn",
]
However, when I run poetry install, there are no errors, but:
python -c "from sktree import tree"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/adam2392/Documents/scikit-tree/sktree/__init__.py", line 37, in <module>
from . import tree
File "/Users/adam2392/Documents/scikit-tree/sktree/tree/__init__.py", line 1, in <module>
from ._classes import UnsupervisedDecisionTree
File "/Users/adam2392/Documents/scikit-tree/sktree/tree/_classes.py", line 3, in <module>
from ._unsup_criterion import UnsupervisedCriterion
ModuleNotFoundError: No module named 'sktree.tree._unsup_criterion'

How to fix errors occurring on installation of Jupyter Notebook

I am new to Python and try to install Jupyter Notebook from within a Windows command prompt window using:
pip install jupyter
But after a couple of minutes of downloading, an error message is displayed as shown below:
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... error
ERROR: Command errored out with exit status 1:
command: 'c:\users\asd\appdata\local\programs\python\python38-32\python.exe
' 'c:\users\asd\appdata\local\programs\python\python38-32\lib\site-packages\pip\
_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\asd\Ap
pData\Local\Temp\tmpnj_hhq6y'
cwd: C:\Users\asd\AppData\Local\Temp\pip-install-_pnki5r8\pywinpty
Complete output (6 lines):
Cargo, the Rust package manager, is not installed or is not on PATH.
This package requires Rust and Cargo to compile extensions. Install it through
the system's package manager or via https://rustup.rs/
Checking for Rust toolchain....
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\asd\appdata\local\progr
ams\python\python38-32\python.exe' 'c:\users\asd\appdata\local\programs\python\p
ython38-32\lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata
_for_build_wheel 'C:\Users\asd\AppData\Local\Temp\tmpnj_hhq6y' Check the logs for
full command output.
WARNING: You are using pip version 20.2.1; however, version 21.1 is available.
You should consider upgrading via the 'c:\users\asd\appdata\local\programs\pytho
n\python38-32\python.exe -m pip install --upgrade pip' command.
I have attached here just the last part of the error output.
How to fix this error for a successful installation of Jupyter Notebook?
EDIT1: I installed the Rust package from the link in the error message. After that I tried installing Jupyter Notebook once again, and this time after proceeding a few steps further than before, it output another error:
Building wheels for collected packages: pywinpty
Building wheel for pywinpty (PEP 517) ... - WARNING: Subprocess output does
not appear to be encoded as cp1252
WARNING: Subprocess output does not appear to be encoded as cp1252
error
ERROR: Command errored out with exit status 1:
command: 'c:\users\asd\appdata\local\programs\python\python38-32\python.exe'
'c:\users\asd\appdata\local\programs\python\python38-32\lib\site-packages\pip\_v
endor\pep517\_in_process.py' build_wheel 'C:\Users\asd\AppData\Local\Temp\tmpaj5
u66_y'
cwd: C:\Users\asd\AppData\Local\Temp\pip-install-mep4ye8d\pywinpty
Complete output (60 lines):
Running `maturin pep517 build-wheel -i c:\users\asd\appdata\local\programs\pyt
hon\python38-32\python.exe`
Compiling proc-macro2 v1.0.26
Compiling unicode-xid v0.2.2
Compiling syn v1.0.71
Compiling winapi v0.3.9
Compiling jobserver v0.1.22
error: could not compile `proc-macro2`
To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
dY'¥ maturin failed
Caused by: Failed to build a native library through cargo
Caused by: Cargo build finished with "exit code: 101": `cargo rustc --messag
e-format json --manifest-path Cargo.toml --release --lib --`
dY\x8d1 Building a mixed python/rust project
dY"- Found pyo3 bindings
dY\x90\x8d Found CPython 3.8 at c:\users\asd\appdata\local\programs\python\pyt
hon38-32\python.exe
error: linker `link.exe` not found
|
= note: The system cannot find the file specified. (os error 2)
note: the msvc targets depend on the msvc linker but `link.exe` was not found
note: please ensure that VS 2013, VS 2015, VS 2017 or VS 2019 was installed wi
th the Visual C++ option
error: aborting due to previous error
error: linker `link.exe` not found
|
= note: The system cannot find the file specified. (os error 2)
note: the msvc targets depend on the msvc linker but `link.exe` was not found
note: please ensure that VS 2013, VS 2015, VS 2017 or VS 2019 was installed wi
th the Visual C++ option
error: aborting due to previous error
error: linker `link.exe` not found
|
= note: The system cannot find the file specified. (os error 2)
note: the msvc targets depend on the msvc linker but `link.exe` was not found
note: please ensure that VS 2013, VS 2015, VS 2017 or VS 2019 was installed wi
th the Visual C++ option
error: aborting due to previous error
Error: command ['maturin', 'pep517', 'build-wheel', '-i', 'c:\\users\\asd\\app
data\\local\\programs\\python\\python38-32\\python.exe'] returned non-zero exit
status 1
----------------------------------------
ERROR: Failed building wheel for pywinpty
Failed to build pywinpty
ERROR: Could not build wheels for pywinpty which use PEP 517 and cannot be insta
lled directly
WARNING: You are using pip version 20.2.1; however, version 21.1 is available.
You should consider upgrading via the 'c:\users\asd\appdata\local\programs\pytho
n\python38-32\python.exe -m pip install --upgrade pip' command.
Upgrade your pip first:
pip install --upgrade pip
Then:
pip install jupyter
I'reached this post after failing to install notebook on a 32-bit python 3.8.3 execution. And as far as I found, pywinpty, which is a dependence, does not support 32-bit executions (see sources below).
I solved the problem by installing python on its 64-bit version.
Sources:
How do I determine if my python shell is executing in 32bit or 64bit?
pip install fails on Python 3.8 32-bit, prevents Jupyter install #129 which simply says that wheels cannot be installed with 32 bit Python and that you should use 64 bit Python instead.
We can't generate 32 bit wheels, sorry. Please use a 64bit build of Python.. Was not my case but might be useful this similar issue when using python 3.8 64-bit
Error installing Jupyter & pywinpty (Python)
https://github.com/spyder-ide/pywinpty/issues/123
Do
pip install wheel
and try again. It worked for me.
What to do:
Check if your python is 64-bit version. If no, go to python site (for example, here is the link to download 3.7.9. Just click at the version that has label "for AMD64/EM64T/x64", do it with any version you wish, just I don't like to use the newest version). Remove yours (with the uninstall file) and download this. Don't forget to put the checkmark near "Add PATH" below;
Download Rust (the description is inside) - you need some files. Check the PATHs - if you want to change them, do it (the names of the variables and where they are - both are written, you can search in the Internet how to change PATH var's (for example));
Go to Windows Shell with admin mode (Win+X and you get the field) - here is the most comfortable place to work;
Go to your python.exe (for example, my way is C:\Users\user\AppData\Local\Programs\Python\Python37) - just for sure;
python.exe python -m pip install --upgrade pip;
python.exe pip install jupyter;
If an error was returned that contains the missing of wheel, try to download it: python.exe pip install wheel.
Donwload any library you miss during installation and continue since the step you stopped at.
Try using Anaconda. link to install conda https://www.anaconda.com/products/individual
then cmd : conda install numpy
cmd: conda install jupyter
cmd : jupyter notebook
The error message looks quite clear, you needs to install Cargo via https://rustup.rs/
I have faced the same issue when I'm using vscode. The simplest solution is to use conda instead of pip
conda install jupyterlab

Error while configuring Snappy. failed with return code 10

in order to configure snappy I runned the next comand
~/snap/bin$ ./snappy-conf /usr/bin/python3.8
As a result I got the following error message:
Configuring SNAP-Python interface...
java.io.IOException: Python configuration failed.
Command [/usr/bin/python3.8 ./snappyutil.py --snap_home /home/sergio/snap --java_module /home/sergio/snap/snap/modules/org-esa-snap-snap-python.jar --force --log_file ./snappyutil.log --jvm_max_mem 10G --java_home /home/sergio/snap/jre/jre --req_arch amd64]
failed with return code 10.
Please check the log file '/home/sergio/.snap/snap-python/snappy/snappyutil.log'.
at org.esa.snap.python.PyBridge.configureJpy(PyBridge.java:232)
at org.esa.snap.python.PyBridge.installPythonModule(PyBridge.java:149)
at org.esa.snap.rcp.cli.SnapArgsProcessor.processPython(SnapArgsProcessor.java:103)
at org.esa.snap.rcp.cli.SnapArgsProcessor.process(SnapArgsProcessor.java:49)
at org.netbeans.modules.sendopts.DefaultProcessor.process(DefaultProcessor.java:202)
at org.netbeans.spi.sendopts.Option$1.process(Option.java:387)
at org.netbeans.api.sendopts.CommandLine.process(CommandLine.java:317)
at org.netbeans.modules.sendopts.HandlerImpl.execute(HandlerImpl.java:62)
at org.netbeans.modules.sendopts.Handler.cli(Handler.java:69)
at org.netbeans.CLIHandler.notifyHandlers(CLIHandler.java:234)
at org.netbeans.core.startup.CLICoreBridge.cli(CLICoreBridge.java:82)
at org.netbeans.CLIHandler.notifyHandlers(CLIHandler.java:234)
at org.netbeans.CLIHandler$1.exec(CLIHandler.java:268)
at org.netbeans.CLIHandler.finishInitialization(CLIHandler.java:447)
at org.netbeans.MainImpl.finishInitialization(MainImpl.java:256)
at org.netbeans.Main.finishInitialization(Main.java:92)
at org.netbeans.core.startup.Main.start(Main.java:316)
at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:123)
at java.lang.Thread.run(Thread.java:748)
Python configuration error: Python configuration failed.
Command [/usr/bin/python3.8 ./snappyutil.py --snap_home /home/sergio/snap --java_module /home/sergio/snap/snap/modules/org-esa-snap-snap-python.jar --force --log_file ./snappyutil.log --jvm_max_mem 10G --java_home /home/sergio/snap/jre/jre --req_arch amd64]
failed with return code 10.
Please check the log file '/home/sergio/.snap/snap-python/snappy/snappyutil.log'.
The '/home/sergio/.snap/snap-python/snappy/snappyutil.log' file shows the following info:
INFO: Installing from Java module '/home/sergio/snap/snap/modules/org-esa-snap-snap-python.jar'
WARNING: Architecture requirement possibly not met: Python is x86_64 but JVM requires amd64
INFO: Installing jpy...
ERROR: The module 'jpy' is required to run snappy, but no binary 'jpy' wheel matching the pattern
'jpy-{version}-cp38-{abi_tag}-linux_x86_64.whl' could be found.
You can try to build a 'jpy' wheel yourself, then copy it into
"/home/sergio/.snap/snap-python/snappy", and then run the configuration again.
Unzip the jpy sources in /home/sergio/.snap/snap-python/snappy/jpy-<version>.zip, then
$ cd jpy-<version>
$ python setup.py bdist_wheel
$ cp dist/*.whl "/home/sergio/.snap/snap-python/snappy"
Or get the source code from https://github.com/bcdev/jpy and follow the build instructions:
$ git clone https://github.com/bcdev/jpy.git
$ cd jpy
ERROR: Configuration failed with exit code 10
I downloaded the "jpy" in the "~/.snap/snap-python/snappy" dir but I still have the same error. After looking info about the warning about the Architecture requirements i found that it shouldn't be a problem.
I'm using Ubuntu 20.04. Does anyone know what could be wrong?
Thank you so much for your time guys
I solved it, There was a problem with the python version and snappy. I had to create a conda environment with the 3.6 python version and then use that version on my notebook.

'/bin/convert_to_uff.py': No such file or directory

I am trying to optimize YoloV3 using tensorRT
I came this post called Have you Optimized your Deep Learning Model Before Deployment?
Docker is used in the post.
Used Enabling GPUs in the Container Runtime Ecosystem to install nvidia-docker2
Pulled the latest version of the docker image docker pull aminehy/tensorrt-opencv-python3:version-1.3 from aminehy/tensorrt-opencv-python3
Here are the images
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nvcr.io/nvidia/cuda 10.1-cudnn7-devel-ubuntu18.04 b4879c167fc1 2 weeks ago 3.67GB
aminehy/tensorrt-opencv-python3 version-1.3 0302e477816d 4 months ago 5.36GB
aminehy/tensorrt-opencv-python3 latest 604502819d12 4 months ago 4.94GB
aminehy/tensorrt-opencv-python3 version-1.1 d693210c500c 4 months ago 4.94GB
I ran
$sudo docker run -it --rm -v $(pwd):/workspace --runtime=nvidia -w /workspace -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY aminehy/tensorrt-opencv-python3:version-1.3```
=====================
== NVIDIA TensorRT ==
=====================
NVIDIA Release 19.05 (build 6392482)
NVIDIA TensorRT 5.1.5 (c) 2016-2019, NVIDIA CORPORATION. All rights reserved.
Container image (c) 2019, NVIDIA CORPORATION. All rights reserved.
https://developer.nvidia.com/tensorrt
To install Python sample dependencies, run /opt/tensorrt/python/python_setup.sh
root#a38b20eeb740:/workspace# cd /opt/tensorrt/python/
root#a38b20eeb740:/opt/tensorrt/python# chmod +x python_setup.sh
root#a38b20eeb740:/opt/tensorrt/python# ./python_setup.sh
Requirement already satisfied: Pillow in /usr/local/lib/python3.5/dist-packages (from -r /opt/tensorrt/samples/sampleSSD/requirements.txt (line 1)) (6.0.0)
WARNING: You are using pip version 19.2.1, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Ignoring torch: markers 'python_version == "3.7"' don't match your environment
......
......
......
Setting up graphsurgeon-tf (5.1.5-1+cuda10.1) ...
Setting up uff-converter-tf (5.1.5-1+cuda10.1) ...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/uff/__init__.py", line 1, in <module>
from uff import converters, model # noqa
File "/usr/lib/python2.7/dist-packages/uff/model/__init__.py", line 1, in <module>
from . import uff_pb2 as uff_pb # noqa
File "/usr/lib/python2.7/dist-packages/uff/model/uff_pb2.py", line 6, in <module>
from google.protobuf.internal import enum_type_wrapper
ImportError: No module named google.protobuf.internal
chmod: cannot access '/bin/convert_to_uff.py': No such file or directory
Can't seem to find any file called convert_to_uff.py inside bin
Whats is going?
Where did I go wrong?
Try reinstalling protobuf to be sure:
pip install protobuf

XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?

I am facing this problem while moving the python-package directory of XGBoost.
Traceback (most recent call last): File "setup.py", line 19, in LIB_PATH = libpath'find_lib_path' File "xgboost/libpath.py", line 46, in find_lib_path 'List of candidates:\n' + ('\n'.join(dll_path))) builtin.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
Could anyone explain to me how to fix it?
thanks in advance.
You get that message when trying to install the xgboost Python package without the xgboost binaries present. The proper way to install the xgboost Python package from source is the following (assuming you have a compiler such as gcc installed):
git clone --recursive https://github.com/dmlc/xgboost.git
cd xgboost
./build.sh
cd python-package
python setup.py install
I prefer to do it inside a virtual environment. Note that the option --recursive when cloning the repo is essential since it will also clone folders from different repos such as dmlc-core which are necessary for building xgboost.
The other answers didn't work for me so I installed xgboost through Conda commands as listed here.
Just run conda install -c conda-forge xgboost
The first answer's suggestions did not work for me, and left me with the same error as the original question.
If I'm assuming correctly that your full error message is something like this:
C:\Users\Matt\xgboost\python-package>python setup.py install
Traceback (most recent call last):
File "setup.py", line 19, in <module>
LIB_PATH = [os.path.relpath(libfile, CURRENT_DIR) for libfile in libpath['find_lib_path']()]
File "xgboost/libpath.py", line 49, in find_lib_path
'List of candidates:\n' + ('\n'.join(dll_path)))
XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
List of candidates:
C:\Users\Matt\xgboost\python-package\xgboost\xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\../../lib/xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\./lib/xgboost.dll
C:\Users\Matt\AppData\Local\Programs\Python\Python35\xgboost\xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\../../windows/x64/Release/xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\./windows/x64/Release/xgboost.dll
then the solution is to
1) Get/find/download the library that setup.py is looking for. Search the xgboost folder for .dll files. See if you can find something like xgboost.dll it might be called libxgboost.dll. If you can, move to step 2. If you cannot find it download it here
2) Copy the .dll file into the xgboost/python-package/xgboost folder. If that .dll is not called xgboost.dll (i.e. if it's called libxgboost.dll) then change the name to xgboost.dll
3) Run the commands as outlined in Gustavo answer. Note these are meant to be run from Git Bash.
If you want a more soup-to-nuts tutorial, this was the best one I found.
thanks to Joe Nyland that found the a good answer for this problem in here.
As he said (and also worked for me) you need to run following commands:
$ brew install gcc#5
$ pip install xgboost
Try this it worked for me:
brew install gcc-5
brew install cmake
pip install xgboost
In my case (Ubuntu 16.04, with CUDA 9.0) the Python library build was evidently broken by adding R library package to the cmake options list:
1) python lib installation works OK:
cmake .. -DUSE_CUDA=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-${CUDA_VER}
cd /tmp/xgboost/python-package && python3 setup.py install
2) adding '-DR_LIB=ON' switch to cmake breaks subsequent python library installation attempt:
cmake .. -DUSE_CUDA=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-${CUDA_VER} -DR_LIB=ON
cd /tmp/xgboost/python-package && python3 setup.py install
> "XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root
> path?"
I had the same issues. I downloaded the file (xgboost.dll) from
(https://picnet.com.au/blog/xgboost-windows-x64-binaries-for-download/)
into the already existing xgboost folder
(C:\Users\Naganandini\AppData\Roaming\Python\Python37\site-packages\xgboost).
It's perfectly working now :)
I faced the same error while installing xgboost using anaconda prompt because the installation of xgboost was interfering with the versions of some other pre-installed libraries. Installing xgboost by creating a virtual environment solved the issue.
On macOS and Linux:
python3 -m pip install --user virtualenv #Install virtualenv module
python3 -m venv env #Create a virtual environment 'env'
source env/bin/activate #Activate virtual environment
pip install xgboost #Install xgboost
On Windows:
py -m pip install --user virtualenv #Install virtualenv module
py -m venv env #Create a virtual environment 'env'
.\env\Scripts\activate #Activate virtual environment
pip install xgboost #Install xgboost
Refer https://packaging.python.org/guides/installing-using-pip-and-virtual-environments for help regarding virtual environment.
Search for xgboost.dll file under your C:\Users<your-user-name> directory.
If you have installed xgboost, somewhere you should find a copy of the xgboost.dll file.
Once you find the xgboost.dll file, just copy it to one of the paths mentioned in the error message,
e.g. C:\Users<your-user-name>\AppData\Roaming\Python\Python37\site-packages\xgboost\ . Import should work now.
1.I started off with the conda installation from anaconda prompt:
(base) C:\Users\abhi.b>conda install -c anaconda py-xgboost
This lead to the following error :
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: \
Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.|
failed
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- py-xgboost -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.5,<3.6.0a0']
Your python: python=3.8
If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
Decided not to followup this path, as exploring python downgrade was not an option for me.
2.There after i followed "The final attempt that works " on the below link :
https://medium.com/analytics-vidhya/this-is-what-you-should-do-if-you-fail-to-install-the-latest-or-an-older-version-of-xgboost-on-7942a7641eee
However i got the same error as other users faced ::
>>> import xgboost as xgb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\__init__.py", line 11, in <module>
from .core import DMatrix, Booster
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\core.py", line 161, in <module>
_LIB = _load_lib()
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\core.py", line 123, in _load_lib
lib_paths = find_lib_path()
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\libpath.py", line 45, in find_lib_path
raise XGBoostLibraryNotFound(
xgboost.libpath.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
List of candidates:
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\../../lib/xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\./lib/xgboost.dll
C:\Users\abhi.b\Anaconda3\xgboost\xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\../../windows/x64/Release/xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\./windows/x64/Release/xgboost.dll
>>> exit()
BTW the link to download xgboost.dll as posted above -
https://picnet.com.au/blog/xgboost-windows-x64-binaries-for-download/
was not clear to me ,so i decided to not follow this thread.
3.Finally ,the solution was very simple for me,Open ANACONDA PROMPT and Type
(base) C:\Users\abhi.b>pip install xgboost
This lead to
Collecting xgboost
Downloading xgboost-1.2.1-py3-none-win_amd64.whl (86.5 MB)
|████████████████████████████████| 86.5 MB 1.7 MB/s
Requirement already satisfied: scipy in c:\users\abhi.b\anaconda3\lib\site-packages (from xgboost) (1.5.0)
Requirement already satisfied: numpy in c:\users\abhi.b\anaconda3\lib\site-packages (from xgboost) (1.18.5)
Installing collected packages: xgboost
Successfully installed xgboost-1.2.1
Then goto python prompt
(base) C:\Users\abhi.b>python
>>>import xgboost as xgb
Or you can type the same command on IDE ie Spyder etc
Voila!!

Categories