1

I'm trying to run a Python script but it gives an error immediately at the first line of code while trying importing hydra library via:

import hydra

The error i get is the following:

Traceback (most recent call last):
  File "C:\Documenti\Python\01 Tool\02_Tool_Archive\calc_risk\src\main.py", line 3, in <module>
    import hydra
ModuleNotFoundError: No module named 'hydra'

As the install via right click on the hydra does not work, i tried to google the error and found a possible solution via installing the hydra via pip install from the terminal - this is what i get after calling the pip install again after the first successfull installation:

PS C:\Documenti\Python\01 Tool> pip install hydra-core --upgrade
Requirement already satisfied: hydra-core in c:\users\mhlaca\appdata\local\programs\python\python310\lib\site-packages (1.2.0)
Requirement already satisfied: packaging in c:\users\mhlaca\appdata\local\programs\python\python310\lib\site-packages (from hydra-core) (21.3)
Requirement already satisfied: omegaconf~=2.2 in c:\users\mhlaca\appdata\local\programs\python\python310\lib\site-packages (from hydra-core) (2.3.0.dev0)          
Requirement already satisfied: antlr4-python3-runtime==4.9.* in c:\users\mhlaca\appdata\local\programs\python\python310\lib\site-packages (from hydra-core) (4.9.3)
Requirement already satisfied: PyYAML>=5.1.0 in c:\users\mhlaca\appdata\local\programs\python\python310\lib\site-packages (from omegaconf~=2.2->hydra-core) (6.0)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\users\mhlaca\appdata\local\programs\python\python310\lib\site-packages (from packaging->hydra-core) (3.0.9)

I'm currently stuck. What can I try next? Using Python 3.10.7 and pycharm as IDE, but also tried visual studio - same error.

Jasha
  • 5,507
  • 2
  • 33
  • 44
Mario
  • 137
  • 1
  • 10
  • 1
    `Using python 3.10.7 and pycharm as IDE` so, if you're using PyCharm, then you need to set up your project interpreter and make sure all relevant packages are installed - or make one with the "inherit global site-packages" option enabled (which I think will work too). Otherwise using `pip` only installs to the system interpreter environment, not the Virtualenv environment that your PyCharm project is using. – Random Davis Sep 23 '22 at 17:57
  • @RandomDavis the hydra-core package is actually installed in the selected python interpreter - but still I'm getting that error. – Mario Sep 23 '22 at 21:02
  • If you run python via the command line and try to import hydra there, does it work? – Random Davis Sep 23 '22 at 21:23
  • @RandomDavis from the python console it works fine...that's strange – Mario Sep 24 '22 at 18:16
  • So then you're using the wrong interpreter in PyCharm, or you think you have the package installed to the one in PyCharm when you really don't. It's pretty straightforward, and I still stand by my first message, despite your message telling me that it is installed. – Random Davis Sep 27 '22 at 15:08

0 Answers0