Can not import name from x in python 2.7 - python

recently i have created this topic and did not get the answer.
after that i edited this and added 2 screenshots.
right now i tested another temporary email library and got the same error :((
this library :
pip install python-guerrillamail
code python 2.7:
from guerrillamail import GuerrillaMailSession
session = GuerrillaMailSession()
print session.get_session_state()['email_address']
print session.get_email_list()[0].guid
it seemed i cant never work like this email lib.
updated after remove email.pyc:
Traceback (most recent call last):
File "C:\Users\11\Desktop\untitle.py", line 1, in <module>
from guerrillamail import Guerrillamail
ImportError: cannot import name Guerrillamail

Your module email.py, is shadowing, or hiding, the email package in Python's standard library. This is causing the error: in the traceback you can see that an error is being reported when the statement import email is executed.
Rename your file to something else, for example myemail.py.

I changed the code to " from guerrillamail import * " that is worked. this code seems import all things to program, maybe it causes to be heavy and executing time.
thanks to #snakecharmerb .

Related

Toast Notifier is not working, Have i done something wrong?

First off thanks for taking the time to read this:
I am currently trying to get ToastNotifier working in python in MU.
I have imported ToastNotifier from win10toast as such :
from win10toast import ToastNotifier
I have the created this function:
def notifacation():
toast = ToastNotifier()
Title = "Notifacation"
message = "Hello from Ben Colledge"
icon = "a.ico"
length = 30
toast.show_toast(title, message, icon_path=icon, duration=length)
And then called the function like so :
notifacation()
I then run the code and it give me this error message
Traceback (most recent call last):
File "c:\users\puzzl\mu_code\notifacation.py", line 1, in module
from win10toast import ToastNotifier
ModuleNotFoundError: No module named 'win10toast'
I have then gone to https://pypi.org/project/win10toast/ and downloaded win10toast yet nothing happened
Any help would be appreciated
Thanks
I had the exact same problem but then I figured out this works best
python.exe -m pip install win10toast
I ran this code and it still has a problem not, although, the same one. Now the bug would be that in the line that has the method.
toast.show_toast(title, message, icon_path=icon, duration=length)
The problem is that 'title' is undefined. The variable that you assigned was named 'Title'. Since Python is case-sensitive, 'title' is an undifined variable. this is what the line should look like now:
toast.show_toast(Title, message, icon_path=icon, duration=length)
Yay! It works now!

Why can't I import without getting an error about another python file? ("partially initialized module has no attribute")

I'm trying to import the requests module to get familiar with bs4, but the request module in the file I'm currently working in is grayed out so it isn't being recognized as a module. When I run the almost empty program, I get an error for an unrelated python file within my project.
Should I individually store each python file I make inside of a separate folder?
Both of these files are inside of the same project folder.
import requests
response = get('https://www.newegg.ca/p/N82E16868105274')
print(response.raise_for_status())
Error:
Traceback (most recent call last):
File "C:\Users\Denze\MyPythonScripts\Webscraping learning\beautifulsoup tests.py", line 1, in <module>
import requests
File "C:\Users\Denze\MyPythonScripts\requests.py", line 3, in <module>
res = requests.get('')
AttributeError: partially initialized module 'requests' has no attribute 'get' (most likely due to a circular import)
Process finished with exit code 1
The other code in question that I think is causing my error:
import requests
res = requests.get('')
playFile = ('TestDownload.txt', 'wb')
for chunk in res.iter_content(100000):
playFile.write(chunk)
playFile.close()
You have a name collision. You're not importing the requests library, you're importing your script.
You wanted to do the following with your imports:
MyPythonScripts\beautifulsoup tests.py
→ requests.get() (the library)
What you're doing instead is:
MyPythonScripts\beautifulsoup tests.py
→ MyPythonScripts\requests.py
→ MyPythonScripts\requests.py .get() (the same file again)
That's the "circular import" that is mentioned in the traceback. The module imports itself and tries to use an attribute that isn't there before it finishes "executing", so the interpreter thinks it's due to the unfinished initialization
Raname MyPythonScripts\requests.py to something else and it should work.

Getting this error using pywin32 module?

This is my code:
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetLast()
body_content = message.body
print (body_content)
and I am getting the following error:
C:\Users\bre\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/bre/PycharmProjects/test/TkinterApp/test13.py
Traceback (most recent call last):
File "C:/Users/bre/PycharmProjects/test/TkinterApp/test13.py", line 1, in <module>
import win32com.client
File "C:\Users\bre\AppData\Local\Programs\Python\Python36-32\lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: DLL load failed: The specified module could not be found.
Process finished with exit code 1
What exactly does this mean, and how would I be able to fix it? I saw that I can download some DLL, but I don't have experience dealing with that. Any suggestions or step-by-step recommendation on how to make this work?
If you look at your Traceback error, you can see where you went wrong. In line 1 of your test13.py file and in in line 5 of the win32 package. The first thing to ask is "what does the error mean?" Take a look here: import win32api error in Python 2.6. Although it is a reference for Python 2, it should give you a good idea of what to do in your similar situation. It seems like you have to move some dll files from where ever they are currently located to the package directory in your Python36-32 directory. For your possible Python 3 needs, here is a good reference: https://github.com/pyinstaller/pyinstaller/issues/1840

Python :: AttributeError: 'module' object has no attribute 'interfaces'

I downloaded a python project from github:
to work with interface file of ubuntu.
the problem is when I try to use the module as the Readme said I get this:
Traceback (most recent call last):
File "./ss.py", line 7, in <module>
adapters = debinterface.interfaces()
AttributeError: 'module' object has no attribute 'interfaces'
my ss.py script is:
#!/usr/bin/python
import debinterface
import sys
sys.path.append("/home/ed/Downloads/netpy/")
sys.path.append("/home/ed/Downloads/netpy/debinterface/")
adapters = debinterface.interfaces()
I run this script within "/home/ed/Downloads/netpy/" that consists of "debinterface". I have to say that I tried that script without "sys.path.append" but nothing changed, even I changed the module name "debinterface" to "debeh" but again nothing changed too.
what is my problem?
This looks like a bug in the documentation or the package code to me. You can use
from debinterface.interfaces import interfaces
and then refer to your the interface class with
adapters = interfaces()
or edit debinterface/__init__.py to do the import of interface module for you when you import the debinterface package. Add the line
from interfaces import interfaces
to the __init__.py file.
Well, I got it working doing the following:
Downloaded the zip from github;
Extracted the zip and renamed it to debinterfaces;
Created a python module in the same directory that debinterfaces folder is;
Changed the import statement:
from debinterface.interfaces import interfaces
And finally, called interfaces:
adapters = interfaces()

Python 3.1 - Error while adding a library in Blender

For this problem (stackoverflow.com/questions/4086435/), I tried to make a Python 3 version of the library python-websocket (github.com/mtah/python-websocket/), here is my code: https://gist.github.com/663175.
Blender comes with his own Python 3.1 package, so I added my file directly in its «site-packages» folder. I get this error now:
Traceback (most recent call last):
File "websocket.py", line 6, in
AttributeError: 'module' object has no attribute 'WebSocket'
when running this code in Blender:
import sys, os, asyncore, websocket
def msg_handler(msg):
print(msg)
socket = websocket.WebSocket('ws://localhost:8080/', onmessage=msg_handler)
socket.onopen = lambda: socket.send('Hello world!')
try:
asyncore.loop()
except KeyboardInterrupt:
socket.close()
I found that a __init__.py is needed so I added but it didn't help…
What I am doing wrong here ? Thanks for your help.
It looks like you called your script websocket.py, so the import of websocket finds the script itself, instead of the installed module by that name. Rename the script to something else (and if it created a websocket.pyc file, delete that.)

Categories