jonashaag / micromamba-pycharm

Use Micromamba environments in PyCharm
65 stars 2 forks source link

PyCharm tries to run python in the env (instead of python3) #10

Closed gredin closed 9 months ago

gredin commented 12 months ago

My env:

PyCharm failed to load a micromamba env, so I logged commands sent by PyCharm to your conda executable. I saw this one: conda run -p /home/myuser/micromamba/envs/myenv --no-capture-output python -c 'import sys; print(sys.executable)'

The problem is that python is unavailable (only python3 exists) in the environment.

I've fixed this with: sys.argv = ["python3" if arg == "python" else arg for arg in sys.argv] but there might be a cleaner and universal way.

Thanks for your work anyway, it's great.

jonashaag commented 12 months ago

How did you set up that env?

gredin commented 12 months ago

This happens for my base env and any empty env created by micromamba create -n.

Usually (not sure it's always true), an additional micromamba install X adds a specific Python dependency and a ~/micromamba/envs/env-test/bin/python symlink.

jonashaag commented 12 months ago

Hm, I can't reproduce this

$ micromamba -p /tmp/test create python -y
...
$ file /tmp/test/bin/python
/tmp/test/bin/python: Mach-O 64-bit executable arm64
gredin commented 12 months ago

Here's a Docker-based reproducible example.

Run docker build . -t micromamba-python-test against this Dockerfile:

FROM ubuntu:23.10

ENV DEBIAN_FRONTEND=noninteractive 

RUN apt update \
    && apt -y install python3 curl

RUN bash -c '"${SHELL}" <(curl -L micro.mamba.pm/install.sh)'

RUN bash -c ". /root/.bashrc"

Then run it:

$ docker run --rm -it micromamba-python-test bash
root@container:/# micromamba create -n python-test
Empty environment created at prefix: /root/micromamba/envs/python-test
root@container:/# micromamba activate python-test 
(python-test) root@container:/# python
bash: python: command not found
(python-test) root@container:/# python3
Python 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
jonashaag commented 12 months ago

You didn't install Python into the env