PyCharm
You can use PyCharm with pixi environments by using the conda
shim provided by the pixi-pycharm package.
How to use#
To get started, add pixi-pycharm
to your pixi project.
This will ensure that the conda shim is installed in your project's environment.
Having pixi-pycharm
installed, you can now configure PyCharm to use your pixi environments.
Go to the Add Python Interpreter dialog (bottom right corner of the PyCharm window) and select Conda Environment.
Set Conda Executable to the full path of the conda
file (on Windows: conda.bat
) which is located in .pixi/envs/default/libexec
.
You can get the path using the following command:
This is an executable that tricks PyCharm into thinking it's the proper conda
executable.
Under the hood it redirects all calls to the corresponding pixi
equivalent.
Use the conda shim from this pixi project
Please make sure that this is the conda
shim from this pixi project and not another one.
If you use multiple pixi projects, you might have to adjust the path accordingly as PyCharm remembers the path to the conda executable.
Having selected the environment, PyCharm will now use the Python interpreter from your pixi environment.
PyCharm should now be able to show you the installed packages as well.
You can now run your programs and tests as usual.
Mark .pixi
as excluded
In order for PyCharm to not get confused about the .pixi
directory, please mark it as excluded.
Also, when using a remote interpreter, you should exclude the .pixi
directory on the remote machine.
Instead, you should run pixi install
on the remote machine and select the conda shim from there.
Multiple environments#
If your project uses multiple environments to tests different Python versions or dependencies, you can add multiple environments to PyCharm by specifying Use existing environment in the Add Python Interpreter dialog.
You can then specify the corresponding environment in the bottom right corner of the PyCharm window.
Multiple pixi projects#
When using multiple pixi projects, remember to select the correct Conda Executable for each project as mentioned above. It also might come up that you have multiple environments it might come up that you have multiple environments with the same name.
It is recommended to rename the environments to something unique.
Debugging#
Logs are written to ~/.cache/pixi-pycharm.log
.
You can use them to debug problems.
Please attach the logs when filing a bug report.
Install as an optional dependency#
In some cases, you might only want to install pixi-pycharm
on your local dev-machines but not in production.
To achieve this, we can use multiple environments.
[project]
name = "multi-env"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["numpy"]
[tool.pixi.project]
channels = ["conda-forge"]
platforms = ["linux-64"]
[tool.pixi.feature.lint.dependencies]
ruff = "*"
[tool.pixi.feature.dev.dependencies]
pixi-pycharm = "*"
[tool.pixi.environments]
# The production environment is the default feature set.
# Adding a solve group to make sure the same versions are used in the `default` and `prod` environments.
prod = { solve-group = "main" }
# Setup the default environment to include the dev features.
# By using `default` instead of `dev` you'll not have to specify the `--environment` flag when running `pixi run`.
default = { features = ["dev"], solve-group = "main" }
# The lint environment doesn't need the default feature set but only the `lint` feature
# and thus can also be excluded from the solve group.
lint = { features = ["lint"], no-default-feature = true }
Now you as a user can run pixi shell
, which will start the default environment.
In production, you then just run pixi run -e prod COMMAND
, and the minimal prod environment is installed.