-
Notifications
You must be signed in to change notification settings - Fork 7
Add Python and uv guide #115
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ To install this package, ensure that you are using one of the supported Python | |
| versions [](https://github.com/epochpic/sdf-xarray) | ||
| ``` | ||
|
|
||
| There are several ways in which you can install <project:#sdf_xarray>. If you are unfamiliar with Python, [follow this guide](#new-to-python). If you are already familiar with Python and `pip` then you can install this using the following. | ||
|
|
||
| Install sdf-xarray from PyPI with: | ||
|
|
||
| ```bash | ||
|
|
@@ -23,7 +25,7 @@ pip install . | |
|
|
||
| ## Interaction | ||
|
|
||
| There are two main ways to load EPOCH SDF files into xarray objects: using the dedicated | ||
| There are two main ways to load [EPOCH SDF files](https://epochpic.github.io/documentation/visualising_output.html) into xarray objects: using the dedicated | ||
| <project:#sdf_xarray> functions or using the standard <inv:#xarray> interface with our custom engine. | ||
| For examples of how to use these functions see [](./key_functionality.md#loading-sdf-files). | ||
|
|
||
|
|
@@ -59,3 +61,116 @@ If you prefer using the native <inv:#xarray> functions, you can use the <inv:#xa | |
| These functions should all work out of the box as long as <project:#sdf_xarray> is installed on your | ||
| system, if you are having issues with it reading files, you might need to pass the parameter | ||
| `engine=sdf_engine` when calling any of the above xarray functions. | ||
|
|
||
| ## New to Python? | ||
|
|
||
| ### Installing uv | ||
|
|
||
| We recommend [installing uv](https://docs.astral.sh/uv/getting-started/installation/) which is a command line tool that can install both Python versions and packages. This tool is widely used in the Python community and is significantly faster than other tools that do the same. | ||
|
|
||
| `````{tab-set} | ||
| ````{tab-item} Linux/MacOS | ||
| ```bash | ||
| curl -LsSf https://astral.sh/uv/install.sh | sh | ||
| ``` | ||
| ```` | ||
|
|
||
| ````{tab-item} Windows | ||
| ```powershell | ||
| powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" | ||
| ``` | ||
| You might need to change the [execution policy](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.4#powershell-execution-policies) to allow running a script from the internet. | ||
| ```` | ||
| ````` | ||
|
|
||
| You can then check `uv` is correctly installed by running: | ||
|
|
||
| ```bash | ||
| uv --version | ||
| ``` | ||
|
|
||
| ### Installing Python | ||
|
|
||
| If Python is already installed on your system then `uv` will detect and use it. If you don't have python already installed on your machine you can use `uv` to install it: | ||
|
|
||
| ```console | ||
| uv python install 3.14 | ||
| ``` | ||
| Once installed, it should be possible to run Python using | ||
|
|
||
| ```bash | ||
| python3.14 --version | ||
| ``` | ||
|
|
||
| ### Setting up a virtual environment | ||
|
|
||
| Now that you've installed `uv` and have a supported Python version you need to create a [virtual environment](https://docs.astral.sh/uv/reference/cli/#uv-venv). You need to do this because Python doesn't allow you to install libraries globally on your system. From a folder of your choosing run the following command to create a subfolder called `.venv` containing all the Python libraries you install. | ||
|
|
||
| ```bash | ||
| uv venv | ||
| ``` | ||
|
|
||
| Depending on your operating system you'll need to follow the activation command that appears after running `uv venv`. This will tell Python to use the libraries installed in this package. | ||
|
|
||
| ### Installing sdf-xarray | ||
|
|
||
| Finally we can install <project:#sdf_xarray> to the `venv` using the following command. Any additional packages that can be installed using `pip` can also be installed using this method. | ||
|
|
||
| ```bash | ||
| uv pip install sdf-xarray | ||
| ``` | ||
|
|
||
| ### Getting an error about a missing `CMAKE_C_COMPILER`? | ||
|
|
||
| Are you getting an error that looks like this? | ||
|
|
||
| ```bash | ||
| $ uv pip install sdf-xarray | ||
| Resolved 16 packages in 293ms | ||
| x Failed to build `sdf-xarray==0.7.0` | ||
| |-> The build backend returned an error | ||
| `-> Call to `scikit_build_core.build.build_wheel` failed (exit status: 1) | ||
|
|
||
| [stdout] | ||
| *** scikit-build-core 0.12.2 using CMake 4.3.1 (wheel) | ||
| *** Configuring CMake... | ||
| loading initial cache file /tmp/tmp8ch254_2/build/CMakeInit.txt | ||
| -- Configuring incomplete, errors occurred! | ||
|
|
||
| [stderr] | ||
| CMake Error at | ||
| /nix/tmp/debug-tools/.cache/uv/builds-v0/.tmpa3v1oF/lib/python3.14/site-packages/cmake/data/share/cmake-4.3/Modules/CMakeDetermineCCompiler.cmake:48 | ||
| (message): | ||
| Could not find the compiler specified in the environment variable CC: | ||
|
|
||
| cc -pthread. | ||
| Call Stack (most recent call first): | ||
| CMakeLists.txt:3 (project) | ||
|
|
||
|
|
||
| CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage | ||
|
|
||
| *** CMake configuration failed | ||
|
|
||
| hint: This usually indicates a problem with the package or the build environment. | ||
| ``` | ||
|
|
||
| Don't panic, this error means you've not installed a `C` compiler onto your computer. | ||
|
|
||
| ````{tab-set} | ||
| ```{tab-item} Linux | ||
| If you're on a fresh or recent Linux install then there's a good chance you might be missing a it, you can remedy this by running `sudo apt install build-essential` on Debian-based Linux systems such as Ubuntu. | ||
| ``` | ||
|
|
||
| ```{tab-item} MacOS | ||
| Make sure you've installed the [Command Line Tools package](https://developer.apple.com/documentation/xcode/installing-the-command-line-tools/#Install-the-Command-Line-Tools-package-in-Terminal). | ||
| ``` | ||
|
|
||
| ```{tab-item} Windows | ||
| If you've encountered this error then I have no idea... But I strongly recommending installing [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/install) and running a mini Ubuntu install on your machine instead of fighting windows. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, fair 😆 Last time I ran into this myself I had a pretty good time with Chocolatey, but even then, it was still rough compared to doing anything in Linux.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting... not heard of that one before but that's really cool! Still going to leave it as is. Not my monkey, not my circus lmao |
||
| ``` | ||
| ```` | ||
|
|
||
| ### How do I run my Python scripts? | ||
|
|
||
| As long as you've "activated" your `venv` you can run a Python script from anywhere on your computer. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this error popping up for people because they're having to install from
sdist? I thought we were distributing binaries withcibuildwheel. If so, it would be good to know which OS/architectures/Python versions we're missing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this by spinning up a fresh docker container with an Ubuntu image and following the steps listed in the code including installing
python3.14viauvMaybe installing fromaptinstalls the necessary components? Didn't work until I installed thebuild-essentialfor gcc support.I've really not done a deep dive into how binaries are built/distributed so I have no idea what needs to be done in order to check/fix this. I was hoping you'd be able to help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of machine are you on? I just tried the same and it looks like it just grabbed a binary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious... I have docker desktop installed and ran this using the steps I listed in the above comment in the hope of replicating a "clean" and fresh OS. I've encountered this error before when installing on other machines so I don't see any problem in leaving it in but at the same time if there's something that needs fixing we should look into it