[General boards] [Fall 2018 courses] [Summer 2018 courses] [Winter 2018 courses] [Older or newer terms]

A3: Circular dependency


#1

Haven’t started coding yet, but as I was trying to run each file I encountered this error [for model.py]:

Traceback (most recent call last):
File “C:/Users/----/OneDrive/Desktop/University/4th year/CSC485H1/Assignments/A3/model.py”, line 16, in
from data import score_arcs
File “C:\Users----\OneDrive\Desktop\University\4th year\CSC485H1\Assignments\A3\data.py”, line 22, in
from parser import PartialParse
ImportError: cannot import name ‘PartialParse’

After some googling it seems like this is caused by a circular dependency. Is it true? Or is this error normal to get at first and will be fixed as we implement the assignment?

Thank you for your help


#2

I didn’t have this problem, so it’s not caused by a circular dependency unless you’ve been modifying the imports or the code on CDF has changed. From the path I’m guessing you’re running this code on your own machine; have you made sure to copy over all of the files and data at “/h/u2/csc485h/fall/pub/deptrans/”? Based on the error you’re getting I’d guess you forgot to copy over parser.py and/or data.py?


#3

Yes, I am working on my machine, and no, I didn’t forget to import any file; I copied all the required ones… Professor Penn said we need python3.6 for this assignment, but on my machine I have 3.5 and 2.7
I guess I will be working on CDF for this assignment as well, since I really don’t want to install yet another python instance… You said you didn’t have any issue running “python model.py” on CDF?


#4

I ran the code using Python 3.6 on my machine, not the CDF machines, without any problems.


#5

I am observing the same issue on my machine. I am runing Python 3.6.7 64bit on a Windows 10 machine.


#6

My environment is exactly the same as yours @wenzlern, the only difference is the Python distribution.
But since @attwelli is also running on his own machine I guess I will try to re-get all the files in [—]/deptrans and see what happens


#7

I tried refetching the files and reinstalled python completely. The issue stays the same.


#8

Yes I gave up too, going to work at school for this assignment…


#9

I was able to solve this problem by copy the entire content of parser.py to a new file and using that new file instead. No idea what was the origin of the problem.


#10

I just tried this myself with the same Python version, but on Ubuntu, and didn’t run into this problem. It’s really hard to say without being able to replicate :frowning: I have sometimes run into import issues when I accidentally named one of my project files the same as a Python library, and then tried to import from the library, but that’s all I can think of without going hands-on myself :confused:


#11

I think it’s related to the fact that there’s a built-in module also called parser. I have no idea how to fix it though


#12

ran into the same problem, the posters above are correct. you’ll have to temporarily change the name of parser.py and all the import calls in data.py and model.py as well. Make sure you change them back before you hand it in though!


#13

If there is such a build-in library, then yes, that would definitely cause the issue. Is this module specific to the Windows builds? Are you using Anaconda and it includes it by default? That would explain why we don’t see it on other machines.


#14

Wait, that’s not right. I have a parser module too.

For some reason, the versions you guys are having this issue with are pulling from that module rather than the local file. This is incorrect behaviour for Python, as it’s supposed to go to the local file first.

Are you running the file with the containing folder as the current working directory?


#15

Yes, I am using PyCharm and I double-checked all my virtual environment settings. Everything seems to be OK. And @mcbrid48 is right, I just renamed my file to a3_parser.py, changed the import statements, and now everything runs fine. Not sure why only some of us are having this issue, but I would consider for future offerings of this course to just name the file something different than a build-in module. It can save students quite some time figuring out what’s wrong.


#16

I ran into the same issue, it took me a lot of time to solve it. And the renaming thing does save my life.