aspuru-guzik-group / funsies

funsies is a lightweight workflow engine 🔧
MIT License
41 stars 3 forks source link

python import not working (Windows?) #3

Closed gflofst closed 3 years ago

gflofst commented 3 years ago

I am trying to get things to work properly in conda in Windows for the testing. I had to run redis in another window because I can't figure out how to drop it in the background, but I am not sure if that will work or not yet as the import line in the example hello-world fails from the pip install funsies (0.7.0)

(base) PS C:\Users\gflofst> pip install funsies Collecting funsies Using cached funsies-0.7.0-py3-none-any.whl (57 kB) Requirement already satisfied: rq>=1.7 in c:\programdata\anaconda3\lib\site-packages (from funsies) (1.8.1) Requirement already satisfied: chevron in c:\programdata\anaconda3\lib\site-packages (from funsies) (0.14.0) Requirement already satisfied: loguru in c:\programdata\anaconda3\lib\site-packages (from funsies) (0.5.3) Requirement already satisfied: mypy-extensions in c:\programdata\anaconda3\lib\site-packages (from funsies) (0.4.3) Requirement already satisfied: cloudpickle in c:\programdata\anaconda3\lib\site-packages (from funsies) (1.6.0) Requirement already satisfied: redis in c:\programdata\anaconda3\lib\site-packages (from funsies) (3.5.3) Requirement already satisfied: click>=5.0.0 in c:\programdata\anaconda3\lib\site-packages (from rq>=1.7->funsies) (7.1.2) Requirement already satisfied: win32-setctime>=1.0.0 in c:\programdata\anaconda3\lib\site-packages (from loguru->funsies) (1.0.3) Requirement already satisfied: colorama>=0.3.4 in c:\programdata\anaconda3\lib\site-packages (from loguru->funsies) (0.4.4) Installing collected packages: funsies Successfully installed funsies-0.7.0 (base) PS C:\Users\gflofst> python funsies.py Traceback (most recent call last): File "funsies.py", line 1, in from funsies import execute, Fun, reduce, shell File "C:\Users\gflofst\funsies.py", line 1, in from funsies import execute, Fun, reduce, shell ImportError: cannot import name 'execute' from partially initialized module 'funsies' (most likely due to a circular import) (C:\Users\gflofst\funsies.py) (base) PS C:\Users\gflofst>

clavigne commented 3 years ago

So the problem is due to the (confusing) way python deals with imports. Local files are imported by name, and they have precedence over installed packages. So doing

from funsies import execute

in a folder with a file funsies.py will attempt to perform the import from that file, not from the installed library with the same name, because the python import system gives local files a higher precedence.

I tested it and can confirm the same issue using a file named funsies.py and that changing the name of the file funsies.py to anything else (e.g. hello.py) resolves it.