(prefect-env) root@ubuntu:/venv/prefect-env/flows#...
# ask-community
a
(prefect-env) root@ubuntu:/venv/prefect-env/flows# python email.py Traceback (most recent call last): File "email.py", line 1, in <module> from prefect import task, Flow File "/venv/prefect-env/lib/python3.8/site-packages/prefect/__init__.py", line 1, in <module> import prefect.utilities File "/venv/prefect-env/lib/python3.8/site-packages/prefect/utilities/__init__.py", line 9, in <module> import prefect.utilities.notifications File "/venv/prefect-env/lib/python3.8/site-packages/prefect/utilities/notifications/__init__.py", line 1, in <module> from prefect.utilities.notifications.notifications import callback_factory File "/venv/prefect-env/lib/python3.8/site-packages/prefect/utilities/notifications/notifications.py", line 7, in <module> import smtplib File "/usr/lib/python3.8/smtplib.py", line 47, in <module> import email.utils File "/venv/prefect-env/flows/email.py", line 1, in <module> from prefect import task, Flow ImportError: cannot import name 'task' from partially initialized module 'prefect' (most likely due to a circular import) (/venv/prefect-env/lib/python3.8/site-packages/prefect/__init__.py) (prefect-env) root@ubuntu:/venv/prefect-env/flows# cat email.py from prefect import task, Flow from prefect.tasks.notifications.email_task import EmailTask @task(name="Task A") def send_email(): EmailTask( subject="Test Prefect EmailTask", msg="Hello success", email_to="email@gmail.com" ) with Flow("Email Task example") as flow: send_email() flow.register(project_name="test") (prefect-env) root@ubuntu:/venv/prefect-env/flows#
k
Hey @Ayyanar Thangaraj, could you move the Traceback into the thread to keep the main channel more compact? This tends to happen when you have naming conflicts with your file structure. Do you have a directory named
prefect
? Do you have files named
tasks.py
,
task.py
? These will cause conflicting imports
a
No @Kevin Kho I don't have anything like above prefect directory and tasks.py, task.py.
(prefect-env) root@ubuntu:/venv/prefect-env/flows# (prefect-env) root@ubuntu:/venv/prefect-env/flows# ls email.py pycache (prefect-env) root@ubuntu:/venv/prefect-env/flows# cd .. (prefect-env) root@ubuntu:/venv/prefect-env# ls bin flows include lib lib64 pyvenv.cfg share (prefect-env) root@ubuntu:/venv/prefect-env#
k
How did you install prefect?
pip install
into the venv?
a
Yes
k
I just wanna make sure it’s not a directory thing. Could you make a subfolder in flows named something like
test
, put
email.py
there and try running that?
I am not familiar with
venv
as much so I’d have to ask the team tomorrow, but this might also be because the script you have is inside the
venv
. It might also be worth trying to have the script in the directory above
venv
, but still have the
venv
activated. If this also fails, I would look at your path and see if there is a folder in your path that has a folder named
prefect
that can cause the import conflict
Placing the scripts inside the
venv
folder seems to be bad practice, but I guess it should cause the errors you’re seeing. Still worth a try though.