mlco2 / codecarbon

Track emissions from Compute and recommend ways to reduce their impact on the environment.
https://mlco2.github.io/codecarbon
MIT License
1.01k stars 158 forks source link

Ubuntu codecarbon: command not found still exists #442

Open Mingbo-Lee opened 10 months ago

Mingbo-Lee commented 10 months ago

Description

I installed anaconda and created a virtual environment. when I run codecarbon init, I meet the problem as this https://github.com/mlco2/codecarbon/issues/381

What I Did

- create a virtual environment
- install codecaron
- run `codecarbon init`
inimaz commented 10 months ago

Could you provide the exact commands you run to create the virtual environment + install codecarbon?

It could be related to codecarbon being installed into one python version/environment and then trying to run it from a different python version/environment.

Mingbo-Lee commented 10 months ago

Thank you for your reply. create the virtual environment : conda create -n my_env python=3.9 install codecarbon: conda install -c codecarbon -c conda-forge codecarbon,
which ref to https://mlco2.github.io/codecarbon/installation.html#from-conda-repository

inimaz commented 10 months ago

Thanks for the reply!

I have tested on my end and I could reproduce the issue. With conda the bin of codecarbon is never installed, so the command codecarbon init does not exist. This is a bug.

In the meantime I can propose 2 workarounds to use codecarbon:

Workaround 1: install it via pip

Install it via pip install codecarbon and you will be able to use it in the command line

Workaround 2: Use it as a python module

Create a .py file and import the package codecarbon. See https://mlco2.github.io/codecarbon/usage.html#quickstart for examples on how to use it as a python package

inimaz commented 10 months ago

As a first glance at the root of the bug, IMHO this is something to do with https://github.com/mlco2/codecarbon/blob/master/setup.py#L58-L63 In the conda file we do not mention these entry points https://github.com/mlco2/codecarbon/blob/master/.conda/meta.yaml

Mingbo-Lee commented 10 months ago

Thank you very much for your reply!

inimaz commented 10 months ago

Note that this one is the one used to build the conda-forge package https://github.com/conda-forge/codecarbon-feedstock/blob/8758935e5c3e3de31a1cdc78e3d2d1eb683c5f1e/recipe/meta.yaml#L16C15-L18