1 year ago
#192516
user3761340
Time of Day affecting how Python Package is Loaded
Of course, I doubt the ToD has anything to do with whether the package gets loaded or not, but it sure feels that way.
Please allow me to share a bit of background.
As part of my leveraging of the following GeeksforGeeks article:
https://www.geeksforgeeks.org/draw-control-flow-graph-using-pycfg-python/
I had to install pycfg.py. As shown in the GeeksforGeeks article, the file cfg.py has the following header:
from pycfg.pycfg import PyCFG, CFGNode, slurp
import argparse
import tkinter as tk
from PIL import ImageTk, Image
After PIP installing pyconfig, i still could not get this thing to run. (Note that I am running on Cygwin which is notorious for installation/path issues, and I was mucking with paths and installations quite a bit to try to get things going, so there is no telling what kind of messed up state I imposed on my Windows/Cygwin/Python environment.)
The guts of what I am trying to get working is the control flow graph that is so nicely enabled by the pycfg package.
Note that pycfg.py is installed here on Cygwin:
/usr/local/lib/python3.9/site-packages/pycfg
One dependency of pycfg is Graphviz, which is probably the trickiest part of running this thing on Cygwin. I'm not sure whether adding the path to the Windows environment, doing the pycfg install with PIP, doing the pycfg install with Cygwin, doing the Graphviz install any of various ways, modifying the Cygwin path, or some other modification of the environment or code was the "magic" that finally enabled the whole thing to work in Cygwin's XWindows. Internet searches, certainly offered many opinions about how to get things working in Cygwin, at least one of which involved rebuilding Graphviz from source. I think another might have suggested building CPython itself from source. I certainly did not want to go down that path this early in my Python "career", especially on Cygwin. Notwithstanding, I was willing to try just about anything to get these utopian control flow graph pictures!
OK, that is the background, now here is the weirdness. Everything was running great until I went boarding at Breckenridge the other week and subsequently returned home this week to run my "go" script, only to see the same issue with loading packages as before:
Traceback (most recent call last): File "/c/z/python/avaca/compiler/cfg/./cfg.py", line 1, in from pycfg import PyCFG, CFGNode, slurp ImportError: cannot import name 'PyCFG' from 'pycfg' (unknown location)
For some reason this seems to be the trigger:
from pycfg.pfcfg import PyCFG, CFGNode, slurp
vs
from pycfg import PyCFG, CFGNode, slurp
It appears based on whether I've been boarding or not, that one works or the other (or both). Note that the original was:
from pycfg.pycfg import PyCFG, CFGNode, slurp
The form, "pycfg.pycfg" is also working now.
I thought that it was weird from the get-go that they chose to use "from pycfg.pycfg" rather than "from pycfg", and lo and behold, it (originally) finally worked with:
from pycfg import PyCFG, CFGNode, slurp
Trying to understand this bizarreness, I switched it back to pycfg.pycfg, and it still worked. Then I switched it back to the more sensical (in my mind anyway), plain ole pycfg, and it continued working. That is, until I returned from Breck.
Ever since, I have been down a package/module implementation rabbit hole, and these efforts have been somewhat fruitless. I've watched several package related tutorials, and even peered a bit at the CPython source, but to no avail.
Now, there is a class called "PyCFG" in pycfg.py, but there is no reference to any lower case "pycfg" in the file.
Does anyone have any ideas about what might be causing this apparent ToD fiasco, or why and in what situations one might use "from pycfg.pycfg..." vs "from pycfg" to invoke a module or package?
Thanks!
python
module
package
cygwin
control-flow-graph
0 Answers
Your Answer