could not use operations
Added by Rahan Öztürk over 2 years ago
Hello,
I'd like use cdo inside python. On the website tutorial, it says; from cdo import Cdo, that works fine.
Yet, cdo = Cdo() doesn't work, so i can not manage to run cdo operations on python.
Error message: "TypeError: expected str, bytes or os.PathLike object, not NoneType"
When i run Cdo alone it shows cdo.Cdo
when i run cdo alone ("import cdo") it doesn't work for operations and says; "<module 'cdo' from '~path\\lib\\site-packages\\cdo.py'>"
i installed cdo via conda install; "conda install -c conda-forge cdo"
Replies (12)
RE: could not use operations - Added by Karin Meier-Fleischer over 2 years ago
Hi Rahan,
you have to install python-cdo, too.
conda install -c conda-forge python-cdo
RE: could not use operations - Added by Karin Meier-Fleischer over 2 years ago
Import and use CDO in Python:
from cdo import * cdo = Cdo()
RE: could not use operations - Added by Rahan Öztürk over 2 years ago
Hello Karin,
I've been trying to install python-cdo via "conda install -c conda-forge python-cdo" yet i still couldn't manage to do it both in jupyterlab (pip install cdo) and in anaconda prompt.
https://github.com/Try2Code/cdo-bindings
conda can't solve the environment; failed with initial frozen solve. Retrying with flexible solve.
failed with repodata from current_update.json, will retry with next repodata source.
Thank you
RE: could not use operations - Added by Estanislao Gavilan over 2 years ago
Hi Rahan,
I have encountered that error before. I do not know why but sometimes the conda enviorment gets bugged. So there are two ways to fix it that I know. The first is to create a new enviorment for cdo using "conda create -n new_env". Then, you use again the "conda install -c conda-forge python-cdo" and the others modules that you need. The other is to use the command "pip install python-cdo". The main difference between them is the version. The python-cdo version in conda reposetory might be different to the pip reposetory. I hope you manage to fix it
Kind regards,
Estanislao
RE: could not use operations - Added by Karin Meier-Fleischer over 2 years ago
Hi Rahan nd Estanislao,
this error often occurs when you try to install a package within a conda environment that uses newer libraries.
To install python-cdo with other packages the best way is to create an own environment for python-cdo, activate it and install the other packages into that environment.
conda create -n cdo_env -c conda-forge python-cdo conda activate cdo_env conda install jupyterlab
RE: could not use operations - Added by Rahan Öztürk over 2 years ago
Unfortunately, that did not work either. I created new environment then installed cdo and xarray and typed "from cdo import * and import xarray" then run "cdo = Cdo()" and shows "FileNotFoundError".
It isn't very pleasant to run cdo commands on Ubuntu every time when i want to automate the application. The last choice is to use Ubuntu for the whole process.
Any more ideas? Thank you very much.
RE: could not use operations - Added by Estanislao Gavilan over 2 years ago
Hi Rahan,
just double checking did you install "python-cdo" and "cdo" in that enviroment? I am not sure if I am wrong on this, but I think you need both libraries installed in your new environment
Kind regards,
Estanislao
RE: could not use operations - Added by Rahan Öztürk over 2 years ago
Hello again,
No good news, I tried to install both on a new environment. Anaconda Navigator shows cdo (1.4.0) and python-cdo (1.4.0 updatable) installed yet anaconda prompt doesn't show cdo is installed. Commands don't work either.
Tried to create new environment however, now i am not able to install both cdo and python-cdo... What is going on here :)
On the new environment, when i try to install python-cdo it says; UnstatisfiableError: The following specifications were found to be incompatible with each other: Output in format: Requested package -> Available versions.
RE: could not use operations - Added by Estanislao Gavilan over 2 years ago
Hi Rahan,
sometimes these things are really annoying. I can confirm that Karin method works. I have just installed cdo in my ubuntu 22.04 virtual machine. I downloaded and installed the version 2022.05 of anaconda from the main website. Then I created an enviroment and installed python-cdo as Karin suggested. Speciffically I used these commands.
conda create --name cdo_env
conda activate cdo_env
conda install -c conda-forge python-cdo
Note when you install python-cdo, conda installs the cdo as well. After following these steps conda installs the python-cdo version 1.5.6 and the cdo version 2.0.5.
This does not explain why you cannot do it. The only advise I can give you is to create a virtual machine (easy to create easy to delete) and try it. Sometimes conda gets crazy and you just need a clean installation. But before doing something like that you should test it in a virtual machine. I hope you can fix it.
Kind regards,
Estanislao
RE: could not use operations - Added by Agnès François almost 2 years ago
Hi Rahan,
I don't know if you managed to fix your issue, but I had the exact same problem as you. The only problem was that jupyterlab was not installed in my virtual environment ("conda install jupyterlab") + I was not opening jupyter notebook from it (I was doing it from my base, "jupyter notebook"). Hope it can help !
Kind regards
RE: could not use operations - Added by Karin Meier-Fleischer almost 2 years ago
I would recommend to create a new conda environment as Estanislao has described above. This should solve the frozen solve problem.
And if you want to use different conda envs in your jupyterlab you have to create a kernel for each environment. In each conda env jupyter has to be installed too, or better ipykernel. There are many infos on the web how to create the kernel.
RE: could not use operations - Added by Agnès François almost 2 years ago
Yes, this what I did :)
Then Rahan you can follow this page to link your environment to jupyter notebook : https://janakiev.com/blog/jupyter-virtual-envs/#add-virtual-environment-to-jupyter-notebook