Skip to content

Commit 281763c

Browse files
authored
docs: refactor getting started and python tutorial (#3977)
1 parent 0db4c48 commit 281763c

File tree

6 files changed

+276
-98
lines changed

6 files changed

+276
-98
lines changed

docs/first_project.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Making a Pixi project
2+
3+
Pixi's biggest strength is its ability to create reproducible powerful and flexible projects.
4+
Let's go over the common steps to create a Pixi project.
5+
6+
## Creating a Pixi project
7+
To create a new Pixi project, you can use the `pixi init` command:
8+
9+
```shell
10+
pixi init my_project
11+
```
12+
13+
This command creates a new directory called `my_project` with the following structure:
14+
15+
```shell
16+
my_project
17+
├── .gitattributes
18+
├── .gitignore
19+
└── pixi.toml
20+
```
21+
22+
The `pixi.toml` file is the manifest of your Pixi project.
23+
It contains all the information about your project, such as its channels, platforms, dependencies, tasks, and more.
24+
25+
The one created by `pixi init` is a minimal manifest that looks like this:
26+
27+
```toml title="pixi.toml"
28+
[workspace]
29+
authors = ["Jane Doe <[email protected]>"]
30+
channels = ["conda-forge"]
31+
name = "my_project"
32+
platforms = ["osx-arm64"]
33+
version = "0.1.0"
34+
35+
[tasks]
36+
37+
[dependencies]
38+
```
39+
40+
??? tip "Do you want autocompletion of the manifest file?"
41+
As `pixi.toml` has a JSON schema, it is possible to use IDE’s like VSCode to edit the field with autocompletion.
42+
Install the Even [Better TOML VSCode](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml) extension to get the best experience.
43+
Or use the integrated schema support in PyCharm.
44+
45+
## Managing dependencies
46+
After creating the project, you can start adding dependencies to the project.
47+
Pixi uses the `pixi add` command to add dependencies to the project.
48+
This command will , by default, add the **conda** dependency to the `pixi.toml`, solve the dependencies, write the lockfile and install the package in the environment.
49+
For example, lets add `numpy` and `pytest` to the project.
50+
51+
```shell
52+
pixi add numpy pytest
53+
```
54+
This results in these lines being added:
55+
56+
```toml title="pixi.toml"
57+
[dependencies]
58+
numpy = ">=2.2.6,<3"
59+
pytest = ">=8.3.5,<9"
60+
```
61+
62+
You can also specify the version of the dependency you want to add.
63+
64+
```shell
65+
pixi add numpy==2.2.6 pytest==8.3.5
66+
```
67+
68+
### PyPI dependencies
69+
Pixi normally uses `conda` packages for dependencies, but you can also add dependencies from PyPI.
70+
Pixi will make sure it doesn't try to install the same package from both sources, and avoid conflicts between them.
71+
72+
If you want to add them to your project you can do that with the `--pypi` flag:
73+
74+
```shell
75+
pixi add --pypi requests
76+
```
77+
This will add the `requests` package from PyPI to the project:
78+
79+
```toml title="pixi.toml"
80+
[pypi-dependencies]
81+
requests = ">=2.31.0,<3"
82+
```
83+
84+
## Lockfile
85+
Pixi will always create a lockfile when the dependencies are solved.
86+
This file will contain all the exact version of the packages and their dependencies.
87+
Resulting in a reproducible environment, that you can share with others or use for testing and deployment.
88+
89+
The lockfile is called `pixi.lock` and it is created in the root of the project.
90+
It contains all the information about the dependencies, such as their versions, channels, platforms, and more.
91+
92+
```yaml title="pixi.lock"
93+
version: 6
94+
environments:
95+
default:
96+
channels:
97+
- url: https://prefix.dev/conda-forge/
98+
indexes:
99+
- https://pypi.org/simple
100+
packages:
101+
osx-arm64:
102+
- conda: https://prefix.dev/conda-forge/osx-arm64/bzip2-1.0.8-h99b78c6_7.conda
103+
- pypi: ...
104+
packages:
105+
- conda: https://prefix.dev/conda-forge/osx-arm64/bzip2-1.0.8-h99b78c6_7.conda
106+
sha256: adfa71f158cbd872a36394c56c3568e6034aa55c623634b37a4836bd036e6b91
107+
md5: fc6948412dbbbe9a4c9ddbbcfe0a79ab
108+
depends:
109+
- __osx >=11.0
110+
license: bzip2-1.0.6
111+
license_family: BSD
112+
size: 122909
113+
timestamp: 1720974522888
114+
- pypi: ...
115+
```
116+
117+
## Managing tasks
118+
Pixi has a built-in cross-platform task runner that allows you to define tasks in the manifest.
119+
This is a great way to share tasks with others and to ensure that the same tasks are run in the same environment.
120+
The tasks are defined in the `pixi.toml` file under the `[tasks]` section.
121+
122+
You can add one to your project by running the `pixi task add` command.
123+
124+
```shell
125+
pixi task add hello "echo Hello, World!"
126+
```
127+
This will add the following lines to the `pixi.toml` file:
128+
129+
```toml title="pixi.toml"
130+
[tasks]
131+
hello = "echo Hello, World!"
132+
```
133+
You can then run the task using the `pixi run` command:
134+
135+
```shell
136+
pixi run hello
137+
```
138+
This will execute the command `echo Hello, World!` in the environment.
139+
140+
## Environments
141+
Pixi always creates a virtual environment for your project.
142+
These environments are located in the `.pixi/envs` directory in the root of your project.
143+
144+
Using these environments is as simple as running the `pixi run` or `pixi shell` command.
145+
These commands will automatically activate the environment and run the command in it.
146+
147+
```shell
148+
pixi run python -VV
149+
# or:
150+
pixi shell
151+
python -VV
152+
exit
153+
```

docs/getting_started.md

Lines changed: 85 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,106 @@
1-
Every Pixi workspace is described by a Pixi manifest.
2-
In this simple example we have a single task `start` which runs a Python file and two dependencies, `cowpy` and `python`.
1+
# Basic usage of Pixi
32

4-
```toml title="pixi.toml"
5-
--8<-- "docs/source_files/pixi_workspaces/introduction/task_add/pixi.toml"
6-
```
3+
Pixi can do alot of things, but it is designed to be simple to use.
4+
Let's go through the basic usage of Pixi.
75

8-
`channels` describes where our dependencies come from and `platforms` which platforms we support.
9-
However, you might wonder why we need to specify the platforms if Pixi could just extract this information from your operating system.
10-
That is because every dependency in your environment is stored in the lockfile called `pixi.lock`.
11-
This ensures that even if you run your workspace on a different platform, the environment will contain exactly the dependencies that were solved on your machine.
12-
This is one of the core features that makes Pixi reproducible.
13-
Learn more about lock files in [this chapter](./workspace/lockfile.md).
6+
## Managing workspaces or projects
147

8+
- [`pixi init`](./reference/cli/pixi/init.md) - create a new Pixi manifest in the current directory
9+
- [`pixi add`](./reference/cli/pixi/add.md) - add a dependency to your manifest
10+
- [`pixi remove`](./reference/cli/pixi/remove.md) - remove a dependency from your manifest
11+
- [`pixi update`](./reference/cli/pixi/update.md) - update dependencies in your manifest
12+
- [`pixi upgrade`](./reference/cli/pixi/upgrade.md) - upgrade the dependencies in your manifest to the latest versions, even if you pinned them to a specific version
13+
- [`pixi lock`](./reference/cli/pixi/lock.md) - create or update the lockfile for your manifest
14+
- [`pixi info`](./reference/cli/pixi/info.md) - show information about your workspace
15+
- [`pixi run`](./reference/cli/pixi/run.md) - run a task defined in your manifest or any command in the current environment
16+
- [`pixi shell`](./reference/cli/pixi/shell.md) - start a shell in the current environment
17+
- [`pixi list`](./reference/cli/pixi/list.md) - list all dependencies in the current environment
18+
- [`pixi tree`](./reference/cli/pixi/tree.md) - show a tree of dependencies in the current environment
19+
- [`pixi clean`](./reference/cli/pixi/clean.md) - remove the environment from your machine
1520

16-
## Multiple environments
17-
18-
We already have a quite powerful setup which is sufficient for many use cases.
19-
However, certain things are hard to do with the way things are set up right now.
20-
What if I wanted to check if my script works with multiple versions of Python?
21-
There cannot be multiple versions of the same package in one environment.
22-
Luckily, Pixi is able to manage multiple environments!
21+
## Managing global installations
22+
Pixi can manage global installations of tools and environments.
23+
It installs the environments in a central location, so you can use them from anywhere.
2324

24-
Environments are composed of features, so let's create a `py312` and `py313` features each with `python` set to a different version.
25-
Then we will add those features to environments of the same name.
26-
27-
```toml title="pixi.toml"
28-
--8<-- "docs/source_files/pixi_workspaces/introduction/multi_env/pixi.toml"
29-
```
25+
- [`pixi global install`](./reference/cli/pixi/global/install.md) - install a package into it's own environment in the global space.
26+
- [`pixi global uninstall`](./reference/cli/pixi/global/uninstall.md) - uninstall an environment from the global space.
27+
- [`pixi global add`](./reference/cli/pixi/global/add.md) - add a package to an existing globally installed environment.
28+
- [`pixi global sync`](./reference/cli/pixi/global/sync.md) - sync the globally installed environments with the global manifest, describing all the environments you want to install.
29+
- [`pixi global edit`](./reference/cli/pixi/global/edit.md) - edit the global manifest.
30+
- [`pixi global update`](./reference/cli/pixi/global/update.md) - update the global environments
31+
- [`pixi global list`](./reference/cli/pixi/global/list.md) - list all the installed environments
3032

31-
Pixi does two things behind the scenes which might not be immediately obvious.
32-
First, it automatically creates both a feature and environment called `default`.
33-
`[dependencies]` and `[tasks]` belong to that feature.
34-
Second, it adds the `default` feature to each environment unless you explicitly opt-out.
35-
That means you can read the manifest as if it were declared like this:
33+
More information: [Global Tools](./global_tools/introduction.md)
3634

37-
!!! warning
35+
## Running one-off commands
36+
Pixi can run one-off commands in a specific environment.
3837

39-
This written out for demonstration purposes.
40-
Don't spell "default" out like this in your own manifest, Pixi will do it for you behind the scenes.
38+
- [`pixi exec`](./reference/cli/pixi/exec.md) - run a command in a temporary environment.
39+
- [`pixi exec --spec`](./reference/cli/pixi/exec.md#arg---spec) - run a command in a temporary environment, with a specific specification.
4140

42-
```toml
43-
[workspace]
44-
channels = ["conda-forge"]
45-
name = "hello-world"
46-
platforms = ["linux-64", "osx-arm64", "win-64"]
47-
48-
# [tasks] belong to the default feature
49-
[feature.default.tasks]
50-
start = 'python hello.py'
51-
52-
# [dependencies] belong to the default feature
53-
[feature.default.dependencies]
54-
cowpy = "1.1.*"
55-
56-
[feature.py312.dependencies]
57-
python = "3.12.*"
58-
59-
[feature.py313.dependencies]
60-
python = "3.13.*"
61-
62-
[environments]
63-
# Pixi automatically creates a default environment that consists only of the default feature
64-
default = ["default"]
65-
# Unless you opt-out with `no-default-feature`, every environment contains the default feature
66-
py312 = ["default", "py312"]
67-
py313 = ["default", "py313"]
68-
```
69-
70-
Let's adapt the Python script so that it displays the current Python version:
71-
72-
```py title="hello.py"
73-
--8<-- "docs/source_files/pixi_workspaces/introduction/multi_env/hello.py"
74-
```
75-
76-
The task `start` is available in both `py312` and `py313`, so we can test the script like this to test against Python 3.12:
41+
For example:
7742

7843
```bash
79-
pixi run --environment=py312 start
44+
> pixi exec python -VV
45+
Python 3.13.5 | packaged by conda-forge | (main, Jun 16 2025, 08:24:05) [Clang 18.1.8 ]
46+
> pixi exec --spec "python=3.12" python -VV
47+
Python 3.12.11 | packaged by conda-forge | (main, Jun 4 2025, 14:38:53) [Clang 18.1.8 ]
8048
```
8149

82-
```
83-
_________________________
84-
< Hello from Python 3.12! >
85-
-------------------------
86-
\ ^__^
87-
\ (oo)\_______
88-
(__)\ )\/\
89-
||----w |
90-
|| ||
91-
```
50+
## Multiple environments
51+
Pixi workspaces allow you to manage multiple environments.
52+
An environment is build out of one or multiple features.
9253

93-
And we can run this command to try it with Python 3.13:
54+
- [`pixi add --feature`](./reference/cli/pixi/add.md#arg---feature) - add a package to a feature
55+
- [`pixi task add --feature`](./reference/cli/pixi/task/add.md#arg---feature) - add a task to a specific feature
56+
- [`pixi workspace environment add`](./reference/cli/pixi/workspace/environment/add.md) - add an environment to the workspace
57+
- [`pixi run --environment`](./reference/cli/pixi/run.md#arg---environment) - run a command in a specific environment
58+
- [`pixi shell --environment`](./reference/cli/pixi/shell.md#arg---environment) - activate a specific environment
59+
- [`pixi list --environment`](./reference/cli/pixi/list.md#arg---environment) - list the dependencies in a specific environment
9460

61+
More information: [Multiple environments](./workspace/multi_environment.md)
9562

96-
```bash
97-
pixi run --environment=py313 start
98-
```
63+
## Tasks
64+
Pixi can run cross-platform tasks using it's built-in task runner.
65+
This can be a predefined task or any normal executable.
9966

67+
- [`pixi run`](./reference/cli/pixi/run.md) - Run a task or command
68+
- [`pixi task add`](./reference/cli/pixi/task/add.md) - Add a new task to the manifest
69+
70+
Tasks can have other tasks as dependencies.
71+
Here is an example of a more complex task usecase
72+
```toml title="pixi.toml"
73+
[tasks]
74+
build = "make build"
75+
# using the toml table view
76+
[tasks.test]
77+
cmd = "pytest"
78+
depends-on = ["build"]
10079
```
101-
_________________________
102-
< Hello from Python 3.13! >
103-
-------------------------
104-
\ ^__^
105-
\ (oo)\_______
106-
(__)\ )\/\
107-
||----w |
108-
|| ||
109-
```
80+
More information: [Tasks](./workspace/advanced_tasks.md)
81+
82+
## Multi platform support
83+
Pixi supports multiple platforms out of the box.
84+
You can specify which platforms your workspace supports and Pixi will ensure that the dependencies are compatible with those platforms.
85+
86+
- [`pixi add --platform`](./reference/cli/pixi/add.md#arg---platform) - add a package only to a specific platform
87+
- [`pixi workspace platform add`](./reference/cli/pixi/workspace/platform/add.md) - add a platform to the workspace that you want to support with your project
88+
89+
More information: [Multi platform support](./workspace/multi_platform_configuration.md)
90+
91+
## Utilities
92+
Pixi comes with a set of utilities to help you debug or manage your setup.
93+
94+
- [`pixi info`](./reference/cli/pixi/info.md) - Show information about the current workspace, and the global setup.
95+
- [`pixi config`](./reference/cli/pixi/config.md) - Show or edit the Pixi configuration.
96+
- [`pixi tree`](./reference/cli/pixi/tree.md) - Show a tree of dependencies in the current environment.
97+
- [`pixi list`](./reference/cli/pixi/list.md) - List all dependencies in the current environment.
98+
- [`pixi clean`](./reference/cli/pixi/clean.md) - Remove the project environments from your machine.
99+
- `pixi help` - Show help for Pixi commands.
100+
- `pixi help <subcommand>` - Show help for a specific Pixi command.
101+
- [`pixi auth`](./reference/cli/pixi/auth.md) - Manage authentication for conda channels.
102+
- [`pixi search`](./reference/cli/pixi/search.md) - Search for packages in the configured channels.
103+
- [`pixi completion`](./reference/cli/pixi/completion.md) - Generate shell completion scripts for Pixi commands.
110104

111105

112106
## Going further

docs/installation.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Installation
12
To install `pixi` you can run the following command in your terminal:
23

34
=== "Linux & macOS"
@@ -35,7 +36,9 @@ Now restart your terminal or shell to make the installation effective.
3536
You can check the installation `sh` script: [download](https://pixi.sh/install.sh) and the `ps1`: [download](https://pixi.sh/install.ps1).
3637
The scripts are open source and available on [GitHub](https://github.com/prefix-dev/pixi/tree/main/install).
3738

38-
39+
!!! note "Don't forget to add autocompletion!"
40+
After installing Pixi, you can enable autocompletion for your shell.
41+
See the [Autocompletion](#autocompletion) section below for instructions.
3942
## Update
4043

4144
Updating is as simple as installing, rerunning the installation script gets you the latest version.
@@ -213,3 +216,22 @@ Add the following to the end of `~/.elvish/rc.elv`:
213216
214217
eval (pixi completion --shell elvish | slurp)
215218
```
219+
220+
# Uninstall
221+
Before un-installation you might want to delete any previous files pixi has installed.
222+
223+
1. Remove any cached data:
224+
```shell
225+
pixi clean cache
226+
```
227+
2. Remove the environments from your pixi projects:
228+
```shell
229+
cd path/to/project && pixi clean
230+
```
231+
3. Remove the `pixi` and it's global environments
232+
```shell
233+
rm -r ~/.pixi
234+
```
235+
4. Remove the pixi binary from your `PATH`:
236+
- For Linux and macOS, remove `~/.pixi/bin` from your `PATH` in your shell configuration file (e.g., `~/.bashrc`, `~/.zshrc`).
237+
- For Windows, remove `%UserProfile%\.pixi\bin` from your `PATH` environment variable.

0 commit comments

Comments
 (0)