Python Forum
Import Error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Import Error (/thread-33344.html)



Import Error - Christian - Apr-17-2021

Hello everyone

I downloaded a Github repo.
this is the main directory
Quote:baselines common configs envs firl fuck logs README.md run.sh utils

 import sys, os, time
  6 
  7 for i in sys.path:
  8     print(i)
  9 
 10 import numpy as np
 11 import torch
 12 import gym
 13 from ruamel.yaml import YAML
 14 
 15 from firl.divs.f_div import f_div_loss, f_div_current_state_loss
 16 from firl.divs.ipm import ipm_loss
 17 from firl.models.reward import MLPReward
 18 from firl.models.discrim import SMMIRLDisc as Disc
 19 from firl.models.discrim import SMMIRLCritic as Critic
 20 from common.sac import ReplayBuffer, SAC
 21 
 22 import envs
 23 from envs.tasks.grid_task import expert_density
 24 #from utils import system, collect, logger, eval
 25 from fk import system
 26 #from utils.plots.train_plot import plot, plot_disc, plot_submission
 27 #from utils import plot_submission
 28 from sklearn import neighbors
In line 24 (uncomment)
I will get an error that
Output:
Traceback (most recent call last): File "firl/irl_density.py", line 24, in <module> from utils import system, collect, logger, eval ImportError: cannot import name 'system'
I copied the folder into "fk" folder in this case its working Wall

What could be the reason? I am not allowed to use the name "utils" as folder
Thank you very much :)

Best Regards
Chris


RE: Import Error - bowlofred - Apr-17-2021

Usually means there's a circular dependency between the modules. What's the repo?


RE: Import Error - Christian - Apr-17-2021

Thank you for your answer
If you wanna have a look
https://github.com/twni2016/f-IRL.git

It does not look like circular dependency
in system.py is no import of this kinda


RE: Import Error - bowlofred - Apr-17-2021

Hmm. Don't know. That thing has a lot of dependencies, and it won't work at all on my normal 3.9, but on 3.8.6 I was able to get everything installed and I couldn't reproduce the error. I was able to run this script.

Try a fresh venv install?

import sys,os,time
import numpy as np
import torch
import gym
from ruamel.yaml import YAML

from firl.divs.f_div import f_div_loss, f_div_current_state_loss
from firl.divs.ipm import ipm_loss
from firl.models.reward import MLPReward
from firl.models.discrim import SMMIRLDisc as Disc
from firl.models.discrim import SMMIRLCritic as Critic
from common.sac import ReplayBuffer, SAC

import envs
from envs.tasks.grid_task import expert_density

from utils import system, collect, logger, eval
print(dir(system))
Output:
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'np', 'os', 'random', 'reproduce', 'torch']
Output:
$ pip list Package Version ----------------- ------- cloudpickle 1.6.0 cycler 0.10.0 future 0.18.2 gym 0.18.0 joblib 1.0.1 kiwisolver 1.3.1 matplotlib 3.4.1 numpy 1.20.2 Pillow 7.2.0 pip 20.2.1 pyglet 1.5.0 pyparsing 2.4.7 python-dateutil 2.8.1 ruamel.yaml 0.17.4 ruamel.yaml.clib 0.2.2 scikit-learn 0.24.1 scipy 1.6.2 setuptools 49.2.1 six 1.15.0 sklearn 0.0 threadpoolctl 2.1.0 torch 1.8.1 typing-extensions 3.7.4.3
Output:
$ ls README.md baselines common configs envs firl importer.py run.sh utils