1

I have installed python and miniconda (I had installed conda before but it didn't work so I opted for miniconda). I opened my anaconda prompt, created my environment, imported all my packages including gdal: conda install -c conda-forge gdal.

When I try to run my python program in the anaconda prompt

(StageEnv) C:\Users\julia\Documents\Stage\QGis\QGis1>python3 interannual_mean_values.py

I get the error

Traceback (most recent call last):
  File "C:\Users\julia\Documents\Stage\QGis\QGis1\interannual_mean_values.py", line 3, in <module>
    import gdal
ModuleNotFoundError: No module named 'gdal'

I have already looked at the solutions proposed here can't import gdal in python?

I also tried from osgeo import gdal but that doesn't work either : when I tried to install osgeo, conda couldn't find it, then I check in the folder where there are all the libs (C:\Users\julia\miniconda3\envs\StageEnv\Lib\site-packages) and there is osgeo. But when I runned it, I had the error no module named 'osgeo'.

Can anyone help please ^^'?

Thanks!

(PS: I'd like to point out that I don't run my code from my IDE (VS) because I get no module named numpy error. The error seems to come from the environment: when I open my file, the prompt automatically runs:

PS C:\Users\julia>  C:/Users/julia/miniconda3/Scripts/activate
PS C:\Users\julia>  conda activate StageEnv

and it's indeed the name of my environment that is displayed as my interpreter. However, when I type conda list in the prompt it outputs the base environment, thus without all the libraries I have installed and not the one in my environment.I've already manually added the miniconda directory to the PATH environment variable. I think it is due to the first line, but as in conda it seems to work until my problem with no module named gdal, I was fine with using it).

juliasvn
  • 11
  • 1
  • Have you made sure that `python3` actually points to the interpreter in the env? try running `python3 -c "import os; print(os.executable)"` – FlyingTeller Apr 26 '23 at 14:17
  • What does `where python3` show? Does simply `python` behave any differently? – merv Apr 26 '23 at 20:08
  • Hi, thank you for your reply, yes I started by putting python3 before my filename and then I tried your command but it still didn't work. I had two pythons installed, I think that is why I had my problem! I uninstalled them and reinstalled python 3 and it doesn't show me the error in anaconda, many thanks for pointing me in the right direction!! However I still have a problem because cause when I run my code with anaconda, nothing happens and as I still have the same problem with VS I cannot try with :( – juliasvn Apr 27 '23 at 08:13
  • For `Where python3` I obtained C:\Users\julia\AppData\Local\Microsoft\WindowsApps\python3.exe whereas for `where python` I obtained: C:\Users\julia\miniconda3\envs\StageEnv\python.exe C:\Users\julia\miniconda3\python.exe C:\Users\julia\AppData\Local\Microsoft\WindowsApps\python.exe Should it be python3 instead of python? – juliasvn Apr 27 '23 at 08:41

0 Answers0